Skip to content

Commit bb29254

Browse files
committed
test(@angular/build): add e2e for a larger project with Vitest
Adds an end-to-end test to verify Vitest runner performance and correctness with a larger number of generated components, services, and pipes. This test executes the suite in both JSDOM and browser environments to ensure stability and proper functionality under scale. (cherry picked from commit 960c80c)
1 parent e843cb6 commit bb29254

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { ng } from '../../utils/process';
2+
import { applyVitestBuilder } from '../../utils/vitest';
3+
import assert from 'node:assert';
4+
import { installPackage } from '../../utils/packages';
5+
import { exec } from '../../utils/process';
6+
7+
export default async function () {
8+
await applyVitestBuilder();
9+
10+
const artifactCount = 100;
11+
// A new project starts with 1 test file (app.spec.ts)
12+
// Each generated artifact will add one more test file.
13+
const initialTestCount = 1;
14+
15+
// Generate a mix of components, services, and pipes
16+
for (let i = 0; i < artifactCount; i++) {
17+
const type = i % 3;
18+
const name = `test-artifact-${i}`;
19+
let generateType;
20+
21+
switch (type) {
22+
case 0:
23+
generateType = 'component';
24+
break;
25+
case 1:
26+
generateType = 'service';
27+
break;
28+
default:
29+
generateType = 'pipe';
30+
break;
31+
}
32+
33+
await ng('generate', generateType, name, '--skip-tests=false');
34+
}
35+
36+
const totalTests = initialTestCount + artifactCount;
37+
const expectedMessage = new RegExp(`${totalTests} passed`);
38+
39+
// Run tests in default (JSDOM) mode
40+
const { stdout: jsdomStdout } = await ng('test', '--no-watch');
41+
assert.match(jsdomStdout, expectedMessage, `Expected ${totalTests} tests to pass in JSDOM mode.`);
42+
43+
// Setup for browser mode
44+
await installPackage('playwright@1');
45+
await installPackage('@vitest/browser-playwright@4');
46+
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');
47+
48+
// Run tests in browser mode
49+
const { stdout: browserStdout } = await ng(
50+
'test',
51+
'--no-watch',
52+
'--browsers',
53+
'ChromiumHeadless',
54+
);
55+
assert.match(
56+
browserStdout,
57+
expectedMessage,
58+
`Expected ${totalTests} tests to pass in browser mode.`,
59+
);
60+
}

0 commit comments

Comments
 (0)