1- import { ng } from '../../utils/process' ;
1+ import { exec , ng , noSilentNg } from '../../utils/process' ;
22import { appendToFile , replaceInFile , readFile } from '../../utils/fs' ;
33import { applyVitestBuilder } from '../../utils/vitest' ;
44import assert from 'node:assert/strict' ;
55import { stripVTControlCharacters } from 'node:util' ;
6+ import { setTimeout } from 'node:timers/promises' ;
67
78export default async function ( ) {
89 // Set up the test project to use the vitest runner
@@ -26,28 +27,41 @@ export default async function () {
2627 ` ,
2728 ) ;
2829
30+ await replaceInFile (
31+ 'node_modules/@vitest/snapshot/dist/index.js' ,
32+ 'const transformed = s.toString()' ,
33+ 'console.log(file, JSON.stringify(snapshots, null, 2));\nconst transformed = s.toString()' ,
34+ ) ;
35+
36+ await replaceInFile (
37+ 'node_modules/@vitest/snapshot/dist/index.js' ,
38+ 'const transformed = s.toString();' ,
39+ 'const transformed = s.toString();console.log(transformed);' ,
40+ ) ;
41+
2942 // First run: create snapshots
30- const { stdout : firstRunStdout } = await ng ( 'test' ) ;
43+ const { stdout : firstRunStdout } = await noSilentNg ( 'test' ) ;
3144 assert . match (
3245 stripVTControlCharacters ( firstRunStdout ) ,
3346 / S n a p s h o t s \s + 2 w r i t t e n / ,
3447 'Snapshots were not written on the first run.' ,
3548 ) ;
3649
37- const specContent = await readFile ( 'src/app/app.spec.ts' ) ;
38- assert . match (
39- specContent ,
40- / t o M a t c h I n l i n e S n a p s h o t \( ` " t e s t - p r o j e c t " ` \) / ,
41- 'Inline snapshot was not written to the spec file.' ,
42- ) ;
43-
4450 const snapshotContent = await readFile ( 'src/app/__snapshots__/app.spec.ts.snap' ) ;
4551 assert . match (
4652 snapshotContent ,
4753 / 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 " ` ; / ,
4854 'File snapshot was not written to disk.' ,
4955 ) ;
5056
57+ const specContent = await readFile ( 'src/app/app.spec.ts' ) ;
58+ console . log ( specContent ) ;
59+ assert . match (
60+ specContent ,
61+ / t o M a t c h I n l i n e S n a p s h o t \( ` " t e s t - p r o j e c t " ` \) / ,
62+ 'Inline snapshot was not written to the spec file.' ,
63+ ) ;
64+
5165 // Second run: tests should pass with existing snapshots
5266 await ng ( 'test' ) ;
5367
0 commit comments