Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jan 7, 2024
1 parent 39042ea commit 955c4e1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ module.exports = {
]
};
```
- It is recommended to use [automatic fixtures](https://playwright.dev/docs/test-fixtures#automatic-fixtures) to add coverage for each test:
- Using [automatic fixtures](https://playwright.dev/docs/test-fixtures#automatic-fixtures) to add coverage for each test:
```js
// fixtures.js for v8 coverage
import { test as testBase, expect } from '@playwright/test';
Expand Down Expand Up @@ -690,8 +690,8 @@ const test = testBase.extend({
});
export { test, expect };
```
- Take coverage on global teardown.
> It can be used to add the server side coverage report. For example, a Node.js web server start at the beginning of the test with the env `NODE_V8_COVERAGE=dir`, the V8 coverage data will be saved to `dir` with calling API `v8.takeCoverage()` manually or terminating server gracefully. On global teardown, reading all from `dir` and adding them to global coverage report. For Node.js, the coverage data requires appending source manually.
- Take server side coverage on global teardown
> For example, a Node.js web server start at the beginning of the test with the env `NODE_V8_COVERAGE=dir`, the V8 coverage data will be saved to `dir` with calling API `v8.takeCoverage()` manually or terminating server gracefully. On global teardown, reading all from `dir` and adding them to global coverage report. For Node.js, the V8 coverage data requires appending source manually.
```js
// global-teardown.js
import fs from 'fs';
Expand All @@ -710,10 +710,9 @@ export default async (config) => {
let coverageList = json.result;
coverageList = coverageList.filter((entry) => entry.url && entry.url.startsWith('file:'));

// appending source content
// appending source
coverageList.forEach((entry) => {
const filePath = fileURLToPath(entry.url);
entry.source = fs.readFileSync(filePath).toString('utf8');
entry.source = fs.readFileSync(fileURLToPath(entry.url)).toString('utf8');
});

// there is no test info on teardown, just mock one with required config
Expand Down

0 comments on commit 955c4e1

Please sign in to comment.