You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-25Lines changed: 23 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,31 +45,7 @@ In Edge, Chrome or chromium you can manually collect coverage in the browser's D
45
45
46
46
Additionally, DevTools Tips writes about it in their [explainer](https://devtoolstips.org/tips/en/detect-unused-code/).
47
47
48
-
### Coverage API
49
-
50
-
Both Puppeteer and Playwright provide an API to programmatically get the coverage data, allowing you to put that directly into this library. Here is the gist:
51
-
52
-
```ts
53
-
// Start collecting coverage
54
-
awaitpage.coverage.startCSSCoverage()
55
-
// Load the page, do all sorts of interactions to increase coverage, etc.
56
-
awaitpage.goto('http://example.com')
57
-
// Stop the coverage and store the result in a variable to pass along
58
-
let coverage =awaitpage.coverage.stopCSSCoverage()
let report =calculcate_coverage(coverage, parse_html)
68
-
```
69
-
70
-
1. Via the `coverage.startCSSCoverage()` API that headless browsers like [Playwright](https://playwright.dev/docs/api/class-coverage#coverage-start-css-coverage) or [Puppeteer](https://pptr.dev/api/puppeteer.coverage.startcsscoverage/) provide.
71
-
72
-
Either way you end up with one or more JSON files that contain coverage data.
48
+
You end up with one or more JSON files that contain coverage data. We provide a helper `parse_coverage()` that both parses the JSON and validates it so you can pass it directly into `calculate_coverage()`.
73
49
74
50
```ts
75
51
// Read a single JSON or a folder full of JSON files with coverage data
@@ -92,6 +68,28 @@ for (let file of files) {
92
68
}
93
69
```
94
70
71
+
### Coverage API
72
+
73
+
Both Puppeteer and Playwright provide an API to programmatically get the coverage data, allowing you to put that directly into this library. Here is the gist:
74
+
75
+
```ts
76
+
// Start collecting coverage
77
+
awaitpage.coverage.startCSSCoverage()
78
+
// Load the page, do all sorts of interactions to increase coverage, etc.
79
+
awaitpage.goto('http://example.com')
80
+
// Stop the coverage and store the result in a variable to pass along
81
+
let coverage =awaitpage.coverage.stopCSSCoverage()
let report =calculcate_coverage(coverage, parse_html)
91
+
```
92
+
95
93
### Optional: coverage from `<style>` blocks
96
94
97
95
Coverage generators also create coverage ranges for `<style>` blocks in HTML. If this applies to your code you should provide a HTML parser that we use to 'scrape' the HTML in case the browser gives us not just plain CSS contents. Depending on where you run this analysis you can use:
0 commit comments