-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add playwright code coverage (#2014)
* test: Add playwright test coverage support * chore: remove extraneous comment * fix: test-e2e.yml PR comment depends on context.issue.number * fix: .nycrc json syntax * fix: remove coverage comment; output report in action * chore: ensure test:build always re-builds * chore: ensure playwright coverage saves to correct folder * fix: ensure test:build is ran before test:e2e * fix: remove needs: build from test:e2e * fix: put istandbul output back into .nyc_output * chore: add codecov action * fix: run nyc report prior to codecov action
- Loading branch information
Showing
17 changed files
with
146 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,7 @@ tsconfig.tsbuildinfo | |
.tool-versions | ||
.envrc | ||
.cid | ||
.cache | ||
.nyc_output | ||
|
||
tx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
{ | ||
"include": ["src/**/*.js"], | ||
"exclude": ["**/*.test.js", "**/*.stories.js"], | ||
"reporter": ["html", "text", "lcov"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @see https://github.com/mxschmitt/playwright-test-coverage | ||
* @see https://github.com/mxschmitt/playwright-test-coverage/blob/main/e2e/baseFixtures.ts | ||
*/ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import * as crypto from 'crypto' | ||
import { test as baseTest } from '@playwright/test' | ||
|
||
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output') | ||
|
||
export function generateUUID () { | ||
return crypto.randomBytes(16).toString('hex') | ||
} | ||
|
||
export const test = baseTest.extend({ | ||
context: async ({ context }, use) => { | ||
await context.addInitScript(() => | ||
window.addEventListener('beforeunload', () => | ||
window.collectIstanbulCoverage(JSON.stringify(window.__coverage__)) | ||
) | ||
) | ||
await fs.promises.mkdir(istanbulCLIOutput, { recursive: true }) | ||
await context.exposeFunction('collectIstanbulCoverage', async (coverageJSON) => { | ||
if (coverageJSON) { | ||
try { | ||
await fs.promises.writeFile(path.join(istanbulCLIOutput, `playwright_coverage_${generateUUID()}.json`), coverageJSON) | ||
} catch (err) { | ||
console.error('Error writing playwright coverage file', err) | ||
} | ||
} else { | ||
throw new Error('No coverage data') | ||
} | ||
}) | ||
await use(context) | ||
for (const page of context.pages()) { | ||
await page.evaluate(() => window.collectIstanbulCoverage(JSON.stringify(window.__coverage__))) | ||
} | ||
} | ||
}) | ||
|
||
export const expect = test.expect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters