-
Notifications
You must be signed in to change notification settings - Fork 2
/
fixtures.ts
51 lines (43 loc) · 1.56 KB
/
fixtures.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { test as testBase, Page } from '@playwright/test';
import MCR from 'monocart-coverage-reports';
import coverageOptions from './mcr.config';
// fixtures
const test = testBase.extend<{
autoTestFixture: string
}>({
autoTestFixture: [async ({ context }, use) => {
const isChromium = test.info().project.name === 'chromium';
const handlePageEvent = async (page: Page) => {
await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false,
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false,
}),
]);
};
// console.log('autoTestFixture setup...');
// coverage API is chromium only
if (isChromium) {
context.on('page', handlePageEvent);
}
await use('autoTestFixture');
// console.log('autoTestFixture teardown...');
if (isChromium) {
context.off('page', handlePageEvent);
const coverageList = await Promise.all(context.pages().map(async (page) => {
const jsCoverage = await page.coverage.stopJSCoverage();
const cssCoverage = await page.coverage.stopCSSCoverage();
return [...jsCoverage, ...cssCoverage];
}));
// console.log(coverageList.map((item) => item.url));
const mcr = MCR(coverageOptions);
await mcr.add(coverageList.flat());
}
}, {
scope: 'test',
auto: true
}]
});
export { test };