Skip to content

Commit

Permalink
fix: playwright coverage report showing incorrect results
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
mas-who authored and edlerd committed Feb 26, 2024
1 parent 0468db1 commit 95a38d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const config: PlaywrightTestConfig<TestOptions> = {
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 3,
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? "blob" : "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const finishCoverage = async (
if (entry.url.includes("spice")) {
continue;
}
if (entry.url.includes("node_modules")) {
continue;
}
const fileMatcher = entry.url.match(/http(s)*:\/\/.*:8407\/(?<file>.*)/);
if (!fileMatcher?.groups) {
continue;
Expand Down
19 changes: 10 additions & 9 deletions tests/fixtures/lxd-test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { test as base } from "@playwright/test";
import { Page, test as base } from "@playwright/test";
import { finishCoverage, startCoverage } from "./coverage";

export type LxdVersions = "5.0-stable" | "latest-edge";
export type TestOptions = {
lxdVersion: LxdVersions;
hasCoverage: boolean;
runCoverage: Page;
};

export const test = base.extend<TestOptions>({
lxdVersion: ["latest-edge", { option: true }],
hasCoverage: [false, { option: true }],
});

test.beforeEach(async ({ page, hasCoverage }) => {
await startCoverage(page, hasCoverage);
});

test.afterEach(async ({ page, hasCoverage }) => {
await finishCoverage(page, hasCoverage);
runCoverage: [
async ({ page, hasCoverage }, use) => {
await startCoverage(page, hasCoverage);
await use(page);
await finishCoverage(page, hasCoverage);
},
{ auto: true },
],
});

export const expect = test.expect;

0 comments on commit 95a38d3

Please sign in to comment.