Skip to content

Commit 842c8ef

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

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
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

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ng } from '../../utils/process';
2-
import { appendToFile, replaceInFile, readFile } from '../../utils/fs';
2+
import { replaceInFile, readFile, writeFile } from '../../utils/fs';
33
import { applyVitestBuilder } from '../../utils/vitest';
44
import assert from 'node:assert/strict';
55
import { stripVTControlCharacters } from 'node:util';
@@ -9,23 +9,32 @@ export default async function () {
99
await applyVitestBuilder();
1010

1111
// Add snapshot assertions to the test file
12-
await appendToFile(
12+
await replaceInFile(
1313
'src/app/app.spec.ts',
14+
`describe('App', () => {`,
1415
`
15-
it('should match file snapshot', () => {
16-
const fixture = TestBed.createComponent(App);
17-
const app = fixture.componentInstance;
18-
expect((app as any).title()).toMatchSnapshot();
19-
});
16+
describe('App', () => {
17+
it('should match file snapshot', () => {
18+
const fixture = TestBed.createComponent(App);
19+
const app = fixture.componentInstance;
20+
expect((app as any).title()).toMatchSnapshot();
21+
});
2022
21-
it('should match inline snapshot', () => {
22-
const fixture = TestBed.createComponent(App);
23-
const app = fixture.componentInstance;
24-
expect((app as any).title()).toMatchInlineSnapshot();
25-
});
26-
`,
23+
it('should match inline snapshot', () => {
24+
const fixture = TestBed.createComponent(App);
25+
const app = fixture.componentInstance;
26+
expect((app as any).title()).toMatchInlineSnapshot();
27+
});
28+
`,
2729
);
2830

31+
// Synchronize line endings for Vitest which currently may miscalculate line counts
32+
// with mixed file line endings.
33+
let content = await readFile('src/app/app.spec.ts');
34+
content = content.replace(/\r\n/g, '\n');
35+
content = content.replace(/\r/g, '\n');
36+
await writeFile('src/app/app.spec.ts', content);
37+
2938
// First run: create snapshots
3039
const { stdout: firstRunStdout } = await ng('test');
3140
assert.match(
@@ -44,7 +53,7 @@ export default async function () {
4453
const snapshotContent = await readFile('src/app/__snapshots__/app.spec.ts.snap');
4554
assert.match(
4655
snapshotContent,
47-
/exports\[`should match file snapshot 1`\] = `"test-project"`;/,
56+
/exports\[`App > should match file snapshot 1`\] = `"test-project"`;/,
4857
'File snapshot was not written to disk.',
4958
);
5059

0 commit comments

Comments
 (0)