|
3 | 3 | > [!WARNING] |
4 | 4 | > This package is still in the experimental phase. You can expect new functionalities, but with this comes the possibility of more frequent errors |
5 | 5 |
|
6 | | -Directory summary (light theme) | File coverage (dark theme) |
7 | | -:----------------------------------------------------------------------------------------------:|:----------------------------: |
8 | | - |  |
| 6 | +Home | Stats | Code |
| 7 | +:----:|:---:|:---: |
| 8 | + |  |  |
| 9 | + |  |  |
9 | 10 |
|
10 | 11 | ## Installation |
11 | 12 |
|
@@ -45,15 +46,81 @@ export default defineConfig({ |
45 | 46 | }); |
46 | 47 | ``` |
47 | 48 |
|
48 | | -## Reading coverage report |
| 49 | +## Iframe - theme support |
49 | 50 |
|
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 |
51 | 104 |
|
52 | 105 | ```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 |
59 | 126 | ``` |
0 commit comments