11import { ng } from '../../utils/process' ;
2- import { appendToFile , replaceInFile , readFile } from '../../utils/fs' ;
2+ import { replaceInFile , readFile , writeFile } from '../../utils/fs' ;
33import { applyVitestBuilder } from '../../utils/vitest' ;
44import assert from 'node:assert/strict' ;
55import { 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- / e x p o r t s \[ ` s h o u l d m a t c h f i l e s n a p s h o t 1 ` \] = ` " t e s t - p r o j e c t " ` ; / ,
56+ / e x p o r t s \[ ` A p p > s h o u l d m a t c h f i l e s n a p s h o t 1 ` \] = ` " t e s t - p r o j e c t " ` ; / ,
4857 'File snapshot was not written to disk.' ,
4958 ) ;
5059
0 commit comments