Skip to content

Commit bece843

Browse files
clydinalan-agius4
authored andcommitted
test: enable build E2E tests for esbuild-based builders
The build E2E tests have now been enabled for the esbuild-based builders. The bundle budget test is currently skipped pending feature implementation. Several redundant tests were also deleted due to the functionality already being covered by unit tests for the builders. (cherry picked from commit 8bd90ff)
1 parent 05ce9d6 commit bece843

22 files changed

+188
-204
lines changed

tests/legacy-cli/e2e.bzl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ BROWSER_TESTS = ["tests/misc/browsers.js"]
3030
YARN_TESTS = ["tests/basic/**", "tests/update/**", "tests/commands/add/**"]
3131
ESBUILD_TESTS = [
3232
"tests/basic/**",
33-
"tests/build/app-shell/app-shell-standalone.js",
34-
"tests/build/app-shell/app-shell-with-schematic.js",
35-
"tests/build/library/**",
36-
"tests/build/ssr/**",
37-
"tests/build/prod-build.js",
38-
"tests/build/relative-sourcemap.js",
39-
"tests/build/styles/**",
40-
"tests/build/prerender/**",
41-
"tests/build/worker.js",
33+
"tests/build/**",
4234
"tests/commands/add/**",
4335
"tests/i18n/**",
4436
]

tests/legacy-cli/e2e/tests/build/app-shell/app-shell-with-service-worker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { updateJsonFile } from '../../../utils/project';
77
const snapshots = require('../../../ng-snapshot/package.json');
88

99
export default async function () {
10+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
11+
1012
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
1113
await ng('generate', 'service-worker', '--project', 'test-project');
1214
await ng('generate', 'app-shell', '--project', 'test-project');
@@ -49,7 +51,12 @@ export default async function () {
4951
`,
5052
);
5153

52-
await ng('run', 'test-project:app-shell:production');
54+
if (useWebpackBuilder) {
55+
await ng('run', 'test-project:app-shell:production');
56+
} else {
57+
await ng('build');
58+
}
5359
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
60+
5461
await ng('e2e', '--configuration=production');
5562
}

tests/legacy-cli/e2e/tests/build/base-href.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/legacy-cli/e2e/tests/build/bundle-budgets.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,32 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { getGlobalVariable } from '../../utils/env';
89
import { ng } from '../../utils/process';
910
import { updateJsonFile } from '../../utils/project';
1011
import { expectToFail } from '../../utils/utils';
1112

1213
export default async function () {
14+
const usingWebpack = !getGlobalVariable('argv')['esbuild'];
15+
1316
// Error
1417
await updateJsonFile('angular.json', (json) => {
1518
json.projects['test-project'].architect.build.configurations.production.budgets = [
1619
{ type: 'all', maximumError: '100b' },
1720
];
1821
});
1922

20-
const { message: errorMessage } = await expectToFail(() => ng('build'));
21-
if (!/Error.+budget/.test(errorMessage)) {
22-
throw new Error('Budget error: all, max error.');
23+
if (usingWebpack) {
24+
const { message: errorMessage } = await expectToFail(() => ng('build'));
25+
if (!/Error.+budget/i.test(errorMessage)) {
26+
throw new Error('Budget error: all, max error.');
27+
}
28+
} else {
29+
// Application builder does not generate an error exit code for budget failures
30+
const { stderr } = await ng('build');
31+
if (!/Error.+budget/i.test(stderr)) {
32+
throw new Error('Budget error: all, max error.');
33+
}
2334
}
2435

2536
// Warning
@@ -30,7 +41,7 @@ export default async function () {
3041
});
3142

3243
const { stderr } = await ng('build');
33-
if (!/Warning.+budget/.test(stderr)) {
44+
if (!/Warning.+budget/i.test(stderr)) {
3445
throw new Error('Budget warning: all, min warning');
3546
}
3647

@@ -42,7 +53,7 @@ export default async function () {
4253
});
4354

4455
const { stderr: stderr2 } = await ng('build');
45-
if (/(Warning|Error)/.test(stderr2)) {
56+
if (/(Warning|Error)/i.test(stderr2)) {
4657
throw new Error('BIG max for all, should not error');
4758
}
4859
}

tests/legacy-cli/e2e/tests/build/css-urls.ts

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,73 @@ import {
77
} from '../../utils/fs';
88
import { copyProjectAsset } from '../../utils/assets';
99
import { expectToFail } from '../../utils/utils';
10+
import { getGlobalVariable } from '../../utils/env';
1011

1112
const imgSvg = `
1213
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
1314
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
1415
</svg>
1516
`;
1617

17-
export default function () {
18-
return (
19-
Promise.resolve()
20-
// Verify absolute/relative paths in global/component css.
21-
.then(() =>
22-
writeMultipleFiles({
23-
'src/styles.css': `
18+
export default async function () {
19+
const usingWebpack = !getGlobalVariable('argv')['esbuild'];
20+
21+
const mediaPath = usingWebpack
22+
? './dist/test-project/browser'
23+
: './dist/test-project/browser/media';
24+
25+
await Promise.resolve()
26+
// Verify absolute/relative paths in global/component css.
27+
.then(() =>
28+
writeMultipleFiles({
29+
'src/styles.css': `
2430
h1 { background: url('/assets/global-img-absolute.svg'); }
2531
h2 { background: url('./assets/global-img-relative.png'); }
2632
`,
27-
'src/app/app.component.css': `
33+
'src/app/app.component.css': `
2834
h3 { background: url('/assets/component-img-absolute.svg'); }
2935
h4 { background: url('../assets/component-img-relative.png'); }
3036
`,
31-
'src/assets/global-img-absolute.svg': imgSvg,
32-
'src/assets/component-img-absolute.svg': imgSvg,
33-
}),
34-
)
35-
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/global-img-relative.png'))
36-
.then(() =>
37-
copyProjectAsset('images/spectrum.png', './src/assets/component-img-relative.png'),
38-
)
39-
.then(() => ng('build', '--aot', '--configuration=development'))
40-
// Check paths are correctly generated.
41-
.then(() =>
42-
expectFileToMatch('dist/test-project/browser/styles.css', 'assets/global-img-absolute.svg'),
43-
)
44-
.then(() =>
45-
expectFileToMatch(
46-
'dist/test-project/browser/styles.css',
47-
/url\('\/assets\/global-img-absolute\.svg'\)/,
48-
),
49-
)
50-
.then(() =>
51-
expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/),
52-
)
53-
.then(() =>
54-
expectFileToMatch(
55-
'dist/test-project/browser/main.js',
56-
'/assets/component-img-absolute.svg',
57-
),
58-
)
59-
.then(() =>
60-
expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/),
61-
)
62-
// Check files are correctly created.
63-
.then(() =>
64-
expectToFail(() => expectFileToExist('dist/test-project/browser/global-img-absolute.svg')),
65-
)
66-
.then(() =>
67-
expectToFail(() =>
68-
expectFileToExist('dist/test-project/browser/component-img-absolute.svg'),
69-
),
70-
)
71-
.then(() => expectFileMatchToExist('./dist/test-project/browser', /global-img-relative\.png/))
72-
.then(() =>
73-
expectFileMatchToExist('./dist/test-project/browser', /component-img-relative\.png/),
74-
)
75-
// Check urls with deploy-url scheme are used as is.
37+
'src/assets/global-img-absolute.svg': imgSvg,
38+
'src/assets/component-img-absolute.svg': imgSvg,
39+
}),
40+
)
41+
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/global-img-relative.png'))
42+
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/component-img-relative.png'))
43+
.then(() => ng('build', '--aot', '--configuration=development'))
44+
// Check paths are correctly generated.
45+
.then(() =>
46+
expectFileToMatch('dist/test-project/browser/styles.css', 'assets/global-img-absolute.svg'),
47+
)
48+
.then(() =>
49+
expectFileToMatch(
50+
'dist/test-project/browser/styles.css',
51+
/url\((['"]?)\/assets\/global-img-absolute\.svg\1\)/,
52+
),
53+
)
54+
.then(() =>
55+
expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/),
56+
)
57+
.then(() =>
58+
expectFileToMatch('dist/test-project/browser/main.js', '/assets/component-img-absolute.svg'),
59+
)
60+
.then(() =>
61+
expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/),
62+
)
63+
// Check files are correctly created.
64+
.then(() => expectToFail(() => expectFileToExist(`${mediaPath}/global-img-absolute.svg`)))
65+
.then(() => expectToFail(() => expectFileToExist(`${mediaPath}/component-img-absolute.svg`)))
66+
.then(() => expectFileMatchToExist(mediaPath, /global-img-relative\.png/))
67+
.then(() => expectFileMatchToExist(mediaPath, /component-img-relative\.png/));
68+
69+
// Early exit before deploy url tests
70+
if (!usingWebpack) {
71+
return;
72+
}
73+
74+
// Check urls with deploy-url scheme are used as is.
75+
return (
76+
Promise.resolve()
7677
.then(() =>
7778
ng(
7879
'build',

tests/legacy-cli/e2e/tests/build/deploy-url.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { ng } from '../../utils/process';
22
import { copyProjectAsset } from '../../utils/assets';
33
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
4+
import { getGlobalVariable } from '../../utils/env';
45

56
export default function () {
7+
if (getGlobalVariable('argv')['esbuild']) {
8+
return;
9+
}
10+
611
return (
712
Promise.resolve()
813
.then(() =>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1+
import { getGlobalVariable } from '../../utils/env';
12
import { expectFileToExist, expectFileToMatch } from '../../utils/fs';
23
import { ng } from '../../utils/process';
34
import { expectToFail } from '../../utils/utils';
45

56
export default async function () {
7+
const usingWebpack = !getGlobalVariable('argv')['esbuild'];
8+
69
// Licenses should be left intact if extraction is disabled
710
await ng('build', '--extract-licenses=false', '--output-hashing=none');
811

9-
await expectToFail(() => expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt'));
12+
if (usingWebpack) {
13+
await expectToFail(() => expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt'));
14+
} else {
15+
// Application builder puts the licenses at the output path root
16+
await expectToFail(() => expectFileToExist('dist/test-project/3rdpartylicenses.txt'));
17+
}
1018
await expectFileToMatch('dist/test-project/browser/main.js', '@license');
1119

1220
// Licenses should be removed if extraction is enabled
1321
await ng('build', '--extract-licenses', '--output-hashing=none');
1422

15-
await expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt');
23+
if (usingWebpack) {
24+
await expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt');
25+
} else {
26+
await expectFileToExist('dist/test-project/3rdpartylicenses.txt');
27+
}
1628
await expectToFail(() => expectFileToMatch('dist/test-project/browser/main.js', '@license'));
1729
}

tests/legacy-cli/e2e/tests/build/jit-prod.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getGlobalVariable } from '../../utils/env';
12
import { ng } from '../../utils/process';
23
import { updateJsonFile } from '../../utils/project';
34

@@ -6,7 +7,9 @@ export default async function () {
67
await updateJsonFile('angular.json', (configJson) => {
78
const appArchitect = configJson.projects['test-project'].architect;
89
appArchitect.build.configurations['production'].aot = false;
9-
appArchitect.build.configurations['production'].buildOptimizer = false;
10+
if (!getGlobalVariable('argv')['esbuild']) {
11+
appArchitect.build.configurations['production'].buildOptimizer = false;
12+
}
1013
});
1114

1215
// Test it works

tests/legacy-cli/e2e/tests/build/multiple-configs.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { getGlobalVariable } from '../../utils/env';
12
import { expectFileToExist } from '../../utils/fs';
23
import { ng } from '../../utils/process';
34
import { updateJsonFile } from '../../utils/project';
45
import { expectToFail } from '../../utils/utils';
56

67
export default async function () {
8+
// TODO: Restructure to support application builder option
9+
// This only needs to be tested once since it is really testing the CLI itself and not the builders
10+
if (getGlobalVariable('argv')['esbuild']) {
11+
return;
12+
}
13+
714
await updateJsonFile('angular.json', (workspaceJson) => {
815
const appArchitect = workspaceJson.projects['test-project'].architect;
916
// These are the default options, that we'll overwrite in subsequent configs.
@@ -13,7 +20,6 @@ export default async function () {
1320
defaultConfiguration: undefined,
1421
options: {
1522
...appArchitect['build'].options,
16-
buildOptimizer: false,
1723
optimization: false,
1824
sourceMap: true,
1925
outputHashing: 'none',

0 commit comments

Comments
 (0)