Skip to content

Commit 04be21a

Browse files
authored
fix: web-core background thread module coverage (#2463)
1 parent 3262ca8 commit 04be21a

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

packages/web-platform/playwright-fixtures/src/coverage-fixture.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,32 @@
55
import fs from 'node:fs/promises';
66
import path from 'node:path';
77
import { fileURLToPath } from 'node:url';
8-
import { existsSync } from 'node:fs';
8+
import { existsSync, readdirSync } from 'node:fs';
99
import { test as base } from '@playwright/test';
1010
import type { Page } from '@playwright/test';
1111
import v8ToIstanbul from 'v8-to-istanbul';
1212

1313
const __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(/\.map$/, '')));
30+
} catch (e) {
31+
return [];
32+
}
33+
};
1434

1535
export 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(

packages/web-platform/web-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dist",
3939
"binary",
4040
"css",
41-
"!dist/**/*.js.map",
41+
"!dist/**/*.map",
4242
"*.d.ts",
4343
"*.js",
4444
"LICENSE.txt",

packages/web-platform/web-core/rsbuild.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export default defineConfig({
99
},
1010
},
1111
output: {
12+
sourceMap: {
13+
js: 'source-map',
14+
css: true,
15+
},
1216
distPath: {
1317
root: './dist/client_prod',
1418
},

0 commit comments

Comments
 (0)