55import fs from 'node:fs/promises' ;
66import path from 'node:path' ;
77import { fileURLToPath } from 'node:url' ;
8- import { existsSync } from 'node:fs' ;
8+ import { existsSync , readdirSync } from 'node:fs' ;
99import { test as base } from '@playwright/test' ;
1010import type { Page } from '@playwright/test' ;
1111import v8ToIstanbul from 'v8-to-istanbul' ;
1212
1313const __dirname = fileURLToPath ( import . meta. url ) ;
14+ const webCoreDist = path . join (
15+ __dirname ,
16+ '..' ,
17+ '..' ,
18+ '..' ,
19+ 'web-core' ,
20+ 'dist' ,
21+ 'client_prod' ,
22+ ) ;
23+ // recursive find all *.map files
24+ const getWebCoreMappedFiles = ( ) => {
25+ try {
26+ const files = readdirSync ( webCoreDist , { recursive : true } ) ;
27+ return files
28+ . filter ( ( f ) => typeof f === 'string' && f . endsWith ( '.map' ) )
29+ . map ( ( f ) => path . join ( webCoreDist , ( f as string ) . replace ( / \. m a p $ / , '' ) ) ) ;
30+ } catch ( e ) {
31+ return [ ] ;
32+ }
33+ } ;
1434
1535export const test : typeof base = base . extend ( {
1636 context : async ( { browserName, context } , use , testInfo ) => {
@@ -39,7 +59,7 @@ export const test: typeof base = base.extend({
3959 await Promise . all (
4060 Array . from ( pages . values ( ) ) . flatMap ( async ( page , index ) => {
4161 const coverage = await page . coverage . stopJSCoverage ( ) ;
42- const sourceFilePath = [
62+ const sourceFilePaths = [
4363 path . join ( path . dirname ( testInfo . file ) , '..' , 'www' , 'main.js' ) ,
4464 path . join (
4565 path . dirname ( testInfo . file ) ,
@@ -49,17 +69,20 @@ export const test: typeof base = base.extend({
4969 'js' ,
5070 'index.js' ,
5171 ) ,
52- ] . find ( ( p ) => existsSync ( p ) ) ! ;
53- const converter = v8ToIstanbul (
54- sourceFilePath ,
55- ) ;
56- await converter . load ( ) ;
72+ ...getWebCoreMappedFiles ( ) ,
73+ ] . filter ( ( p ) => existsSync ( p ) ) ;
5774
58- for ( const entry of coverage ) {
59- converter . applyCoverage ( entry . functions ) ;
60- }
75+ const coverageMapData = { } ;
76+ for ( const sourceFilePath of sourceFilePaths ) {
77+ const converter = v8ToIstanbul ( sourceFilePath ) ;
78+ await converter . load ( ) ;
6179
62- const coverageMapData = converter . toIstanbul ( ) ;
80+ for ( const entry of coverage ) {
81+ converter . applyCoverage ( entry . functions ) ;
82+ }
83+
84+ Object . assign ( coverageMapData , converter . toIstanbul ( ) ) ;
85+ }
6386
6487 return fs . writeFile (
6588 path . join (
0 commit comments