Skip to content

Commit

Permalink
Move coverage code to playwright-test-coverage-native
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jan 22, 2024
1 parent 079b609 commit 9128a70
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/react-dom": "^18.2.18",
"@vitest/coverage-v8": "^1.2.1",
"c8": "^9.1.0",
"playwright-test-coverage-native": "^0.1.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.3",
"use-immer": "^0.9.0",
Expand Down
8 changes: 6 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, devices } from "@playwright/test";
import { defineConfig, devices } from "playwright-test-coverage-native";

/**
* See https://playwright.dev/docs/test-configuration.
Expand Down Expand Up @@ -31,7 +31,11 @@ export default defineConfig({
// NOTE: our goal here isn't to extensively test Niivue, all we need is a working WebGL2!
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
use: {
...devices["Desktop Chrome"],
coverageDir: './coverage-playwright/tmp',
coverageSrc: './src'
},
},
],

Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 1 addition & 23 deletions tests/playwright/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test as base, expect } from "@playwright/test";
import { test as base, expect } from "playwright-test-coverage-native";
import { NVImage } from "@niivue/niivue";
import { NVRVolume } from "../../src";
import * as fsPromises from "node:fs/promises";
import * as path from "node:path";

type NiivueCanvasTest = {
getVolume: (name: string) => Promise<NVImage>;
Expand All @@ -14,26 +12,6 @@ type MyFixtures = {
};

export const test = base.extend<MyFixtures>({
page: async ({ page }, use, testInfo) => {
// Use Playwright's built-in v8 coverage, write to a file
// https://github.com/microsoft/playwright/issues/9208#issuecomment-1147884893
await page.coverage.startJSCoverage();
await use(page);

const coverage = await page.coverage.stopJSCoverage();
const srcPath = "@fs" + path.normalize(`${__dirname}/../../src`);
const srcCoverage = coverage
.filter((entry) => entry.url.includes(srcPath))
.map((entry) => {
return { ...entry, url: entry.url.replace(/^.+@fs/, "file://") };
});
await fsPromises.mkdir("coverage-playwright/tmp", { recursive: true });
const testTitle = testInfo.title.replaceAll("/", "_");
await fsPromises.writeFile(
`coverage-playwright/tmp/${testTitle}.json`,
JSON.stringify({ result: srcCoverage }, null, 2),
);
},
nvt: async ({ page }, use) => {
const setVolumes = async (volumes: NVRVolume[]) => {
await page.getByTestId("volumes-string").fill(JSON.stringify(volumes));
Expand Down

0 comments on commit 9128a70

Please sign in to comment.