Skip to content

Commit 400cd76

Browse files
committed
test: update E2E tests setup to work with application builder
This commit updates the E2E tests setup to account for the default builder change from `@angular-devkit/build-angular:browser` to `@angular-devkit/build-angular:application`.
1 parent 3f8aa9d commit 400cd76

18 files changed

+275
-87
lines changed

tests/legacy-cli/e2e.bzl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ 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",
3335
"tests/build/library/**",
3436
"tests/build/prod-build.js",
3537
"tests/build/relative-sourcemap.js",
3638
"tests/build/styles/**",
3739
"tests/commands/add/add-pwa.js",
3840
"tests/i18n/extract-ivy*",
39-
]
40-
41-
# Tests excluded for esbuild
42-
ESBUILD_IGNORE_TESTS = [
4341
"tests/ssr/**",
4442
]
4543

@@ -135,8 +133,9 @@ def _e2e_suite(name, runner, type, data, toolchain_name = "", toolchain = None):
135133
elif type == "esbuild":
136134
args.append("--esbuild")
137135
tests = ESBUILD_TESTS
138-
ignore = BROWSER_TESTS + ESBUILD_IGNORE_TESTS
136+
ignore = BROWSER_TESTS
139137
elif type == "saucelabs":
138+
args.append("--esbuild")
140139
tests = BROWSER_TESTS
141140
ignore = None
142141
elif type == "npm":

tests/legacy-cli/e2e/initialize/500-create-project.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@ export default async function () {
2626
process.chdir('./test-project');
2727

2828
// Setup esbuild builder if requested on the commandline
29-
const useEsbuildBuilder = !!getGlobalVariable('argv')['esbuild'];
30-
if (useEsbuildBuilder) {
29+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
30+
if (useWebpackBuilder) {
3131
await updateJsonFile('angular.json', (json) => {
32-
json['projects']['test-project']['architect']['build']['builder'] =
33-
'@angular-devkit/build-angular:browser-esbuild';
32+
const build = json['projects']['test-project']['architect']['build'];
33+
build.builder = '@angular-devkit/build-angular:browser';
34+
build.options = {
35+
...build.options,
36+
main: build.options.browser,
37+
browser: undefined,
38+
};
39+
40+
build.configurations.development = {
41+
...build.configurations.development,
42+
vendorChunk: true,
43+
namedChunks: true,
44+
buildOptimizer: false,
45+
};
3446
});
3547
}
3648
}

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ const snapshots = require('../../../ng-snapshot/package.json');
88

99
export default async function () {
1010
await ng('generate', 'app', 'test-project-two', '--routing', '--standalone', '--skip-install');
11+
12+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
13+
14+
// Setup webpack builder if esbuild is not requested on the commandline
15+
await updateJsonFile('angular.json', (json) => {
16+
const build = json['projects']['test-project-two']['architect']['build'];
17+
if (useWebpackBuilder) {
18+
build.builder = '@angular-devkit/build-angular:browser';
19+
build.options = {
20+
...build.options,
21+
main: build.options.browser,
22+
browser: undefined,
23+
};
24+
25+
build.configurations.development = {
26+
...build.configurations.development,
27+
vendorChunk: true,
28+
namedChunks: true,
29+
buildOptimizer: false,
30+
};
31+
} else {
32+
// TODO(alanagius): enable once esbuild supports standalone route extraction.
33+
build.configurations.production.prerender = false;
34+
}
35+
});
36+
1137
await ng('generate', 'app-shell', '--project', 'test-project-two');
1238

1339
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
@@ -30,9 +56,13 @@ export default async function () {
3056
}
3157
}
3258

33-
await ng('run', 'test-project-two:app-shell:development');
34-
await expectFileToMatch('dist/test-project-two/browser/index.html', 'app-shell works!');
35-
36-
await ng('run', 'test-project-two:app-shell');
37-
await expectFileToMatch('dist/test-project-two/browser/index.html', 'app-shell works!');
59+
if (useWebpackBuilder) {
60+
await ng('run', 'test-project-two:app-shell:development');
61+
await expectFileToMatch('dist/test-project-two/browser/index.html', 'app-shell works!');
62+
await ng('run', 'test-project-two:app-shell');
63+
await expectFileToMatch('dist/test-project-two/browser/index.html', 'app-shell works!');
64+
} else {
65+
await ng('build', 'test-project-two');
66+
await expectFileToMatch('dist/test-project-two/index.html', 'app-shell works!');
67+
}
3868
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const snapshots = require('../../../ng-snapshot/package.json');
99
export default async function () {
1010
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
1111
await ng('generate', 'app-shell', '--project', 'test-project');
12+
// Setup webpack builder if esbuild is not requested on the commandline
13+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
1214

1315
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
1416
if (isSnapshotBuild) {
@@ -30,9 +32,14 @@ export default async function () {
3032
}
3133
}
3234

33-
await ng('run', 'test-project:app-shell:development');
34-
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
35+
if (useWebpackBuilder) {
36+
await ng('run', 'test-project:app-shell:development');
37+
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
3538

36-
await ng('run', 'test-project:app-shell');
37-
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
39+
await ng('run', 'test-project:app-shell');
40+
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
41+
} else {
42+
await ng('build');
43+
await expectFileToMatch('dist/test-project/index.html', 'app-shell works!');
44+
}
3845
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ export default async function () {
5151

5252
await ng('run', 'test-project:app-shell:production');
5353
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
54-
5554
await ng('e2e', '--configuration=production');
5655
}

tests/legacy-cli/e2e/tests/build/library/lib-consumption-full-jit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { updateJsonFile } from '../../../utils/project';
22
import { expectFileToMatch } from '../../../utils/fs';
33
import { ng } from '../../../utils/process';
44
import { libraryConsumptionSetup } from './setup';
5+
import { getGlobalVariable } from '../../../utils/env';
56

67
export default async function () {
78
await libraryConsumptionSetup();
@@ -13,7 +14,9 @@ export default async function () {
1314
await updateJsonFile('angular.json', (config) => {
1415
const build = config.projects['test-project'].architect.build;
1516
build.options.aot = false;
16-
build.configurations.production.buildOptimizer = false;
17+
if (!getGlobalVariable('argv')['esbuild']) {
18+
build.configurations.production.buildOptimizer = false;
19+
}
1720
});
1821

1922
// Check that the e2e succeeds prod and non prod mode

tests/legacy-cli/e2e/tests/build/library/lib-consumption-partial-jit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { updateJsonFile } from '../../../utils/project';
22
import { ng } from '../../../utils/process';
33
import { libraryConsumptionSetup } from './setup';
4+
import { getGlobalVariable } from '../../../utils/env';
45

56
export default async function () {
67
await libraryConsumptionSetup();
@@ -12,7 +13,9 @@ export default async function () {
1213
await updateJsonFile('angular.json', (config) => {
1314
const build = config.projects['test-project'].architect.build;
1415
build.options.aot = false;
15-
build.configurations.production.buildOptimizer = false;
16+
if (!getGlobalVariable('argv')['esbuild']) {
17+
build.configurations.production.buildOptimizer = false;
18+
}
1619
});
1720

1821
// Check that the e2e succeeds prod and non prod mode

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { statSync } from 'fs';
22
import { join } from 'path';
3-
import { getGlobalVariable } from '../../utils/env';
43
import { expectFileToExist, expectFileToMatch, readFile } from '../../utils/fs';
54
import { noSilentNg } from '../../utils/process';
65

@@ -33,10 +32,7 @@ export default async function () {
3332
// Check for cache busting hash script src
3433
await expectFileToMatch('dist/test-project/index.html', /main\.[0-9a-zA-Z]{8,16}\.js/);
3534
await expectFileToMatch('dist/test-project/index.html', /styles\.[0-9a-zA-Z]{8,16}\.css/);
36-
if (!getGlobalVariable('argv')['esbuild']) {
37-
// EXPERIMENTAL_ESBUILD: esbuild does not yet extract license text
38-
await expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/);
39-
}
35+
await expectFileToMatch('dist/test-project/3rdpartylicenses.txt', /MIT/);
4036

4137
const indexContent = await readFile('dist/test-project/index.html');
4238
const mainPath = indexContent.match(/src="(main\.[0-9a-zA-Z]{0,32}\.js)"/)![1];

tests/legacy-cli/e2e/tests/build/relative-sourcemap.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ import { updateJsonFile } from '../../utils/project';
88
export default async function () {
99
// General secondary application project
1010
await ng('generate', 'application', 'secondary-project', '--skip-install');
11-
// Setup esbuild builder if requested on the commandline
12-
const useEsbuildBuilder = !!getGlobalVariable('argv')['esbuild'];
13-
if (useEsbuildBuilder) {
11+
// Setup webpack builder if esbuild is not requested on the commandline
12+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
13+
if (useWebpackBuilder) {
1414
await updateJsonFile('angular.json', (json) => {
15-
json['projects']['secondary-project']['architect']['build']['builder'] =
16-
'@angular-devkit/build-angular:browser-esbuild';
15+
const build = json['projects']['secondary-project']['architect']['build'];
16+
build.builder = '@angular-devkit/build-angular:browser';
17+
build.options = {
18+
...build.options,
19+
main: build.options.browser,
20+
browser: undefined,
21+
};
22+
23+
build.configurations.development = {
24+
...build.configurations.development,
25+
vendorChunk: true,
26+
namedChunks: true,
27+
buildOptimizer: false,
28+
};
1729
});
1830
}
1931

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ const snapshots = require('../../../ng-snapshot/package.json');
99

1010
export default async function () {
1111
await ng('generate', 'application', 'test-project-two', '--standalone', '--skip-install');
12+
13+
// Setup webpack builder if esbuild is not requested on the commandline
14+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
15+
if (useWebpackBuilder) {
16+
await updateJsonFile('angular.json', (json) => {
17+
const build = json['projects']['test-project-two']['architect']['build'];
18+
build.builder = '@angular-devkit/build-angular:browser';
19+
build.options = {
20+
...build.options,
21+
main: build.options.browser,
22+
browser: undefined,
23+
};
24+
25+
build.configurations.development = {
26+
...build.configurations.development,
27+
vendorChunk: true,
28+
namedChunks: true,
29+
buildOptimizer: false,
30+
};
31+
});
32+
}
33+
1234
await ng('generate', 'server', '--project', 'test-project-two');
1335

1436
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ const snapshots = require('../../../ng-snapshot/package.json');
99

1010
export default async function () {
1111
await ng('generate', 'application', 'test-project-two', '--standalone', '--skip-install');
12+
13+
// Setup webpack builder if esbuild is not requested on the commandline
14+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
15+
if (useWebpackBuilder) {
16+
await updateJsonFile('angular.json', (json) => {
17+
const build = json['projects']['test-project-two']['architect']['build'];
18+
build.builder = '@angular-devkit/build-angular:browser';
19+
build.options = {
20+
...build.options,
21+
main: build.options.browser,
22+
browser: undefined,
23+
};
24+
25+
build.configurations.development = {
26+
...build.configurations.development,
27+
vendorChunk: true,
28+
namedChunks: true,
29+
buildOptimizer: false,
30+
};
31+
});
32+
}
33+
1234
await ng('generate', 'server', '--project', 'test-project-two');
1335

1436
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default async function () {
3333
` import 'zone.js/dist/zone-node';
3434
import * as fs from 'fs';
3535
import { renderModule } from '@angular/platform-server';
36-
import { AppServerModule } from './src/main.server';
36+
import AppServerModule from './src/main.server';
3737
3838
renderModule(AppServerModule, {
3939
url: '/',
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { getGlobalVariable } from '../../../utils/env';
21
import { writeMultipleFiles, expectFileToMatch, replaceInFile, createDir } from '../../../utils/fs';
32
import { ng } from '../../../utils/process';
43
import { updateJsonFile } from '../../../utils/project';
54

65
export default async function () {
7-
// esbuild currently only supports Sass
8-
const esbuild = getGlobalVariable('argv')['esbuild'];
9-
106
await createDir('src/style-paths');
117
await writeMultipleFiles({
128
'src/style-paths/_variables.scss': '$primary-color: red;',
@@ -32,15 +28,15 @@ export default async function () {
3228
await replaceInFile(
3329
'src/app/app.component.ts',
3430
`'./app.component.css\'`,
35-
`'./app.component.scss'` + (esbuild ? '' : `, './app.component.less'`),
31+
`'./app.component.scss', './app.component.less'`,
3632
);
3733

3834
await updateJsonFile('angular.json', (workspaceJson) => {
3935
const appArchitect = workspaceJson.projects['test-project'].architect;
40-
appArchitect.build.options.styles = [{ input: 'src/styles.scss' }];
41-
if (!esbuild) {
42-
appArchitect.build.options.styles.push({ input: 'src/styles.less' });
43-
}
36+
appArchitect.build.options.styles = [
37+
{ input: 'src/styles.scss' },
38+
{ input: 'src/styles.less' },
39+
];
4440
appArchitect.build.options.stylePreprocessorOptions = {
4541
includePaths: ['src/style-paths'],
4642
};
@@ -49,19 +45,13 @@ export default async function () {
4945
await ng('build', '--configuration=development');
5046
await expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/);
5147
await expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/);
52-
if (!esbuild) {
53-
// These checks are for the less files
54-
await expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/);
55-
await expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/);
56-
}
57-
58-
// esbuild currently only supports AOT and not JIT mode
59-
if (!esbuild) {
60-
await ng('build', '--no-aot', '--configuration=development');
48+
// These checks are for the less files
49+
await expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/);
50+
await expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/);
6151

62-
await expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/);
63-
await expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/);
64-
await expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/);
65-
await expectFileToMatch('dist/test-project/main.js', /h6.*{\s*color: #ADDADD;\s*}/);
66-
}
52+
await ng('build', '--no-aot', '--configuration=development');
53+
await expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/);
54+
await expectFileToMatch('dist/test-project/main.js', /h2.*{[\S\s]*color: red;[\S\s]*}/);
55+
await expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/);
56+
await expectFileToMatch('dist/test-project/main.js', /h6.*{[\S\s]*color: #ADDADD;[\S\s]*}/);
6757
}

tests/legacy-cli/e2e/tests/commands/add/npm-env-vars.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs';
2+
import { installWorkspacePackages } from '../../../utils/packages';
23
import { git, ng } from '../../../utils/process';
34
import {
45
createNpmConfigForAuthentication,
@@ -23,4 +24,7 @@ export default async function () {
2324
await createNpmConfigForAuthentication(false, true);
2425
await ng(...command);
2526
await expectFileToExist('src/manifest.webmanifest');
27+
28+
await git('clean', '-dxf');
29+
await installWorkspacePackages();
2630
}

tests/legacy-cli/e2e/tests/commands/add/secure-registry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs';
2+
import { installWorkspacePackages } from '../../../utils/packages';
23
import { git, ng } from '../../../utils/process';
34
import { createNpmConfigForAuthentication } from '../../../utils/registry';
45
import { expectToFail } from '../../../utils/utils';
@@ -29,4 +30,7 @@ export default async function () {
2930

3031
await createNpmConfigForAuthentication(true, true);
3132
await expectToFail(() => ng(...command));
33+
34+
await git('clean', '-dxf');
35+
await installWorkspacePackages();
3236
}

0 commit comments

Comments
 (0)