-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathlarger-project.ts
More file actions
70 lines (58 loc) · 1.92 KB
/
larger-project.ts
File metadata and controls
70 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';
import assert from 'node:assert';
import { installPackage } from '../../utils/packages';
import { exec } from '../../utils/process';
export default async function () {
await applyVitestBuilder();
const artifactCount = 100;
// A new project starts with 1 test file (app.spec.ts)
// Each generated artifact will add one more test file.
const initialTestCount = 1;
await generateArtifactsInBatches(artifactCount);
const totalTests = initialTestCount + artifactCount;
const expectedMessage = new RegExp(`${totalTests} passed`);
// Run tests in default (JSDOM) mode
const { stdout: jsdomStdout } = await ng('test', '--no-watch');
assert.match(jsdomStdout, expectedMessage, `Expected ${totalTests} tests to pass in JSDOM mode.`);
// Setup for browser mode
await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');
// Run tests in browser mode
const { stdout: browserStdout } = await ng(
'test',
'--no-watch',
'--browsers',
'ChromiumHeadless',
);
assert.match(
browserStdout,
expectedMessage,
`Expected ${totalTests} tests to pass in browser mode.`,
);
}
async function generateArtifactsInBatches(artifactCount: number): Promise<void> {
const BATCH_SIZE = 5;
let commands: Promise<any>[] = [];
for (let i = 0; i < artifactCount; i++) {
const type = i % 3;
const name = `test-artifact-${i}`;
let generateType: string;
switch (type) {
case 0:
generateType = 'component';
break;
case 1:
generateType = 'service';
break;
default:
generateType = 'pipe';
break;
}
commands.push(ng('generate', generateType, name, '--skip-tests=false'));
if (commands.length === BATCH_SIZE || i === artifactCount - 1) {
await Promise.all(commands);
commands = [];
}
}
}