Skip to content

Commit

Permalink
test: enable build E2E tests for esbuild-based builders
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clydin authored and alan-agius4 committed Nov 1, 2023
1 parent 974acb7 commit 8bd90ff
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 204 deletions.
10 changes: 1 addition & 9 deletions tests/legacy-cli/e2e.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ BROWSER_TESTS = ["tests/misc/browsers.js"]
YARN_TESTS = ["tests/basic/**", "tests/update/**", "tests/commands/add/**"]
ESBUILD_TESTS = [
"tests/basic/**",
"tests/build/app-shell/app-shell-standalone.js",
"tests/build/app-shell/app-shell-with-schematic.js",
"tests/build/library/**",
"tests/build/ssr/**",
"tests/build/prod-build.js",
"tests/build/relative-sourcemap.js",
"tests/build/styles/**",
"tests/build/prerender/**",
"tests/build/worker.js",
"tests/build/**",
"tests/commands/add/**",
"tests/i18n/**",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { updateJsonFile } from '../../../utils/project';
const snapshots = require('../../../ng-snapshot/package.json');

export default async function () {
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];

await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
await ng('generate', 'service-worker', '--project', 'test-project');
await ng('generate', 'app-shell', '--project', 'test-project');
Expand Down Expand Up @@ -49,7 +51,12 @@ export default async function () {
`,
);

await ng('run', 'test-project:app-shell:production');
if (useWebpackBuilder) {
await ng('run', 'test-project:app-shell:production');
} else {
await ng('build');
}
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);

await ng('e2e', '--configuration=production');
}
10 changes: 0 additions & 10 deletions tests/legacy-cli/e2e/tests/build/base-href.ts

This file was deleted.

18 changes: 0 additions & 18 deletions tests/legacy-cli/e2e/tests/build/build-optimizer.ts

This file was deleted.

21 changes: 16 additions & 5 deletions tests/legacy-cli/e2e/tests/build/bundle-budgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { getGlobalVariable } from '../../utils/env';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

export default async function () {
const usingWebpack = !getGlobalVariable('argv')['esbuild'];

// Error
await updateJsonFile('angular.json', (json) => {
json.projects['test-project'].architect.build.configurations.production.budgets = [
{ type: 'all', maximumError: '100b' },
];
});

const { message: errorMessage } = await expectToFail(() => ng('build'));
if (!/Error.+budget/.test(errorMessage)) {
throw new Error('Budget error: all, max error.');
if (usingWebpack) {
const { message: errorMessage } = await expectToFail(() => ng('build'));
if (!/Error.+budget/i.test(errorMessage)) {
throw new Error('Budget error: all, max error.');
}
} else {
// Application builder does not generate an error exit code for budget failures
const { stderr } = await ng('build');
if (!/Error.+budget/i.test(stderr)) {
throw new Error('Budget error: all, max error.');
}
}

// Warning
Expand All @@ -30,7 +41,7 @@ export default async function () {
});

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

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

const { stderr: stderr2 } = await ng('build');
if (/(Warning|Error)/.test(stderr2)) {
if (/(Warning|Error)/i.test(stderr2)) {
throw new Error('BIG max for all, should not error');
}
}
107 changes: 54 additions & 53 deletions tests/legacy-cli/e2e/tests/build/css-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,73 @@ import {
} from '../../utils/fs';
import { copyProjectAsset } from '../../utils/assets';
import { expectToFail } from '../../utils/utils';
import { getGlobalVariable } from '../../utils/env';

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

export default function () {
return (
Promise.resolve()
// Verify absolute/relative paths in global/component css.
.then(() =>
writeMultipleFiles({
'src/styles.css': `
export default async function () {
const usingWebpack = !getGlobalVariable('argv')['esbuild'];

const mediaPath = usingWebpack
? './dist/test-project/browser'
: './dist/test-project/browser/media';

await Promise.resolve()
// Verify absolute/relative paths in global/component css.
.then(() =>
writeMultipleFiles({
'src/styles.css': `
h1 { background: url('/assets/global-img-absolute.svg'); }
h2 { background: url('./assets/global-img-relative.png'); }
`,
'src/app/app.component.css': `
'src/app/app.component.css': `
h3 { background: url('/assets/component-img-absolute.svg'); }
h4 { background: url('../assets/component-img-relative.png'); }
`,
'src/assets/global-img-absolute.svg': imgSvg,
'src/assets/component-img-absolute.svg': imgSvg,
}),
)
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/global-img-relative.png'))
.then(() =>
copyProjectAsset('images/spectrum.png', './src/assets/component-img-relative.png'),
)
.then(() => ng('build', '--aot', '--configuration=development'))
// Check paths are correctly generated.
.then(() =>
expectFileToMatch('dist/test-project/browser/styles.css', 'assets/global-img-absolute.svg'),
)
.then(() =>
expectFileToMatch(
'dist/test-project/browser/styles.css',
/url\('\/assets\/global-img-absolute\.svg'\)/,
),
)
.then(() =>
expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/),
)
.then(() =>
expectFileToMatch(
'dist/test-project/browser/main.js',
'/assets/component-img-absolute.svg',
),
)
.then(() =>
expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/),
)
// Check files are correctly created.
.then(() =>
expectToFail(() => expectFileToExist('dist/test-project/browser/global-img-absolute.svg')),
)
.then(() =>
expectToFail(() =>
expectFileToExist('dist/test-project/browser/component-img-absolute.svg'),
),
)
.then(() => expectFileMatchToExist('./dist/test-project/browser', /global-img-relative\.png/))
.then(() =>
expectFileMatchToExist('./dist/test-project/browser', /component-img-relative\.png/),
)
// Check urls with deploy-url scheme are used as is.
'src/assets/global-img-absolute.svg': imgSvg,
'src/assets/component-img-absolute.svg': imgSvg,
}),
)
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/global-img-relative.png'))
.then(() => copyProjectAsset('images/spectrum.png', './src/assets/component-img-relative.png'))
.then(() => ng('build', '--aot', '--configuration=development'))
// Check paths are correctly generated.
.then(() =>
expectFileToMatch('dist/test-project/browser/styles.css', 'assets/global-img-absolute.svg'),
)
.then(() =>
expectFileToMatch(
'dist/test-project/browser/styles.css',
/url\((['"]?)\/assets\/global-img-absolute\.svg\1\)/,
),
)
.then(() =>
expectFileToMatch('dist/test-project/browser/styles.css', /global-img-relative\.png/),
)
.then(() =>
expectFileToMatch('dist/test-project/browser/main.js', '/assets/component-img-absolute.svg'),
)
.then(() =>
expectFileToMatch('dist/test-project/browser/main.js', /component-img-relative\.png/),
)
// Check files are correctly created.
.then(() => expectToFail(() => expectFileToExist(`${mediaPath}/global-img-absolute.svg`)))
.then(() => expectToFail(() => expectFileToExist(`${mediaPath}/component-img-absolute.svg`)))
.then(() => expectFileMatchToExist(mediaPath, /global-img-relative\.png/))
.then(() => expectFileMatchToExist(mediaPath, /component-img-relative\.png/));

// Early exit before deploy url tests
if (!usingWebpack) {
return;
}

// Check urls with deploy-url scheme are used as is.
return (
Promise.resolve()
.then(() =>
ng(
'build',
Expand Down
5 changes: 5 additions & 0 deletions tests/legacy-cli/e2e/tests/build/deploy-url.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { ng } from '../../utils/process';
import { copyProjectAsset } from '../../utils/assets';
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { getGlobalVariable } from '../../utils/env';

export default function () {
if (getGlobalVariable('argv')['esbuild']) {
return;
}

return (
Promise.resolve()
.then(() =>
Expand Down
16 changes: 14 additions & 2 deletions tests/legacy-cli/e2e/tests/build/extract-licenses.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getGlobalVariable } from '../../utils/env';
import { expectFileToExist, expectFileToMatch } from '../../utils/fs';
import { ng } from '../../utils/process';
import { expectToFail } from '../../utils/utils';

export default async function () {
const usingWebpack = !getGlobalVariable('argv')['esbuild'];

// Licenses should be left intact if extraction is disabled
await ng('build', '--extract-licenses=false', '--output-hashing=none');

await expectToFail(() => expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt'));
if (usingWebpack) {
await expectToFail(() => expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt'));
} else {
// Application builder puts the licenses at the output path root
await expectToFail(() => expectFileToExist('dist/test-project/3rdpartylicenses.txt'));
}
await expectFileToMatch('dist/test-project/browser/main.js', '@license');

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

await expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt');
if (usingWebpack) {
await expectFileToExist('dist/test-project/browser/3rdpartylicenses.txt');
} else {
await expectFileToExist('dist/test-project/3rdpartylicenses.txt');
}
await expectToFail(() => expectFileToMatch('dist/test-project/browser/main.js', '@license'));
}
5 changes: 4 additions & 1 deletion tests/legacy-cli/e2e/tests/build/jit-prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getGlobalVariable } from '../../utils/env';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';

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

// Test it works
Expand Down
8 changes: 7 additions & 1 deletion tests/legacy-cli/e2e/tests/build/multiple-configs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { getGlobalVariable } from '../../utils/env';
import { expectFileToExist } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

export default async function () {
// TODO: Restructure to support application builder option
// This only needs to be tested once since it is really testing the CLI itself and not the builders
if (getGlobalVariable('argv')['esbuild']) {
return;
}

await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
// These are the default options, that we'll overwrite in subsequent configs.
Expand All @@ -13,7 +20,6 @@ export default async function () {
defaultConfiguration: undefined,
options: {
...appArchitect['build'].options,
buildOptimizer: false,
optimization: false,
sourceMap: true,
outputHashing: 'none',
Expand Down
44 changes: 0 additions & 44 deletions tests/legacy-cli/e2e/tests/build/no-sourcemap.ts

This file was deleted.

Loading

0 comments on commit 8bd90ff

Please sign in to comment.