|
1 |
| -import {ng} from '../../utils/process'; |
| 1 | +import { writeMultipleFiles } from '../../utils/fs'; |
| 2 | +import { ng } from '../../utils/process'; |
| 3 | +import { updateJsonFile } from '../../utils/project'; |
| 4 | +import { expectToFail } from '../../utils/utils'; |
| 5 | +import { stripIndent } from 'common-tags'; |
2 | 6 |
|
3 |
| - |
4 |
| -export default function() { |
| 7 | +export default function () { |
5 | 8 | // make sure both --watch=false and --single-run work
|
6 | 9 | return ng('test', '--single-run')
|
7 |
| - .then(() => ng('test', '--watch=false')); |
| 10 | + .then(() => ng('test', '--watch=false')) |
| 11 | + // prepare global scripts test files |
| 12 | + .then(() => writeMultipleFiles({ |
| 13 | + 'src/string-script.js': `stringScriptGlobal = 'string-scripts.js';`, |
| 14 | + 'src/input-script.js': `inputScriptGlobal = 'input-scripts.js';`, |
| 15 | + 'src/typings.d.ts': stripIndent` |
| 16 | + declare var stringScriptGlobal: any; |
| 17 | + declare var inputScriptGlobal: any; |
| 18 | + `, |
| 19 | + 'src/app/app.component.ts': stripIndent` |
| 20 | + import { Component } from '@angular/core'; |
| 21 | +
|
| 22 | + @Component({ selector: 'app-root', template: '' }) |
| 23 | + export class AppComponent { |
| 24 | + stringScriptGlobalProp = stringScriptGlobal; |
| 25 | + inputScriptGlobalProp = inputScriptGlobal; |
| 26 | + } |
| 27 | + `, |
| 28 | + 'src/app/app.component.spec.ts': stripIndent` |
| 29 | + import { TestBed, async } from '@angular/core/testing'; |
| 30 | + import { AppComponent } from './app.component'; |
| 31 | +
|
| 32 | + describe('AppComponent', () => { |
| 33 | + beforeEach(() => { |
| 34 | + TestBed.configureTestingModule({ declarations: [ AppComponent ] }); |
| 35 | + TestBed.compileComponents(); |
| 36 | + }); |
| 37 | +
|
| 38 | + it('should have access to string-script.js', async(() => { |
| 39 | + let app = TestBed.createComponent(AppComponent).debugElement.componentInstance; |
| 40 | + expect(app.stringScriptGlobalProp).toEqual('string-scripts.js'); |
| 41 | + })); |
| 42 | +
|
| 43 | + it('should have access to input-script.js', async(() => { |
| 44 | + let app = TestBed.createComponent(AppComponent).debugElement.componentInstance; |
| 45 | + expect(app.inputScriptGlobalProp).toEqual('input-scripts.js'); |
| 46 | + })); |
| 47 | + }); |
| 48 | +
|
| 49 | + describe('Spec', () => { |
| 50 | + it('should have access to string-script.js', async(() => { |
| 51 | + expect(stringScriptGlobal).toBe('string-scripts.js'); |
| 52 | + })); |
| 53 | +
|
| 54 | + it('should have access to input-script.js', async(() => { |
| 55 | + expect(inputScriptGlobal).toBe('input-scripts.js'); |
| 56 | + })); |
| 57 | + }); |
| 58 | + ` |
| 59 | + })) |
| 60 | + // should fail because the global scripts were not added to scripts array |
| 61 | + .then(() => expectToFail(() => ng('test', '--single-run'))) |
| 62 | + .then(() => updateJsonFile('angular-cli.json', configJson => { |
| 63 | + const app = configJson['apps'][0]; |
| 64 | + app['scripts'] = [ |
| 65 | + 'string-script.js', |
| 66 | + { input: 'input-script.js' } |
| 67 | + ]; |
| 68 | + })) |
| 69 | + // should pass now |
| 70 | + .then(() => ng('test', '--single-run')); |
8 | 71 | }
|
0 commit comments