@alexgorbatchev/storybook-test-runner-bun 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/coverageSourcePath.ts +20 -0
- package/src/writeCoverage.ts +7 -0
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ Existing stories and browser-side `storybook/test` imports stay as they are. Cha
|
|
|
118
118
|
|
|
119
119
|
# Browser Coverage
|
|
120
120
|
|
|
121
|
-
The runner starts Playwright's native JavaScript coverage before navigating to the Storybook preview. Chromium tracks execution without instrumenting your application. Monocart merges the results, maps bundled code back to original sources, and generates reports. Enable source maps in your Storybook build (for Bun builds, use `sourcemap: "inline"`) and make external source maps accessible to the runner if used.
|
|
121
|
+
The runner starts Playwright's native JavaScript coverage before navigating to the Storybook preview. Chromium tracks execution without instrumenting your application. Relative source-map filenames resolve against their served module, preserving directories in Vite development coverage. Monocart merges the results, maps bundled code back to original sources, and generates reports. Enable source maps in your Storybook build (for Bun builds, use `sourcemap: "inline"`) and make external source maps accessible to the runner if used.
|
|
122
122
|
|
|
123
123
|
```ts
|
|
124
124
|
const results = await runStories({
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
|
|
3
|
+
export function coverageSourcePath(
|
|
4
|
+
path: string,
|
|
5
|
+
info: { url?: unknown; distFile?: string },
|
|
6
|
+
): string {
|
|
7
|
+
if (typeof info.url !== "string") return path;
|
|
8
|
+
if (/^https?:/.test(info.url)) {
|
|
9
|
+
const pathname = decodeURIComponent(new URL(info.url).pathname);
|
|
10
|
+
return pathname.startsWith("/@fs/")
|
|
11
|
+
? relative(process.cwd(), pathname.slice(5))
|
|
12
|
+
: pathname.slice(1);
|
|
13
|
+
}
|
|
14
|
+
if (!info.distFile || /^(?:[a-z][\w+.-]*:|\/)/i.test(info.url)) return path;
|
|
15
|
+
// Dev servers often map a module to just its filename. Resolve it against
|
|
16
|
+
// the served module, rather than collapsing files from different folders.
|
|
17
|
+
return decodeURIComponent(new URL(info.url, `http://storybook/${info.distFile}`).pathname).slice(
|
|
18
|
+
1,
|
|
19
|
+
);
|
|
20
|
+
}
|
package/src/writeCoverage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CoverageReport } from "monocart-coverage-reports";
|
|
2
2
|
import type { BrowserCoverage } from "./types";
|
|
3
|
+
import { coverageSourcePath } from "./coverageSourcePath";
|
|
3
4
|
|
|
4
5
|
export async function writeCoverage(
|
|
5
6
|
data: BrowserCoverage,
|
|
@@ -7,10 +8,16 @@ export async function writeCoverage(
|
|
|
7
8
|
filter?: string,
|
|
8
9
|
): Promise<void> {
|
|
9
10
|
if (!data.length) throw new Error("No browser coverage was collected");
|
|
11
|
+
const glob = filter ? new Bun.Glob(filter) : undefined;
|
|
10
12
|
const report = new CoverageReport({
|
|
11
13
|
outputDir: directory,
|
|
12
14
|
reports: ["v8", "json", "lcovonly"],
|
|
13
15
|
sourceFilter: filter,
|
|
16
|
+
sourcePath: coverageSourcePath,
|
|
17
|
+
entryFilter: (entry) =>
|
|
18
|
+
!glob ||
|
|
19
|
+
glob.match(coverageSourcePath(entry.url, entry)) ||
|
|
20
|
+
Boolean(entry.source?.includes("sourceMappingURL=")),
|
|
14
21
|
inline: true,
|
|
15
22
|
logging: "off",
|
|
16
23
|
cleanCache: true,
|