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
1. You have collected browser coverage data of your CSS. There are several ways to do this:
23
-
24
-
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
25
-
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.
26
-
27
-
Either way you end up with one or more JSON files that contain coverage data.
28
-
29
-
```ts
30
-
// Read a single JSON or a folder full of JSON files with coverage data
1. You 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:
1.Node (using [linkedom](https://github.com/WebReflection/linkedom) in this example):
59
-
60
-
```ts
61
-
// $ npm install linkedom
62
-
import { DOMParser } from 'linkedom'
63
-
64
-
function parse_html(html: string) {
65
-
return new DOMParser().parseFromString(html, 'text/html')
66
-
}
67
-
```
22
+
You have collected browser coverage data of your CSS. There are several ways to do this:
23
+
24
+
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
25
+
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.
26
+
27
+
Either way you end up with one or more JSON files that contain coverage data.
28
+
29
+
```ts
30
+
// Read a single JSON or a folder full of JSON files with coverage data
@@ -73,3 +54,26 @@ import { calculate_coverage } from '@projectwallace/css-code-coverage'
73
54
74
55
let report =calculcate_coverage(coverage_data, parse_html)
75
56
```
57
+
58
+
See [src/index.ts](https://github.com/projectwallace/css-code-coverage/blob/main/src/index.ts) for the data that's returned.
59
+
60
+
### Optional: coverage from `<style>` blocks
61
+
62
+
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:
0 commit comments