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
let report =calculcate_coverage(coverage_data, parse_html)
31
+
```
32
+
33
+
See [src/index.ts](https://github.com/projectwallace/css-code-coverage/blob/main/src/index.ts) for the data that's returned.
34
+
35
+
## Collecting CSS Coverage
36
+
37
+
There are two principal ways of collecting CSS Coverage data:
38
+
39
+
### Browser devtools
40
+
41
+
In Edge, Chrome or chromium you can manually collect coverage in the browser's DevTools. In all cases you'll generate coverage data manually and the browser will let you export the data to a JSON file. Note that this JSON contains both JS coverage as well as the CSS coverage. Learn how it works:
42
+
43
+
- Collect coverage in Microsoft Edge: https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/coverage/
44
+
- Collect coevrage in Google Chrome: https://developer.chrome.com/docs/devtools/coverage/
45
+
46
+
Additionally, DevTools Tips writes about it in their [explainer](https://devtoolstips.org/tips/en/detect-unused-code/).
47
+
48
+
### Coverage API
24
49
25
-
You have collected browser coverage data of your CSS. There are several ways to do this:
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
+
```
26
69
27
-
1. in the browser devtools in [Edge](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/coverage/)/[Chrome](https://developer.chrome.com/docs/devtools/coverage/)/chromium
28
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.
29
71
30
72
Either way you end up with one or more JSON files that contain coverage data.
let report =calculcate_coverage(coverage_data, parse_html)
59
-
```
60
-
61
-
See [src/index.ts](https://github.com/projectwallace/css-code-coverage/blob/main/src/index.ts) for the data that's returned.
62
-
63
95
### Optional: coverage from `<style>` blocks
64
96
65
-
Covergae 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:
97
+
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