Skip to content

Commit 69aab2f

Browse files
committed
Update reporter readme
1 parent 3caf24c commit 69aab2f

File tree

2 files changed

+79
-12
lines changed

2 files changed

+79
-12
lines changed

packages/reporter/README.md

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
> [!WARNING]
44
> This package is still in the experimental phase. You can expect new functionalities, but with this comes the possibility of more frequent errors
55
6-
Directory summary (light theme) | File coverage (dark theme)
7-
:----------------------------------------------------------------------------------------------:|:----------------------------:
8-
![Summary](https://github.com/akcyp/coverage-pretty-html-reporter/raw/main/images/summary.png) | ![Coverage](https://github.com/akcyp/coverage-pretty-html-reporter/raw/main/images/file.png)
6+
Home | Stats | Code
7+
:----:|:---:|:---:
8+
![Summary](../../images/home-dark.png) | ![Stats](../../images/stats-dark.png) | ![Coverage](../../images/code-dark.png)
9+
![Summary](../../images/home-light.png) | ![Stats](../../images/stats-light.png) | ![Coverage](../../images/code-light.png)
910

1011
## Installation
1112

@@ -45,15 +46,81 @@ export default defineConfig({
4546
});
4647
```
4748

48-
## Reading coverage report
49+
## Iframe - theme support
4950

50-
`coverage-pretty-html-reporter` does not support viewing web-page locally (via file:// protocol) (i.e. double clicking the .html file). You need to publish coverage directory on local network ex.:
51+
When the reporter UI is embedded in an iframe, the built-in theme toggle button is hidden. In this mode you are expected to control the theme from the parent window.
52+
53+
The iframe listens for postMessage events with the following payload:
54+
55+
```ts
56+
type CoverageThemeMessage = {
57+
type: "coverage-theme";
58+
theme: "light" | "dark";
59+
};
60+
```
61+
62+
Example integration in the parent page:
63+
64+
```html
65+
<iframe
66+
id="coverage-report"
67+
src="/path/to/coverage/index.html"
68+
style="width: 100%; height: 100%; border: 0;"
69+
></iframe>
70+
71+
<script>
72+
const iframe = document.getElementById("coverage-report");
73+
74+
function setCoverageTheme(theme) {
75+
iframe?.contentWindow?.postMessage({ type: "coverage-theme", theme }, "*");
76+
}
77+
78+
// Send initial theme once the iframe is loaded
79+
iframe.addEventListener("load", () => {
80+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
81+
setCoverageTheme(prefersDark ? "dark" : "light");
82+
});
83+
84+
// Example: hook into your own app theme system
85+
window.addEventListener("app-theme-changed", (event) => {
86+
setCoverageTheme(event.detail.theme); // "light" | "dark"
87+
});
88+
<\/script>
89+
```
90+
91+
Inside the iframe, the selected theme is persisted in localStorage under the coverage-theme key and a coverage-theme-changed CustomEvent is dispatched on window so internal components can react to theme changes.
92+
93+
```
94+
95+
## Contributing
96+
97+
Fell free to report any bugs & share your ideas. PRs are welcome.
98+
99+
## Developer guide
100+
101+
Requirements (see package.json#packageManager):
102+
- bun@1.0.4
103+
- node@^18.17.1
51104
52105
```sh
53-
# When using npm
54-
npx http-server ./coverage
55-
# When using pnpm
56-
pnpm dlx http-server ./coverage
57-
# When using bun
58-
bunx http-server ./coverage
106+
git clone git@github.com:akcyp/coverage-pretty-html-reporter.git
107+
cd coverage-pretty-html-reporter
108+
109+
# Init
110+
bun i
111+
bun run build
112+
113+
# Production testing
114+
bun run demo:nyc # or demo:c8
115+
bun run demo:preview
116+
117+
# UI development
118+
cd packages/reporter
119+
bun run dev
120+
121+
# Reporter development - only production testing
122+
# edit packages/reporter/node/index.ts
123+
cd packages/example
124+
bun run test:c8
125+
bun run test:nyc
59126
```

packages/reporter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coverage-pretty-html-reporter",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"files": [
55
"dist"
66
],

0 commit comments

Comments
 (0)