lighthouse-reporting 1.6.8 → 1.6.9

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.
@@ -1,93 +1,91 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("path");
4
- const fse = require("fs-extra");
5
- const writeCsvResult = async (reportDir, name, scores, thresholds = {}, swimlanes = []) => {
6
- let csvData = Object.keys(scores).join(",");
7
- if (swimlanes.length > 0) {
8
- csvData += "," + swimlanes.map((swimlane) => `${swimlane}_threshold`);
9
- }
10
- csvData += "\n";
11
- csvData += Object.values(scores).join(",");
12
- if (swimlanes.length > 0 && Object.keys(thresholds).length > 0) {
13
- csvData += "," + swimlanes.map((swimlane) => thresholds[swimlane]);
14
- }
15
- await fse.writeFile(path.join(reportDir, `${name}.csv`), csvData);
2
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
3
+ let path = require("path");
4
+ path = require_rolldown_runtime.__toESM(path, 1);
5
+ let fs_extra = require("fs-extra");
6
+ fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
7
+ //#region src/lighthouseReports.ts
8
+ var writeCsvResult = async (reportDir, name, scores, thresholds = {}, swimlanes = []) => {
9
+ let csvData = Object.keys(scores).join(",");
10
+ if (swimlanes.length > 0) csvData += "," + swimlanes.map((swimlane) => `${swimlane}_threshold`);
11
+ csvData += "\n";
12
+ csvData += Object.values(scores).join(",");
13
+ if (swimlanes.length > 0 && Object.keys(thresholds).length > 0) csvData += "," + swimlanes.map((swimlane) => thresholds[swimlane]);
14
+ await fs_extra.default.writeFile(path.default.join(reportDir, `${name}.csv`), csvData);
16
15
  };
17
- const writeHtmlListEntry = async (htmlFilePath, name, scores, thresholds, error, addReportLink) => {
18
- const htmlFileData = (await fse.readFile(htmlFilePath)).toString("utf-8").split("\n");
19
- const insertIdx = htmlFileData.findIndex((v) => v.includes("// lighthouse-page-results"));
20
- if (insertIdx < 0) {
21
- throw new Error("Failed to write results to index.html");
22
- }
23
- htmlFileData.splice(insertIdx + 1, 0, JSON.stringify({ href: `${name}.html`, name, scores, thresholds, error, addReportLink }) + ",");
24
- await fse.writeFile(htmlFilePath, htmlFileData.join("\n"));
16
+ var writeHtmlListEntry = async (htmlFilePath, name, scores, thresholds, error, addReportLink) => {
17
+ const htmlFileData = (await fs_extra.default.readFile(htmlFilePath)).toString("utf-8").split("\n");
18
+ const insertIdx = htmlFileData.findIndex((v) => v.includes("// lighthouse-page-results"));
19
+ if (insertIdx < 0) throw new Error("Failed to write results to index.html");
20
+ htmlFileData.splice(insertIdx + 1, 0, JSON.stringify({
21
+ href: `${name}.html`,
22
+ name,
23
+ scores,
24
+ thresholds,
25
+ error,
26
+ addReportLink
27
+ }) + ",");
28
+ await fs_extra.default.writeFile(htmlFilePath, htmlFileData.join("\n"));
25
29
  };
26
- const writeHtmlListEntryWithRetry = async (htmlFilePath, name, scores, thresholds, comparisonError, addReportLink = true) => {
27
- let attempts = 10;
28
- let error;
29
- while (attempts > 0) {
30
- attempts--;
31
- try {
32
- await writeHtmlListEntry(htmlFilePath, name, scores, thresholds, comparisonError, addReportLink);
33
- return;
34
- } catch (e) {
35
- error = e;
36
- }
37
- await new Promise((resolve) => setTimeout(resolve, 10));
38
- }
39
- throw error;
30
+ /**
31
+ * workaround conflicts when multiple threads write the same file
32
+ */
33
+ var writeHtmlListEntryWithRetry = async (htmlFilePath, name, scores, thresholds, comparisonError, addReportLink = true) => {
34
+ let attempts = 10;
35
+ let error;
36
+ while (attempts > 0) {
37
+ attempts--;
38
+ try {
39
+ await writeHtmlListEntry(htmlFilePath, name, scores, thresholds, comparisonError, addReportLink);
40
+ return;
41
+ } catch (e) {
42
+ error = e;
43
+ }
44
+ await new Promise((resolve) => setTimeout(resolve, 10));
45
+ }
46
+ throw error;
40
47
  };
41
- const getScores = (result) => Object.entries(result.lhr.categories).reduce(
42
- (prev, [key, c]) => {
43
- const score = typeof c.score === "number" ? c.score : 0;
44
- prev[key] = Math.floor(score * 100);
45
- return prev;
46
- },
47
- {}
48
- );
49
- const writeScoresToJson = async (lhScoresDir, name, scores, result) => {
50
- const json = Object.entries(scores).reduce(
51
- (prev, [k, score]) => {
52
- prev[k] = { score };
53
- return prev;
54
- },
55
- {}
56
- );
57
- const accessibilityViolations = result.artifacts.Accessibility ? result.artifacts.Accessibility.violations.map((v) => {
58
- return {
59
- title: result.lhr.audits[v.id].title,
60
- nodes: v.nodes.length
61
- };
62
- }) : [];
63
- if (accessibilityViolations.length > 0) {
64
- json.accessibility.issues = accessibilityViolations;
65
- }
66
- await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
48
+ var getScores = (result) => Object.entries(result.lhr.categories).reduce((prev, [key, c]) => {
49
+ const score = typeof c.score === "number" ? c.score : 0;
50
+ prev[key] = Math.floor(score * 100);
51
+ return prev;
52
+ }, {});
53
+ var writeScoresToJson = async (lhScoresDir, name, scores, result) => {
54
+ const json = Object.entries(scores).reduce((prev, [k, score]) => {
55
+ prev[k] = { score };
56
+ return prev;
57
+ }, {});
58
+ const accessibilityViolations = result.artifacts.Accessibility ? result.artifacts.Accessibility.violations.map((v) => {
59
+ return {
60
+ title: result.lhr.audits[v.id].title,
61
+ nodes: v.nodes.length
62
+ };
63
+ }) : [];
64
+ if (accessibilityViolations.length > 0) json.accessibility.issues = accessibilityViolations;
65
+ await fs_extra.default.writeFile(path.default.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
67
66
  };
68
- const buildAverageCsv = async (lhScoresDir, reportDir) => {
69
- const files = await fse.readdir(lhScoresDir);
70
- const jsonFiles = files.filter((f) => f.endsWith(".json"));
71
- if (jsonFiles.length === 0) {
72
- return;
73
- }
74
- const scores = {};
75
- for (const fileName of jsonFiles) {
76
- const score = await fse.readJson(
77
- path.join(lhScoresDir, fileName)
78
- );
79
- Object.entries(score).forEach(([k, v]) => {
80
- if (!scores[k]) {
81
- scores[k] = 0;
82
- }
83
- scores[k] += v.score;
84
- });
85
- }
86
- Object.entries(scores).forEach(([k, v]) => {
87
- scores[k] = v / jsonFiles.length;
88
- });
89
- await writeCsvResult(reportDir, "_AVERAGE_", scores);
67
+ /**
68
+ * Generate average csv file. Make sure to use `writeScoresToJson` in your test!
69
+ * @param lhScoresDir path to folder with lighthouse json files. See `writeScoresToJson`.
70
+ * @param reportDir folder where `_AVERAGE_.json` will be generated
71
+ */
72
+ var buildAverageCsv = async (lhScoresDir, reportDir) => {
73
+ const jsonFiles = (await fs_extra.default.readdir(lhScoresDir)).filter((f) => f.endsWith(".json"));
74
+ if (jsonFiles.length === 0) return;
75
+ const scores = {};
76
+ for (const fileName of jsonFiles) {
77
+ const score = await fs_extra.default.readJson(path.default.join(lhScoresDir, fileName));
78
+ Object.entries(score).forEach(([k, v]) => {
79
+ if (!scores[k]) scores[k] = 0;
80
+ scores[k] += v.score;
81
+ });
82
+ }
83
+ Object.entries(scores).forEach(([k, v]) => {
84
+ scores[k] = v / jsonFiles.length;
85
+ });
86
+ await writeCsvResult(reportDir, "_AVERAGE_", scores);
90
87
  };
88
+ //#endregion
91
89
  exports.buildAverageCsv = buildAverageCsv;
92
90
  exports.getScores = getScores;
93
91
  exports.writeCsvResult = writeCsvResult;
@@ -1,95 +1,85 @@
1
1
  import path from "path";
2
2
  import fse from "fs-extra";
3
- const writeCsvResult = async (reportDir, name, scores, thresholds = {}, swimlanes = []) => {
4
- let csvData = Object.keys(scores).join(",");
5
- if (swimlanes.length > 0) {
6
- csvData += "," + swimlanes.map((swimlane) => `${swimlane}_threshold`);
7
- }
8
- csvData += "\n";
9
- csvData += Object.values(scores).join(",");
10
- if (swimlanes.length > 0 && Object.keys(thresholds).length > 0) {
11
- csvData += "," + swimlanes.map((swimlane) => thresholds[swimlane]);
12
- }
13
- await fse.writeFile(path.join(reportDir, `${name}.csv`), csvData);
3
+ //#region src/lighthouseReports.ts
4
+ var writeCsvResult = async (reportDir, name, scores, thresholds = {}, swimlanes = []) => {
5
+ let csvData = Object.keys(scores).join(",");
6
+ if (swimlanes.length > 0) csvData += "," + swimlanes.map((swimlane) => `${swimlane}_threshold`);
7
+ csvData += "\n";
8
+ csvData += Object.values(scores).join(",");
9
+ if (swimlanes.length > 0 && Object.keys(thresholds).length > 0) csvData += "," + swimlanes.map((swimlane) => thresholds[swimlane]);
10
+ await fse.writeFile(path.join(reportDir, `${name}.csv`), csvData);
14
11
  };
15
- const writeHtmlListEntry = async (htmlFilePath, name, scores, thresholds, error, addReportLink) => {
16
- const htmlFileData = (await fse.readFile(htmlFilePath)).toString("utf-8").split("\n");
17
- const insertIdx = htmlFileData.findIndex((v) => v.includes("// lighthouse-page-results"));
18
- if (insertIdx < 0) {
19
- throw new Error("Failed to write results to index.html");
20
- }
21
- htmlFileData.splice(insertIdx + 1, 0, JSON.stringify({ href: `${name}.html`, name, scores, thresholds, error, addReportLink }) + ",");
22
- await fse.writeFile(htmlFilePath, htmlFileData.join("\n"));
12
+ var writeHtmlListEntry = async (htmlFilePath, name, scores, thresholds, error, addReportLink) => {
13
+ const htmlFileData = (await fse.readFile(htmlFilePath)).toString("utf-8").split("\n");
14
+ const insertIdx = htmlFileData.findIndex((v) => v.includes("// lighthouse-page-results"));
15
+ if (insertIdx < 0) throw new Error("Failed to write results to index.html");
16
+ htmlFileData.splice(insertIdx + 1, 0, JSON.stringify({
17
+ href: `${name}.html`,
18
+ name,
19
+ scores,
20
+ thresholds,
21
+ error,
22
+ addReportLink
23
+ }) + ",");
24
+ await fse.writeFile(htmlFilePath, htmlFileData.join("\n"));
23
25
  };
24
- const writeHtmlListEntryWithRetry = async (htmlFilePath, name, scores, thresholds, comparisonError, addReportLink = true) => {
25
- let attempts = 10;
26
- let error;
27
- while (attempts > 0) {
28
- attempts--;
29
- try {
30
- await writeHtmlListEntry(htmlFilePath, name, scores, thresholds, comparisonError, addReportLink);
31
- return;
32
- } catch (e) {
33
- error = e;
34
- }
35
- await new Promise((resolve) => setTimeout(resolve, 10));
36
- }
37
- throw error;
26
+ /**
27
+ * workaround conflicts when multiple threads write the same file
28
+ */
29
+ var writeHtmlListEntryWithRetry = async (htmlFilePath, name, scores, thresholds, comparisonError, addReportLink = true) => {
30
+ let attempts = 10;
31
+ let error;
32
+ while (attempts > 0) {
33
+ attempts--;
34
+ try {
35
+ await writeHtmlListEntry(htmlFilePath, name, scores, thresholds, comparisonError, addReportLink);
36
+ return;
37
+ } catch (e) {
38
+ error = e;
39
+ }
40
+ await new Promise((resolve) => setTimeout(resolve, 10));
41
+ }
42
+ throw error;
38
43
  };
39
- const getScores = (result) => Object.entries(result.lhr.categories).reduce(
40
- (prev, [key, c]) => {
41
- const score = typeof c.score === "number" ? c.score : 0;
42
- prev[key] = Math.floor(score * 100);
43
- return prev;
44
- },
45
- {}
46
- );
47
- const writeScoresToJson = async (lhScoresDir, name, scores, result) => {
48
- const json = Object.entries(scores).reduce(
49
- (prev, [k, score]) => {
50
- prev[k] = { score };
51
- return prev;
52
- },
53
- {}
54
- );
55
- const accessibilityViolations = result.artifacts.Accessibility ? result.artifacts.Accessibility.violations.map((v) => {
56
- return {
57
- title: result.lhr.audits[v.id].title,
58
- nodes: v.nodes.length
59
- };
60
- }) : [];
61
- if (accessibilityViolations.length > 0) {
62
- json.accessibility.issues = accessibilityViolations;
63
- }
64
- await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
44
+ var getScores = (result) => Object.entries(result.lhr.categories).reduce((prev, [key, c]) => {
45
+ const score = typeof c.score === "number" ? c.score : 0;
46
+ prev[key] = Math.floor(score * 100);
47
+ return prev;
48
+ }, {});
49
+ var writeScoresToJson = async (lhScoresDir, name, scores, result) => {
50
+ const json = Object.entries(scores).reduce((prev, [k, score]) => {
51
+ prev[k] = { score };
52
+ return prev;
53
+ }, {});
54
+ const accessibilityViolations = result.artifacts.Accessibility ? result.artifacts.Accessibility.violations.map((v) => {
55
+ return {
56
+ title: result.lhr.audits[v.id].title,
57
+ nodes: v.nodes.length
58
+ };
59
+ }) : [];
60
+ if (accessibilityViolations.length > 0) json.accessibility.issues = accessibilityViolations;
61
+ await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
65
62
  };
66
- const buildAverageCsv = async (lhScoresDir, reportDir) => {
67
- const files = await fse.readdir(lhScoresDir);
68
- const jsonFiles = files.filter((f) => f.endsWith(".json"));
69
- if (jsonFiles.length === 0) {
70
- return;
71
- }
72
- const scores = {};
73
- for (const fileName of jsonFiles) {
74
- const score = await fse.readJson(
75
- path.join(lhScoresDir, fileName)
76
- );
77
- Object.entries(score).forEach(([k, v]) => {
78
- if (!scores[k]) {
79
- scores[k] = 0;
80
- }
81
- scores[k] += v.score;
82
- });
83
- }
84
- Object.entries(scores).forEach(([k, v]) => {
85
- scores[k] = v / jsonFiles.length;
86
- });
87
- await writeCsvResult(reportDir, "_AVERAGE_", scores);
88
- };
89
- export {
90
- buildAverageCsv,
91
- getScores,
92
- writeCsvResult,
93
- writeHtmlListEntryWithRetry,
94
- writeScoresToJson
63
+ /**
64
+ * Generate average csv file. Make sure to use `writeScoresToJson` in your test!
65
+ * @param lhScoresDir path to folder with lighthouse json files. See `writeScoresToJson`.
66
+ * @param reportDir folder where `_AVERAGE_.json` will be generated
67
+ */
68
+ var buildAverageCsv = async (lhScoresDir, reportDir) => {
69
+ const jsonFiles = (await fse.readdir(lhScoresDir)).filter((f) => f.endsWith(".json"));
70
+ if (jsonFiles.length === 0) return;
71
+ const scores = {};
72
+ for (const fileName of jsonFiles) {
73
+ const score = await fse.readJson(path.join(lhScoresDir, fileName));
74
+ Object.entries(score).forEach(([k, v]) => {
75
+ if (!scores[k]) scores[k] = 0;
76
+ scores[k] += v.score;
77
+ });
78
+ }
79
+ Object.entries(scores).forEach(([k, v]) => {
80
+ scores[k] = v / jsonFiles.length;
81
+ });
82
+ await writeCsvResult(reportDir, "_AVERAGE_", scores);
95
83
  };
84
+ //#endregion
85
+ export { buildAverageCsv, getScores, writeCsvResult, writeHtmlListEntryWithRetry, writeScoresToJson };
@@ -1,31 +1,23 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const os = require("os");
4
- const path = require("path");
5
- const getPort = require("get-port");
6
- const test = require("@playwright/test");
7
- const constants = require("./constants-ClvZzVIQ.cjs");
8
- const playwrightLighthouseTest = test.test.extend({
9
- port: [
10
- // eslint-disable-next-line no-empty-pattern
11
- async ({}, use) => {
12
- const port = await getPort();
13
- await use(port);
14
- },
15
- { scope: "worker" }
16
- ],
17
- context: [
18
- async ({ port, launchOptions }, use) => {
19
- const context = await test.chromium.launchPersistentContext(
20
- path.join(os.tmpdir(), constants.PW_TMP_DIR, `${Math.random()}`.replace(".", "")),
21
- {
22
- args: [...launchOptions.args || [], `--remote-debugging-port=${port}`]
23
- }
24
- );
25
- await use(context);
26
- await context.close();
27
- },
28
- { scope: "test" }
29
- ]
2
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
3
+ const require_constants = require("./constants-WB1XbOZm.cjs");
4
+ let os = require("os");
5
+ os = require_rolldown_runtime.__toESM(os, 1);
6
+ let path = require("path");
7
+ path = require_rolldown_runtime.__toESM(path, 1);
8
+ let get_port = require("get-port");
9
+ get_port = require_rolldown_runtime.__toESM(get_port, 1);
10
+ let _playwright_test = require("@playwright/test");
11
+ //#region src/playwrightLighthouseTest.ts
12
+ var playwrightLighthouseTest = _playwright_test.test.extend({
13
+ port: [async ({}, use) => {
14
+ await use(await (0, get_port.default)());
15
+ }, { scope: "worker" }],
16
+ context: [async ({ port, launchOptions }, use) => {
17
+ const context = await _playwright_test.chromium.launchPersistentContext(path.default.join(os.default.tmpdir(), require_constants.PW_TMP_DIR, `${Math.random()}`.replace(".", "")), { args: [...launchOptions.args || [], `--remote-debugging-port=${port}`] });
18
+ await use(context);
19
+ await context.close();
20
+ }, { scope: "test" }]
30
21
  });
22
+ //#endregion
31
23
  exports.playwrightLighthouseTest = playwrightLighthouseTest;
@@ -1,31 +1,18 @@
1
+ import { r as PW_TMP_DIR } from "./constants-CFLum58k.js";
1
2
  import os from "os";
2
3
  import path from "path";
3
4
  import getPort from "get-port";
4
- import { test, chromium } from "@playwright/test";
5
- import { P as PW_TMP_DIR } from "./constants-CvRW9vHz.js";
6
- const playwrightLighthouseTest = test.extend({
7
- port: [
8
- // eslint-disable-next-line no-empty-pattern
9
- async ({}, use) => {
10
- const port = await getPort();
11
- await use(port);
12
- },
13
- { scope: "worker" }
14
- ],
15
- context: [
16
- async ({ port, launchOptions }, use) => {
17
- const context = await chromium.launchPersistentContext(
18
- path.join(os.tmpdir(), PW_TMP_DIR, `${Math.random()}`.replace(".", "")),
19
- {
20
- args: [...launchOptions.args || [], `--remote-debugging-port=${port}`]
21
- }
22
- );
23
- await use(context);
24
- await context.close();
25
- },
26
- { scope: "test" }
27
- ]
5
+ import { chromium, test } from "@playwright/test";
6
+ //#region src/playwrightLighthouseTest.ts
7
+ var playwrightLighthouseTest = test.extend({
8
+ port: [async ({}, use) => {
9
+ await use(await getPort());
10
+ }, { scope: "worker" }],
11
+ context: [async ({ port, launchOptions }, use) => {
12
+ const context = await chromium.launchPersistentContext(path.join(os.tmpdir(), PW_TMP_DIR, `${Math.random()}`.replace(".", "")), { args: [...launchOptions.args || [], `--remote-debugging-port=${port}`] });
13
+ await use(context);
14
+ await context.close();
15
+ }, { scope: "test" }]
28
16
  });
29
- export {
30
- playwrightLighthouseTest
31
- };
17
+ //#endregion
18
+ export { playwrightLighthouseTest };
@@ -0,0 +1,28 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ Object.defineProperty(exports, "__toESM", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return __toESM;
27
+ }
28
+ });
@@ -1,33 +1,30 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fse = require("fs-extra");
4
- const test = require("@playwright/test");
5
- const storybookPlaywright = {
6
- getStories: (pathToStorybookIndexJson, storyFilterFn) => {
7
- if (!fse.existsSync(pathToStorybookIndexJson)) {
8
- console.log(pathToStorybookIndexJson, "doesn't exist.");
9
- throw new Error("Please build storybook before running tests!");
10
- }
11
- const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
12
- const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
13
- const stories = Object.values(storyObject).filter(storyFilterFn);
14
- return stories;
15
- },
16
- captureScreenshot: async (story, context, screenshotOptions, options = {
17
- waitForLoadStateTimeout: 2e3
18
- }, actionBeforeScreenshot) => {
19
- const page = context.pages()[0];
20
- await page.goto(`/iframe.html?id=${story.id}`);
21
- await test.expect(page.locator(".sb-show-main")).toBeVisible();
22
- await test.expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
23
- try {
24
- await page.waitForLoadState("networkidle", { timeout: options.waitForLoadStateTimeout });
25
- } catch {
26
- }
27
- if (actionBeforeScreenshot) {
28
- await actionBeforeScreenshot(page);
29
- }
30
- await test.expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
31
- }
2
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
3
+ let fs_extra = require("fs-extra");
4
+ fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
5
+ let _playwright_test = require("@playwright/test");
6
+ //#region src/storybookPlaywright.ts
7
+ var storybookPlaywright = {
8
+ getStories: (pathToStorybookIndexJson, storyFilterFn) => {
9
+ if (!fs_extra.default.existsSync(pathToStorybookIndexJson)) {
10
+ console.log(pathToStorybookIndexJson, "doesn't exist.");
11
+ throw new Error("Please build storybook before running tests!");
12
+ }
13
+ const storybookIndexJson = fs_extra.default.readJsonSync(pathToStorybookIndexJson);
14
+ const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
15
+ return Object.values(storyObject).filter(storyFilterFn);
16
+ },
17
+ captureScreenshot: async (story, context, screenshotOptions, options = { waitForLoadStateTimeout: 2e3 }, actionBeforeScreenshot) => {
18
+ const page = context.pages()[0];
19
+ await page.goto(`/iframe.html?id=${story.id}`);
20
+ await (0, _playwright_test.expect)(page.locator(".sb-show-main")).toBeVisible();
21
+ await (0, _playwright_test.expect)(page.locator(".sb-show-errordisplay")).not.toBeVisible();
22
+ try {
23
+ await page.waitForLoadState("networkidle", { timeout: options.waitForLoadStateTimeout });
24
+ } catch {}
25
+ if (actionBeforeScreenshot) await actionBeforeScreenshot(page);
26
+ await (0, _playwright_test.expect)(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
27
+ }
32
28
  };
29
+ //#endregion
33
30
  exports.storybookPlaywright = storybookPlaywright;
@@ -1,33 +1,27 @@
1
1
  import fse from "fs-extra";
2
2
  import { expect } from "@playwright/test";
3
- const storybookPlaywright = {
4
- getStories: (pathToStorybookIndexJson, storyFilterFn) => {
5
- if (!fse.existsSync(pathToStorybookIndexJson)) {
6
- console.log(pathToStorybookIndexJson, "doesn't exist.");
7
- throw new Error("Please build storybook before running tests!");
8
- }
9
- const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
10
- const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
11
- const stories = Object.values(storyObject).filter(storyFilterFn);
12
- return stories;
13
- },
14
- captureScreenshot: async (story, context, screenshotOptions, options = {
15
- waitForLoadStateTimeout: 2e3
16
- }, actionBeforeScreenshot) => {
17
- const page = context.pages()[0];
18
- await page.goto(`/iframe.html?id=${story.id}`);
19
- await expect(page.locator(".sb-show-main")).toBeVisible();
20
- await expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
21
- try {
22
- await page.waitForLoadState("networkidle", { timeout: options.waitForLoadStateTimeout });
23
- } catch {
24
- }
25
- if (actionBeforeScreenshot) {
26
- await actionBeforeScreenshot(page);
27
- }
28
- await expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
29
- }
30
- };
31
- export {
32
- storybookPlaywright
3
+ //#region src/storybookPlaywright.ts
4
+ var storybookPlaywright = {
5
+ getStories: (pathToStorybookIndexJson, storyFilterFn) => {
6
+ if (!fse.existsSync(pathToStorybookIndexJson)) {
7
+ console.log(pathToStorybookIndexJson, "doesn't exist.");
8
+ throw new Error("Please build storybook before running tests!");
9
+ }
10
+ const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
11
+ const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
12
+ return Object.values(storyObject).filter(storyFilterFn);
13
+ },
14
+ captureScreenshot: async (story, context, screenshotOptions, options = { waitForLoadStateTimeout: 2e3 }, actionBeforeScreenshot) => {
15
+ const page = context.pages()[0];
16
+ await page.goto(`/iframe.html?id=${story.id}`);
17
+ await expect(page.locator(".sb-show-main")).toBeVisible();
18
+ await expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
19
+ try {
20
+ await page.waitForLoadState("networkidle", { timeout: options.waitForLoadStateTimeout });
21
+ } catch {}
22
+ if (actionBeforeScreenshot) await actionBeforeScreenshot(page);
23
+ await expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
24
+ }
33
25
  };
26
+ //#endregion
27
+ export { storybookPlaywright };