Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(@angular-devkit/build-angular): execute all basic E2E tests with esbuild builder #25024

Merged
merged 1 commit into from Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/legacy-cli/e2e.bzl
Expand Up @@ -41,10 +41,6 @@ ESBUILD_TESTS = [

# Tests excluded for esbuild
ESBUILD_IGNORE_TESTS = [
"tests/basic/environment.js",
"tests/basic/rebuild.js",
"tests/basic/serve.js",
"tests/basic/scripts-array.js",
]

def _to_glob(patterns):
Expand Down
9 changes: 6 additions & 3 deletions tests/legacy-cli/e2e/tests/basic/rebuild.ts
Expand Up @@ -2,10 +2,13 @@ import { waitForAnyProcessOutputToMatch, silentNg } from '../../utils/process';
import { writeFile, writeMultipleFiles } from '../../utils/fs';
import fetch from 'node-fetch';
import { ngServe } from '../../utils/project';

const validBundleRegEx = / Compiled successfully./;
import { getGlobalVariable } from '../../utils/env';

export default async function () {
const esbuild = getGlobalVariable('argv')['esbuild'];
const validBundleRegEx = esbuild ? /Complete\./ : /Compiled successfully\./;
const lazyBundleRegEx = esbuild ? /lazy\.module/ : /lazy_module_ts\.js/;

const port = await ngServe();
// Add a lazy module.
await silentNg('generate', 'module', 'lazy', '--routing');
Expand All @@ -15,7 +18,7 @@ export default async function () {
// the file, otherwise rebuilds can be too fast and fail CI.
// Count the bundles.
await Promise.all([
waitForAnyProcessOutputToMatch(/lazy_module_ts\.js/),
waitForAnyProcessOutputToMatch(lazyBundleRegEx),
writeFile(
'src/app/app.module.ts',
`
Expand Down
35 changes: 24 additions & 11 deletions tests/legacy-cli/e2e/tests/basic/scripts-array.ts
@@ -1,3 +1,4 @@
import { getGlobalVariable } from '../../utils/env';
import { appendToFile, expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
Expand Down Expand Up @@ -50,15 +51,27 @@ export default async function () {
await expectFileToMatch('dist/test-project/renamed-lazy-script.js', 'pre-rename-lazy-script');

// index.html lists the right bundles
await expectFileToMatch(
'dist/test-project/index.html',
[
'<script src="runtime.js" type="module"></script>',
'<script src="polyfills.js" type="module"></script>',
'<script src="scripts.js" defer></script>',
'<script src="renamed-script.js" defer></script>',
'<script src="vendor.js" type="module"></script>',
'<script src="main.js" type="module"></script>',
].join(''),
);
if (getGlobalVariable('argv')['esbuild']) {
await expectFileToMatch(
'dist/test-project/index.html',
[
'<script src="polyfills.js" type="module"></script>',
'<script src="scripts.js" defer></script>',
'<script src="renamed-script.js" defer></script>',
'<script src="main.js" type="module"></script>',
].join(''),
);
} else {
await expectFileToMatch(
'dist/test-project/index.html',
[
'<script src="runtime.js" type="module"></script>',
'<script src="polyfills.js" type="module"></script>',
'<script src="scripts.js" defer></script>',
'<script src="renamed-script.js" defer></script>',
'<script src="vendor.js" type="module"></script>',
'<script src="main.js" type="module"></script>',
].join(''),
);
}
}
9 changes: 2 additions & 7 deletions tests/legacy-cli/e2e/tests/basic/styles-array.ts
@@ -1,4 +1,3 @@
import { getGlobalVariable } from '../../utils/env';
import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
Expand Down Expand Up @@ -39,13 +38,9 @@ export default async function () {
'<link rel="stylesheet" href="styles.css"><link rel="stylesheet" href="renamed-style.css">',
);

if (getGlobalVariable('argv')['esbuild']) {
// EXPERIMENTAL_ESBUILD: esbuild does not yet output build stats
return;
}

// Non injected styles should be listed under lazy chunk files
if (!/Lazy Chunk Files.*\srenamed-lazy-style\.css/m.test(stdout)) {
if (!/Lazy Chunk Files[\s\S]+renamed-lazy-style\.css/m.test(stdout)) {
console.log(stdout);
throw new Error(`Expected "renamed-lazy-style.css" to be listed under "Lazy Chunk Files".`);
}
}
5 changes: 4 additions & 1 deletion tests/legacy-cli/e2e/utils/project.ts
Expand Up @@ -26,10 +26,13 @@ export function updateTsConfig(fn: (json: any) => any | void) {
export async function ngServe(...args: string[]) {
const port = await findFreePort();

const esbuild = getGlobalVariable('argv')['esbuild'];
const validBundleRegEx = esbuild ? /Complete\./ : /Compiled successfully\./;

await execAndWaitForOutputToMatch(
'ng',
['serve', '--port', String(port), ...args],
/ Compiled successfully./,
validBundleRegEx,
);

return port;
Expand Down