Skip to content

Commit bd63c83

Browse files
committed
test: use node:assert in basic and build E2E tests
Replaces error throwing with Node.js assertions in E2E tests. This provides more informative error messages when tests fail.
1 parent 58065c8 commit bd63c83

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

tests/legacy-cli/e2e/tests/basic/rebuild.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import { setTimeout } from 'node:timers/promises';
23
import { getGlobalVariable } from '../../utils/env';
34
import { appendToFile, replaceInFile, writeMultipleFiles } from '../../utils/fs';
@@ -68,15 +69,9 @@ export default async function () {
6869
{
6970
const response = await fetch(`http://localhost:${port}/main.js`);
7071
const body = await response.text();
71-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
72-
throw new Error('Expected golden value 1.');
73-
}
74-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_2/)) {
75-
throw new Error('Expected golden value 2.');
76-
}
77-
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_3/)) {
78-
throw new Error('Expected golden value 3.');
79-
}
72+
assert.match(body, /\$\$_E2E_GOLDEN_VALUE_1/);
73+
assert.match(body, /\$\$_E2E_GOLDEN_VALUE_2/);
74+
assert.match(body, /\$\$_E2E_GOLDEN_VALUE_3/);
8075
}
8176

8277
await setTimeout(500);
@@ -90,9 +85,7 @@ export default async function () {
9085
{
9186
const response = await fetch(`http://localhost:${port}/main.js`);
9287
const body = await response.text();
93-
if (!body.match(/testingTESTING123/)) {
94-
throw new Error('Expected component HTML to update.');
95-
}
88+
assert.match(body, /testingTESTING123/);
9689
}
9790

9891
await setTimeout(500);
@@ -106,9 +99,7 @@ export default async function () {
10699
{
107100
const response = await fetch(`http://localhost:${port}/main.js`);
108101
const body = await response.text();
109-
if (!body.match(/color:\s?blue/)) {
110-
throw new Error('Expected component CSS to update.');
111-
}
102+
assert.match(body, /color:\s?blue/);
112103
}
113104

114105
await setTimeout(500);
@@ -122,8 +113,6 @@ export default async function () {
122113
{
123114
const response = await fetch(`http://localhost:${port}/styles.css`);
124115
const body = await response.text();
125-
if (!body.match(/color:\s?green/)) {
126-
throw new Error('Expected global CSS to update.');
127-
}
116+
assert.match(body, /color:\s?green/);
128117
}
129118
}

tests/legacy-cli/e2e/tests/basic/serve.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import { killAllProcesses } from '../../utils/process';
23
import { ngServe } from '../../utils/project';
34

@@ -14,14 +15,8 @@ export default async function () {
1415

1516
async function verifyResponse(port: number): Promise<void> {
1617
const indexResponse = await fetch(`http://localhost:${port}/`);
17-
18-
if (!/<app-root><\/app-root>/.test(await indexResponse.text())) {
19-
throw new Error('Response does not match expected value.');
20-
}
18+
assert.match(await indexResponse.text(), /<app-root><\/app-root>/);
2119

2220
const assetResponse = await fetch(`http://localhost:${port}/favicon.ico`);
23-
24-
if (!assetResponse.ok) {
25-
throw new Error('Expected favicon asset to be available.');
26-
}
21+
assert(assetResponse.ok, 'Expected favicon asset to be available.');
2722
}

tests/legacy-cli/e2e/tests/basic/styles-array.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
23
import { ng } from '../../utils/process';
34
import { updateJsonFile } from '../../utils/project';
@@ -42,8 +43,5 @@ export default async function () {
4243
);
4344

4445
// Non injected styles should be listed under lazy chunk files
45-
if (!/Lazy chunk files[\s\S]+renamed-lazy-style\.css/m.test(stdout)) {
46-
console.log(stdout);
47-
throw new Error(`Expected "renamed-lazy-style.css" to be listed under "Lazy chunk files".`);
48-
}
46+
assert.match(stdout, /Lazy chunk files[\s\S]+renamed-lazy-style\.css/m);
4947
}

0 commit comments

Comments
 (0)