Skip to content

Commit 4c6e7e2

Browse files
committed
test: update tests to work with new stricter tsconfig file inclusions
1 parent a57e986 commit 4c6e7e2

File tree

15 files changed

+89
-38
lines changed

15 files changed

+89
-38
lines changed

packages/angular_devkit/build_angular/test/browser/errors_spec_large.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ describe('Browser Builder errors', () => {
2323
it('shows error when files are not part of the compilation', async () => {
2424
host.replaceInFile(
2525
'src/tsconfig.app.json',
26-
'"compilerOptions": {',
27-
`
28-
"files": ["main.ts"],
29-
"compilerOptions": {
30-
`,
26+
/,\r?\n?\s*"polyfills\.ts"/,
27+
'',
28+
);
29+
host.replaceInFile(
30+
'src/tsconfig.app.json',
31+
'"**/*.ts"',
32+
'"**/*.d.ts"',
3133
);
3234
const logger = new logging.Logger('');
3335
const logs: string[] = [];

packages/angular_devkit/build_angular/test/browser/lazy-module_spec_large.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { TestLogger } from '@angular-devkit/architect/testing';
10+
import { TestLogger, TestProjectHost } from '@angular-devkit/architect/testing';
1111
import { take, tap, timeout } from 'rxjs/operators';
1212
import {
1313
browserBuild,
@@ -30,6 +30,21 @@ describe('Browser Builder lazy modules', () => {
3030
});
3131
afterEach(async () => host.restore().toPromise());
3232

33+
function addLazyLoadedModulesInTsConfig(host: TestProjectHost, lazyModuleFiles: Record<string, string>) {
34+
const files = [
35+
...Object.keys(lazyModuleFiles),
36+
'main.ts',
37+
]
38+
.map(f => '"' + f.replace('src/', '') + '"')
39+
.join(', ');
40+
41+
host.replaceInFile(
42+
'src/tsconfig.app.json',
43+
'"main.ts"',
44+
`${files}`,
45+
);
46+
}
47+
3348
const cases: [string, Record<string, string>][] = [
3449
['string', lazyModuleStringImport],
3550
['function', lazyModuleFnImport],
@@ -40,6 +55,10 @@ describe('Browser Builder lazy modules', () => {
4055
host.writeMultipleFiles(lazyModuleFiles);
4156
host.writeMultipleFiles(imports);
4257

58+
if (name === 'string') {
59+
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
60+
}
61+
4362
const { files } = await browserBuild(architect, host, target);
4463
expect('lazy-lazy-module.js' in files).toBe(true);
4564
});
@@ -91,6 +110,7 @@ describe('Browser Builder lazy modules', () => {
91110
it('supports lazy bundle for lazy routes with AOT', async () => {
92111
host.writeMultipleFiles(lazyModuleFiles);
93112
host.writeMultipleFiles(imports);
113+
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
94114

95115
const { files } = await browserBuild(architect, host, target, { aot: true });
96116
if (ivyEnabled) {
@@ -131,10 +151,13 @@ describe('Browser Builder lazy modules', () => {
131151
});
132152

133153
it(`supports lazy bundle for System.import() calls`, async () => {
134-
host.writeMultipleFiles({
154+
const lazyfiles = {
135155
'src/lazy-module.ts': 'export const value = 42;',
136156
'src/main.ts': `declare var System: any; System.import('./lazy-module');`,
137-
});
157+
};
158+
159+
host.writeMultipleFiles(lazyfiles);
160+
addLazyLoadedModulesInTsConfig(host, lazyfiles);
138161

139162
const { files } = await browserBuild(architect, host, target);
140163
expect(files['lazy-module.js']).not.toBeUndefined();
@@ -199,6 +222,7 @@ describe('Browser Builder lazy modules', () => {
199222
}`,
200223
});
201224
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
225+
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
202226

203227
const { files } = await browserBuild(architect, host, target, {
204228
lazyModules: ['src/app/lazy/lazy.module'],
@@ -227,6 +251,7 @@ describe('Browser Builder lazy modules', () => {
227251
}`,
228252
});
229253
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
254+
addLazyLoadedModulesInTsConfig(host, lazyModuleFiles);
230255
const { files } = await browserBuild(architect, host, target, {
231256
lazyModules: ['src/app/lazy/lazy.module'],
232257
aot: true,

packages/angular_devkit/build_angular/test/browser/output-hashing_spec_large.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createArchitect,
1414
host,
1515
lazyModuleFiles,
16-
lazyModuleStringImport,
16+
lazyModuleFnImport,
1717
} from '../utils';
1818

1919
describe('Browser Builder output hashing', () => {
@@ -68,7 +68,7 @@ describe('Browser Builder output hashing', () => {
6868
let newHashes: Map<string, string>;
6969

7070
host.writeMultipleFiles(lazyModuleFiles);
71-
host.writeMultipleFiles(lazyModuleStringImport);
71+
host.writeMultipleFiles(lazyModuleFnImport);
7272

7373
const overrides = { outputHashing: 'all', extractCss: true };
7474

@@ -79,7 +79,7 @@ describe('Browser Builder output hashing', () => {
7979
// Save the current hashes.
8080
oldHashes = generateFileHashMap();
8181
host.writeMultipleFiles(lazyModuleFiles);
82-
host.writeMultipleFiles(lazyModuleStringImport);
82+
host.writeMultipleFiles(lazyModuleFnImport);
8383

8484
await browserBuild(architect, host, target, overrides);
8585
newHashes = generateFileHashMap();
@@ -117,7 +117,7 @@ describe('Browser Builder output hashing', () => {
117117
it('supports options', async () => {
118118
host.writeMultipleFiles({ 'src/styles.css': `h1 { background: url('./spectrum.png')}` });
119119
host.writeMultipleFiles(lazyModuleFiles);
120-
host.writeMultipleFiles(lazyModuleStringImport);
120+
host.writeMultipleFiles(lazyModuleFnImport);
121121

122122
// We must do several builds instead of a single one in watch mode, so that the output
123123
// path is deleted on each run and only contains the most recent files.

packages/angular_devkit/build_angular/test/browser/rebuild_spec_large.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
host,
1616
ivyEnabled,
1717
lazyModuleFiles,
18-
lazyModuleStringImport,
18+
lazyModuleFnImport,
1919
} from '../utils';
2020

2121
describe('Browser Builder rebuilds', () => {
@@ -84,7 +84,7 @@ describe('Browser Builder rebuilds', () => {
8484
// No lazy chunk should exist.
8585
if (!hasLazyChunk) {
8686
phase = 2;
87-
host.writeMultipleFiles({ ...lazyModuleFiles, ...lazyModuleStringImport });
87+
host.writeMultipleFiles({ ...lazyModuleFiles, ...lazyModuleFnImport });
8888
}
8989
break;
9090

tests/angular_devkit/build_angular/hello-world-app-ivy/src/tsconfig.app.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"outDir": "../out-tsc/app",
55
"types": []
66
},
7-
"exclude": [
8-
"test.ts",
9-
"**/*.spec.ts"
7+
"files": [
8+
"main.ts",
9+
"polyfills.ts"
10+
],
11+
"include": [
12+
"**/*.d.ts"
1013
],
1114
"angularCompilerOptions": {
1215
"enableIvy": true

tests/angular_devkit/build_angular/hello-world-app-ivy/src/tsconfig.server.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
2-
"extends": "../tsconfig.json",
2+
"extends": "./tsconfig.app.json",
33
"compilerOptions": {
44
"outDir": "../dist-server",
55
"baseUrl": "./",
66
"module": "commonjs",
77
"types": []
88
},
9-
"exclude": [
10-
"test.ts",
11-
"**/*.spec.ts"
9+
"files": [
10+
"main.server.ts"
1211
],
1312
"angularCompilerOptions": {
1413
"entryModule": "app/app.server.module#AppServerModule",

tests/angular_devkit/build_angular/hello-world-app/src/tsconfig.app.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"outDir": "../out-tsc/app",
55
"types": []
66
},
7+
"files": [
8+
"main.ts",
9+
"polyfills.ts"
10+
],
11+
"include": [
12+
"**/*.ts"
13+
],
714
"exclude": [
815
"test.ts",
916
"**/*.spec.ts"

tests/angular_devkit/build_angular/hello-world-app/src/tsconfig.server.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
2-
"extends": "../tsconfig.json",
2+
"extends": "./tsconfig.app.json",
33
"compilerOptions": {
44
"outDir": "../dist-server",
5-
"baseUrl": "./",
65
"module": "commonjs",
76
"types": []
87
},
9-
"exclude": [
10-
"test.ts",
11-
"**/*.spec.ts"
8+
"files": [
9+
"main.server.ts"
1210
],
1311
"angularCompilerOptions": {
1412
"entryModule": "app/app.server.module#AppServerModule"

tests/legacy-cli/e2e/tests/basic/rebuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function() {
3737
FormsModule,
3838
HttpClientModule,
3939
RouterModule.forRoot([
40-
{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
40+
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }
4141
])
4242
],
4343
providers: [],

tests/legacy-cli/e2e/tests/build/build-app-shell.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export default function() {
5252
"module": "commonjs",
5353
"types": []
5454
},
55+
"files": [
56+
"src/main.server.ts"
57+
],
58+
"include": [
59+
"src/**/*.d.ts"
60+
],
5561
"angularCompilerOptions": {
5662
"entryModule": "src/app/app.server.module#AppServerModule"
5763
}

tests/legacy-cli/e2e/tests/build/build-errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default function() {
5050
.then(() =>
5151
updateJsonFile('./tsconfig.app.json', configJson => {
5252
configJson.include = ['src/**/*.ts'];
53+
configJson.exclude = ['**/**.spec.ts'];
5354
configJson.files = undefined;
5455
}),
5556
)

tests/legacy-cli/e2e/tests/build/dynamic-import.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export default async function() {
1414
];
1515
});
1616

17+
await updateJsonFile('tsconfig.app.json', tsConfig => {
18+
tsConfig.files.push('src/app/lazy/lazy.module.ts');
19+
});
20+
1721
// Update the app component to use the lazy module
1822
await writeFile('src/app/app.component.ts', `
1923
import { Component, SystemJsNgModuleLoader } from '@angular/core';

tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ export default async function () {
8282
buildTarget['configurations']['production'] = { aot: true };
8383
});
8484

85-
// Test string import.
86-
// Both Ivy and View Engine should support it.
87-
await replaceLoadChildren(`'./lazy/lazy.module#LazyModule'`);
88-
await ng('e2e');
89-
await ng('e2e', '--prod');
90-
9185
// Test `import()` style lazy load.
9286
// Both Ivy and View Engine should support it.
9387
await replaceLoadChildren(`() => import('./lazy/lazy.module').then(m => m.LazyModule)`);
9488

95-
// TODO: remove cast after https://github.com/angular/angular/pull/29832 is released.
96-
await replaceInFile(appRoutingModulePath, '];', '] as Routes;');
89+
await ng('e2e');
90+
await ng('e2e', '--prod');
9791

92+
// Test string import.
93+
// Both Ivy and View Engine should support it.
94+
await updateJsonFile('tsconfig.app.json', tsConfig => {
95+
tsConfig.files.push('src/app/lazy/lazy.module.ts');
96+
});
97+
await replaceLoadChildren(`'./lazy/lazy.module#LazyModule'`);
9898
await ng('e2e');
9999
await ng('e2e', '--prod');
100100
}

tests/legacy-cli/e2e/tests/build/platform-server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export default function() {
5050
"module": "commonjs",
5151
"types": []
5252
},
53+
"files": [
54+
"src/main.server.ts"
55+
],
56+
"include": [
57+
"src/**/*.d.ts"
58+
],
5359
"angularCompilerOptions": {
5460
"entryModule": "src/app/app.server.module#AppServerModule"
5561
}

tests/legacy-cli/e2e/tests/misc/lazy-module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export default function() {
1515
import { RouterModule } from '@angular/router';
1616
`))
1717
.then(() => replaceInFile('src/app/app.module.ts', 'imports: [', `imports: [
18-
RouterModule.forRoot([{ path: "lazy", loadChildren: 'src/app/lazy/lazy.module#LazyModule' }]),
19-
RouterModule.forRoot([{ path: "lazy1", loadChildren: './lazy/lazy.module#LazyModule' }]),
20-
RouterModule.forRoot([{ path: "lazy2", loadChildren: './too/lazy/lazy.module#LazyModule' }]),
18+
RouterModule.forRoot([{ path: "lazy", loadChildren: () => import('src/app/lazy/lazy.module').then(m => m.LazyModule) }]),
19+
RouterModule.forRoot([{ path: "lazy1", loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) }]),
20+
RouterModule.forRoot([{ path: "lazy2", loadChildren: () => import('./too/lazy/lazy.module').then(m => m.LazyModule) }]),
2121
`))
2222
.then(() => ng('build', '--named-chunks'))
2323
.then(() => readdirSync('dist/test-project'))

0 commit comments

Comments
 (0)