1- import { ng } from '../../utils/process' ;
1+ import { ng , noSilentNg } from '../../utils/process' ;
22import { applyVitestBuilder } from '../../utils/vitest' ;
33import assert from 'node:assert' ;
44import { installPackage } from '../../utils/packages' ;
55import { exec } from '../../utils/process' ;
66import { updateJsonFile } from '../../utils/project' ;
7- import { readFile } from '../../utils/fs' ;
7+ import { readFile , replaceInFile } from '../../utils/fs' ;
88
99export default async function ( ) {
1010 await applyVitestBuilder ( ) ;
@@ -59,29 +59,62 @@ export default async function () {
5959 const expectedMessage = new RegExp ( `${ totalTests } passed` ) ;
6060 const coverageJsonPath = 'coverage/test-project/coverage-final.json' ;
6161
62+ // Check for raw v8 coverage info
63+ // await replaceInFile(
64+ // 'node_modules/@vitest/coverage-v8/dist/index.js',
65+ // `return { result };`,
66+ // `console.log(JSON.stringify(result, null, 2));return { result };`,
67+ // );
68+
69+ // await replaceInFile(
70+ // 'node_modules/@vitest/coverage-v8/dist/provider.js',
71+ // `if (this.isIncluded(fileURLToPath(result.url))) {`,
72+ // `console.log('CHECKING:', result.url);if (this.isIncluded(fileURLToPath(result.url))) {console.log('INCLUDED:', result.url);`,
73+ // );
74+
75+ // await replaceInFile(
76+ // 'node_modules/@vitest/coverage-v8/dist/provider.js',
77+ // `const exists = existsSync(filename);`,
78+ // `const exists = existsSync(filename);console.log('EXISTS:', filename, exists);`,
79+ // );
80+
81+ await replaceInFile (
82+ 'node_modules/@vitest/coverage-v8/dist/provider.js' ,
83+ `let ast;` ,
84+ `let ast;console.log('REMAPPING:', filename);` ,
85+ ) ;
86+
87+ await replaceInFile (
88+ 'node_modules/@vitest/coverage-v8/dist/provider.js' ,
89+ `removeStartsWith(url, FILE_PROTOCOL)` ,
90+ `fileURLToPath(url)` ,
91+ ) ;
92+
6293 // Run tests in default (JSDOM) mode with coverage
63- const { stdout : jsdomStdout } = await ng ( 'test' , '--no-watch' , '--coverage' ) ;
94+ const { stdout : jsdomStdout } = await noSilentNg ( 'test' , '--no-watch' , '--coverage' ) ;
6495 assert . match ( jsdomStdout , expectedMessage , `Expected ${ totalTests } tests to pass in JSDOM mode.` ) ;
6596
97+ const jsdomSummary = JSON . parse ( await readFile ( coverageJsonPath ) ) ;
6698 // TODO: Investigate why coverage-final.json is empty on Windows in JSDOM mode.
6799 // For now, skip the coverage report check on Windows.
68100 if ( process . platform !== 'win32' ) {
69101 // Assert that every generated file is in the coverage report by reading the JSON output.
70- const jsdomSummary = JSON . parse ( await readFile ( coverageJsonPath ) ) ;
102+
71103 const jsdomSummaryKeys = Object . keys ( jsdomSummary ) ;
72104 for ( const file of generatedFiles ) {
73105 const found = jsdomSummaryKeys . some ( ( key ) => key . endsWith ( file ) ) ;
74106 assert . ok ( found , `Expected ${ file } to be in the JSDOM coverage report.` ) ;
75107 }
76108 }
109+ console . log ( JSON . stringify ( jsdomSummary , null , 2 ) ) ;
77110
78111 // Setup for browser mode
79112 await installPackage ( 'playwright@1' ) ;
80113 await installPackage ( '@vitest/browser-playwright@4' ) ;
81114 await exec ( 'npx' , 'playwright' , 'install' , 'chromium' , '--only-shell' ) ;
82115
83116 // Run tests in browser mode with coverage
84- const { stdout : browserStdout } = await ng (
117+ const { stdout : browserStdout } = await noSilentNg (
85118 'test' ,
86119 '--no-watch' ,
87120 '--coverage' ,
@@ -101,4 +134,6 @@ export default async function () {
101134 const found = browserSummaryKeys . some ( ( key ) => key . endsWith ( file ) ) ;
102135 assert . ok ( found , `Expected ${ file } to be in the browser coverage report.` ) ;
103136 }
137+
138+ console . log ( JSON . stringify ( browserSummaryKeys , null , 2 ) ) ;
104139}
0 commit comments