Skip to content

Commit

Permalink
Correctly remove page event listener on teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-kochetygov authored Sep 4, 2024
1 parent 98c68d1 commit b57a9c3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test as testBase } from '@playwright/test';
import { test as testBase, Page } from '@playwright/test';
import MCR from 'monocart-coverage-reports';
import coverageOptions from './mcr.config';

Expand All @@ -10,25 +10,28 @@ const test = testBase.extend<{

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', async (page) => {
await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false
})
]);
});
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();
Expand Down

0 comments on commit b57a9c3

Please sign in to comment.