-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathtest-scripts.ts
More file actions
75 lines (63 loc) · 2.58 KB
/
test-scripts.ts
File metadata and controls
75 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { getGlobalVariable } from '../../utils/env';
import { writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
export default async function () {
// TODO(architect): Delete this test. It is now in devkit/build-angular.
await ng('test', '--watch=false');
// prepare global scripts test files
await writeMultipleFiles({
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `globalThis.inputScriptGlobal = 'input-scripts.js';`,
'src/typings.d.ts': `
declare var stringScriptGlobal: any;
declare var inputScriptGlobal: any;
`,
'src/app/app.ts': `
import { Component } from '@angular/core';
@Component({ selector: 'app-root', template: '', standalone: false })
export class App {
stringScriptGlobalProp = stringScriptGlobal;
inputScriptGlobalProp = inputScriptGlobal;
}
`,
'src/app/app.spec.ts': `
import { TestBed } from '@angular/core/testing';
import { App } from './app';
describe('App', () => {
beforeEach(() => TestBed.configureTestingModule({
declarations: [App]
}));
it('should have access to string-script.js', () => {
let app = TestBed.createComponent(App).debugElement.componentInstance;
expect(app.stringScriptGlobalProp).toEqual('string-scripts.js');
});
it('should have access to input-script.js', () => {
let app = TestBed.createComponent(App).debugElement.componentInstance;
expect(app.inputScriptGlobalProp).toEqual('input-scripts.js');
});
});
describe('Spec', () => {
it('should have access to string-script.js', () => {
expect(stringScriptGlobal).toBe('string-scripts.js');
});
it('should have access to input-script.js', () => {
expect(inputScriptGlobal).toBe('input-scripts.js');
});
});
`,
});
// should fail because the global scripts were not added to scripts array
await expectToFail(() => ng('test', '--watch=false'));
const isWebpack = !getGlobalVariable('argv')['esbuild'];
await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect[isWebpack ? 'test' : 'build'].options.scripts = [
{ input: 'src/string-script.js' },
{ input: 'src/input-script.js' },
];
});
// should pass now
await ng('test', '--watch=false');
}