-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathtest-environment.ts
More file actions
71 lines (62 loc) · 1.87 KB
/
test-environment.ts
File metadata and controls
71 lines (62 loc) · 1.87 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
import { ng } from '../../utils/process';
import { writeFile, writeMultipleFiles } from '../../utils/fs';
import { updateJsonFile } from '../../utils/project';
import { getGlobalVariable } from '../../utils/env';
export default async function () {
const isWebpack = !getGlobalVariable('argv')['esbuild'];
// Tests run in 'dev' environment by default.
await writeMultipleFiles({
'src/environment.prod.ts': `
export const environment = {
production: true
};`,
'src/environment.ts': `
export const environment = {
production: false
};
`,
'src/app/environment.spec.ts': `
import { environment } from '../environment';
describe('Test environment', () => {
it('should have production disabled', () => {
expect(environment.production).toBe(false);
});
});
`,
});
await ng('test', '--watch=false');
await updateJsonFile('angular.json', (configJson) => {
const appArchitect = configJson.projects['test-project'].architect;
appArchitect[isWebpack ? 'test' : 'build'].configurations = {
production: {
fileReplacements: [
{
replace: 'src/environment.ts',
with: 'src/environment.prod.ts',
},
],
},
};
if (!isWebpack) {
appArchitect.test.options ??= {};
appArchitect.test.options.buildTarget = '::production';
}
});
// Tests can run in different environment.
await writeFile(
'src/app/environment.spec.ts',
`
import { environment } from '../environment';
describe('Test environment', () => {
it('should have production enabled', () => {
expect(environment.production).toBe(true);
});
});
`,
);
if (isWebpack) {
await ng('test', '--watch=false', '--configuration=production');
} else {
await ng('test', '--watch=false');
}
}