Skip to content

Commit 94b207a

Browse files
committed
test(@angular-devkit/build-angular): update tests to reflect Webpack 5 behavior
1 parent 174bfc7 commit 94b207a

File tree

11 files changed

+63
-60
lines changed

11 files changed

+63
-60
lines changed

packages/angular_devkit/build_angular/src/browser/specs/errors_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ describe('Browser Builder errors', () => {
9494
// Wait for the builder to complete
9595
await run.stop();
9696

97-
expect(logs.join()).toContain(`export 'missingExport' was not found in 'rxjs'`);
97+
expect(logs.join()).toContain(`export 'missingExport' (imported as 'missingExport') was not found in 'rxjs'`);
9898
});
9999
});

packages/angular_devkit/build_angular/src/browser/specs/lazy-module_spec.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ describe('Browser Builder lazy modules', () => {
6969
}
7070

7171
const { files } = await browserBuild(architect, host, target);
72-
expect('lazy-lazy-module.js' in files).toBe(true);
72+
if (veEnabled && name === 'string') {
73+
expect(files['lazy-lazy-module.js']).toBeDefined();
74+
} else {
75+
expect('src_app_lazy_lazy_module_ts.js' in files).toBe(true);
76+
}
7377
});
7478

7579
it('supports lazy bundle for lazy routes with AOT', async () => {
@@ -79,9 +83,11 @@ describe('Browser Builder lazy modules', () => {
7983

8084
const { files } = await browserBuild(architect, host, target, { aot: true });
8185
if (!veEnabled) {
82-
const data = await files['lazy-lazy-module.js'];
86+
const data = await files['src_app_lazy_lazy_module_ts.js'];
8387
expect(data).not.toBeUndefined('Lazy module output bundle does not exist');
8488
expect(data).toContain('LazyModule.ɵmod');
89+
} else if (name === 'function') {
90+
expect(files['src_app_lazy_lazy_module_ngfactory_js.js']).toBeDefined();
8591
} else {
8692
expect(files['lazy-lazy-module-ngfactory.js']).not.toBeUndefined();
8793
}
@@ -146,7 +152,7 @@ describe('Browser Builder lazy modules', () => {
146152
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
147153

148154
const { files } = await browserBuild(architect, host, target);
149-
expect(files['lazy-module.js']).not.toBeUndefined();
155+
expect(files['src_lazy-module_ts.js']).not.toBeUndefined();
150156
});
151157

152158
it(`supports lazy bundle for dynamic import() calls`, async () => {
@@ -157,20 +163,11 @@ describe('Browser Builder lazy modules', () => {
157163
import(/*webpackChunkName: '[request]'*/'./lazy-' + lazyFileName);
158164
`,
159165
});
160-
host.replaceInFile('src/tsconfig.app.json', `"module": "es2015"`, `"module": "esnext"`);
161-
162-
const { files } = await browserBuild(architect, host, target);
163-
expect(files['lazy-module.js']).not.toBeUndefined();
164-
});
165-
166-
it(`supports lazy bundle for System.import() calls`, async () => {
167-
const lazyfiles = {
168-
'src/lazy-module.ts': 'export const value = 42;',
169-
'src/main.ts': `declare var System: any; System.import('./lazy-module');`,
170-
};
171-
172-
host.writeMultipleFiles(lazyfiles);
173-
addLazyLoadedModulesInTsConfig(host, lazyfiles);
166+
host.replaceInFile(
167+
'src/tsconfig.app.json',
168+
'"main.ts"',
169+
`"main.ts","lazy-module.ts"`,
170+
);
174171

175172
const { files } = await browserBuild(architect, host, target);
176173
expect(files['lazy-module.js']).not.toBeUndefined();
@@ -184,10 +181,13 @@ describe('Browser Builder lazy modules', () => {
184181
});
185182

186183
const { files } = await browserBuild(architect, host, target);
187-
expect(files['one.js']).not.toBeUndefined();
188-
expect(files['two.js']).not.toBeUndefined();
189-
// TODO: the chunk with common modules used to be called `common`, see why that changed.
190-
expect(files['default~one~two.js']).not.toBeUndefined();
184+
expect(files['src_one_ts.js']).not.toBeUndefined();
185+
expect(files['src_two_ts.js']).not.toBeUndefined();
186+
if (veEnabled) {
187+
expect(files['default-node_modules_angular_common_fesm2015_http_js.js']).not.toBeUndefined();
188+
} else {
189+
expect(files['default-node_modules_angular_common___ivy_ngcc___fesm2015_http_js.js']).toBeDefined();
190+
}
191191
});
192192

193193
it(`supports disabling the common bundle`, async () => {
@@ -198,9 +198,13 @@ describe('Browser Builder lazy modules', () => {
198198
});
199199

200200
const { files } = await browserBuild(architect, host, target, { commonChunk: false });
201-
expect(files['one.js']).not.toBeUndefined();
202-
expect(files['two.js']).not.toBeUndefined();
203-
expect(files['common.js']).toBeUndefined();
201+
expect(files['src_one_ts.js']).not.toBeUndefined();
202+
expect(files['src_two_ts.js']).not.toBeUndefined();
203+
if (veEnabled) {
204+
expect(files['default-node_modules_angular_common_fesm2015_http_js.js']).toBeUndefined();
205+
} else {
206+
expect(files['default-node_modules_angular_common___ivy_ngcc___fesm2015_http_js.js']).toBeUndefined();
207+
}
204208
});
205209

206210
it(`supports extra lazy modules array in JIT`, async () => {

packages/angular_devkit/build_angular/src/browser/specs/rebuild_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Browser Builder rebuilds', () => {
8282
debounceTime(rebuildDebounceTime),
8383
tap(result => {
8484
expect(result.success).toBe(true, 'build should succeed');
85-
const hasLazyChunk = host.scopedSync().exists(normalize('dist/lazy-lazy-module.js'));
85+
const hasLazyChunk = host.scopedSync().exists(normalize('dist/src_app_lazy_lazy_module_ts.js'));
8686
switch (phase) {
8787
case 1:
8888
// No lazy chunk should exist.

packages/angular_devkit/build_angular/src/browser/specs/resolve-json-module_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ describe('Browser Builder resolve json module', () => {
4646

4747
switch (buildCount) {
4848
case 1:
49-
expect(content).toContain('\\"foo\\":\\"1\\"');
49+
expect(content).toContain('"foo":"1"');
5050
host.writeMultipleFiles({
5151
'src/my-json-file.json': `{"foo": "2"}`,
5252
});
5353
break;
5454
case 2:
55-
expect(content).toContain('\\"foo\\":\\"2\\"');
55+
expect(content).toContain('"foo":"2"');
5656
break;
5757
}
5858

packages/angular_devkit/build_angular/src/browser/specs/styles_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ describe('Browser Builder styles', () => {
266266

267267
const overrides = { extractCss: true, styles: [`src/styles.scss`] };
268268
await browserBuild(architect, host, target, overrides);
269-
}, 30000);
269+
});
270270

271271
it(`supports font-awesome imports (tilde)`, async () => {
272272
host.writeMultipleFiles({
@@ -278,7 +278,7 @@ describe('Browser Builder styles', () => {
278278

279279
const overrides = { extractCss: true, styles: [`src/styles.scss`] };
280280
await browserBuild(architect, host, target, overrides);
281-
}, 30000);
281+
});
282282

283283
it(`supports font-awesome imports without extractCss`, async () => {
284284
host.writeMultipleFiles({
@@ -289,7 +289,7 @@ describe('Browser Builder styles', () => {
289289

290290
const overrides = { extractCss: false, styles: [`src/styles.scss`] };
291291
await browserBuild(architect, host, target, overrides);
292-
}, 30000);
292+
});
293293

294294
it(`uses autoprefixer`, async () => {
295295
host.writeMultipleFiles({

packages/angular_devkit/build_angular/src/browser/tests/behavior/rebuild-errors_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
2121
const buildCount = await harness
2222
.execute({ outputLogsOnFailure: false })
2323
.pipe(
24-
timeout(30000),
24+
timeout(60000),
2525
concatMap(async ({ result, logs }, index) => {
2626
switch (index) {
2727
case 0:

packages/angular_devkit/build_angular/src/browser/tests/options/named-chunks_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { buildWebpackBrowser } from '../../index';
99
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
1010

1111
const MAIN_OUTPUT = 'dist/main.js';
12-
const NAMED_LAZY_OUTPUT = 'dist/lazy-module.js';
13-
const UNNAMED_LAZY_OUTPUT = 'dist/0.js';
12+
const NAMED_LAZY_OUTPUT = 'dist/src_lazy-module_ts.js';
13+
const UNNAMED_LAZY_OUTPUT = 'dist/339.js';
1414

1515
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
1616
describe('Option: "namedChunks"', () => {

packages/angular_devkit/build_angular/src/browser/tests/options/watch_spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import { concatMap, count, take, timeout } from 'rxjs/operators';
99
import { buildWebpackBrowser } from '../../index';
1010
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
1111

12+
/**
13+
* Maximum time in milliseconds for a single build of the test application
14+
*/
15+
const BUILD_TIMEOUT = 20000;
16+
1217
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
1318
describe('Option: "watch"', () => {
1419
it('does not wait for file changes when false', (done) => {
@@ -22,7 +27,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
2227
let count = 0;
2328
harness
2429
.execute()
25-
.pipe(timeout(15000))
30+
.pipe(timeout(BUILD_TIMEOUT))
2631
.subscribe({
2732
complete() {
2833
expect(count).toBe(1);
@@ -48,7 +53,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
4853
let count = 0;
4954
harness
5055
.execute()
51-
.pipe(timeout(15000))
56+
.pipe(timeout(BUILD_TIMEOUT))
5257
.subscribe({
5358
complete() {
5459
expect(count).toBe(1);
@@ -74,7 +79,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
7479
const buildCount = await harness
7580
.execute()
7681
.pipe(
77-
timeout(30000),
82+
timeout(BUILD_TIMEOUT * 2),
7883
concatMap(async ({ result }, index) => {
7984
expect(result?.success).toBe(true);
8085

packages/angular_devkit/build_angular/src/test-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ export async function browserBuild(
8181
const output = (await run.result) as BrowserBuilderOutput;
8282
expect(output.success).toBe(true);
8383

84+
if (!output.success) {
85+
return {
86+
output,
87+
files: {},
88+
};
89+
}
90+
8491
expect(output.outputPaths[0]).not.toBeUndefined();
8592
const outputPath = normalize(output.outputPaths[0]);
8693

tests/legacy-cli/e2e/tests/build/differential-loading-sri.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createHash } from 'crypto';
2+
import { getGlobalVariable } from '../../utils/env';
23
import {
34
appendToFile,
45
expectFileToMatch,
@@ -46,6 +47,7 @@ export default async function () {
4647
'--prod',
4748
'--subresource-integrity',
4849
'--output-hashing=none',
50+
'--named-chunks',
4951
'--output-path=dist/first',
5052
);
5153

@@ -55,14 +57,19 @@ export default async function () {
5557
'--prod',
5658
'--subresource-integrity',
5759
'--output-hashing=none',
60+
'--named-chunks',
5861
'--output-path=dist/second',
5962
);
6063

64+
const lazyFileBase = getGlobalVariable('argv')['ve']
65+
? 'src_app_lazy_lazy_module_ngfactory_js'
66+
: 'src_app_lazy_lazy_module_ts';
67+
6168
const codeHashES5 = createHash('sha384')
62-
.update(await readFile('dist/first/5-es5.js'))
69+
.update(await readFile(`dist/first/${lazyFileBase}-es5.js`))
6370
.digest('base64');
6471
const codeHashES2015 = createHash('sha384')
65-
.update(await readFile('dist/first/5-es2015.js'))
72+
.update(await readFile(`dist/first/${lazyFileBase}-es2015.js`))
6673
.digest('base64');
6774

6875
await expectFileToMatch('dist/first/runtime-es5.js', 'sha384-' + codeHashES5);

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,10 @@ export default function() {
2828
}
2929
oldNumberOfFiles = currentNumberOfDistFiles;
3030

31-
if (!distFiles.includes('too-lazy-lazy-module.js')) {
31+
if (!distFiles.includes('src_app_too_lazy_lazy_module_ts.js')) {
3232
throw new Error('The lazy module chunk did not use a unique name.');
3333
}
3434
})
35-
// verify System.import still works
36-
.then(() => writeFile('src/app/lazy-file.ts', ''))
37-
.then(() => appendToFile('src/app/app.component.ts', `
38-
// verify other System.import still work
39-
declare var System: any;
40-
const lazyFile = 'file';
41-
System.import(/*webpackChunkName: '[request]'*/'./lazy-' + lazyFile);
42-
`))
43-
.then(() => ng('build', '--named-chunks'))
44-
.then(() => readdirSync('dist/test-project'))
45-
.then((distFiles) => {
46-
const currentNumberOfDistFiles = distFiles.length;
47-
if (oldNumberOfFiles >= currentNumberOfDistFiles) {
48-
throw new Error('A bundle for the lazy file was not created.');
49-
}
50-
if (!distFiles.includes('lazy-file.js')) {
51-
throw new Error('The lazy file chunk did not have a name.');
52-
}
53-
oldNumberOfFiles = currentNumberOfDistFiles;
54-
})
5535
// verify 'import *' syntax doesn't break lazy modules
5636
.then(() => installPackage('moment'))
5737
.then(() => appendToFile('src/app/app.component.ts', `

0 commit comments

Comments
 (0)