Skip to content

Commit 142ff57

Browse files
committed
test: attempt to workaround Windows snapshot E2E flakes
1 parent 138649e commit 142ff57

File tree

3 files changed

+19
-11
lines changed
  • .github/workflows
  • packages/angular/build/src/builders/unit-test/runners/vitest
  • tests/legacy-cli/e2e/tests/vitest

3 files changed

+19
-11
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
test_target_name: e2e.esbuild_node22
172172
env:
173173
E2E_SHARD_TOTAL: 1
174-
TESTBRIDGE_TEST_ONLY: tests/basic/{build,rebuild}.ts
174+
TESTBRIDGE_TEST_ONLY: tests/vitest/snapshot.ts
175175

176176
e2e-package-managers:
177177
needs: build

packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function createVitestConfigPlugin(
118118
setupFiles,
119119
globals: true,
120120
// Allow Vitest to manage test isolation by its default behavior.
121-
sequence: { setupFiles: 'list' },
121+
// sequence: { setupFiles: 'list' },
122122
},
123123
optimizeDeps: {
124124
noDiscovery: true,

tests/legacy-cli/e2e/tests/vitest/snapshot.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { ng } from '../../utils/process';
1+
import { exec, ng, noSilentNg } from '../../utils/process';
22
import { appendToFile, replaceInFile, readFile } from '../../utils/fs';
33
import { applyVitestBuilder } from '../../utils/vitest';
44
import assert from 'node:assert/strict';
55
import { stripVTControlCharacters } from 'node:util';
6+
import { setTimeout } from 'node:timers/promises';
67

78
export default async function () {
89
// Set up the test project to use the vitest runner
@@ -26,28 +27,35 @@ export default async function () {
2627
`,
2728
);
2829

30+
await replaceInFile(
31+
'node_modules/@vitest/snapshot/dist/environment.js',
32+
'await promises.mkdir',
33+
'console.log(filepath);\nawait promises.mkdir',
34+
);
35+
2936
// First run: create snapshots
30-
const { stdout: firstRunStdout } = await ng('test');
37+
const { stdout: firstRunStdout } = await noSilentNg('test');
3138
assert.match(
3239
stripVTControlCharacters(firstRunStdout),
3340
/Snapshots\s+2 written/,
3441
'Snapshots were not written on the first run.',
3542
);
3643

37-
const specContent = await readFile('src/app/app.spec.ts');
38-
assert.match(
39-
specContent,
40-
/toMatchInlineSnapshot\(`"test-project"`\)/,
41-
'Inline snapshot was not written to the spec file.',
42-
);
43-
4444
const snapshotContent = await readFile('src/app/__snapshots__/app.spec.ts.snap');
4545
assert.match(
4646
snapshotContent,
4747
/exports\[`should match file snapshot 1`\] = `"test-project"`;/,
4848
'File snapshot was not written to disk.',
4949
);
5050

51+
const specContent = await readFile('src/app/app.spec.ts');
52+
console.log(specContent);
53+
assert.match(
54+
specContent,
55+
/toMatchInlineSnapshot\(`"test-project"`\)/,
56+
'Inline snapshot was not written to the spec file.',
57+
);
58+
5159
// Second run: tests should pass with existing snapshots
5260
await ng('test');
5361

0 commit comments

Comments
 (0)