lighthouse-reporting 1.0.0 → 1.1.0

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/dist/index.cjs CHANGED
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const hooks = require("./hooks.cjs");
4
4
  const lighthouseReports = require("./lighthouseReports.cjs");
5
- const lighthouseTest = require("./lighthouseTest.cjs");
5
+ const playwrightLighthouseTest = require("./playwrightLighthouseTest.cjs");
6
+ const storybookPlaywright = require("./storybookPlaywright.cjs");
6
7
  require("os");
7
8
  require("path");
8
9
  require("fs-extra");
@@ -15,4 +16,5 @@ exports.lighthouseSetup = hooks.lighthouseSetup;
15
16
  exports.getScores = lighthouseReports.getScores;
16
17
  exports.writeCsvResult = lighthouseReports.writeCsvResult;
17
18
  exports.writeHtmlListEntryWithRetry = lighthouseReports.writeHtmlListEntryWithRetry;
18
- exports.lighthouseTest = lighthouseTest.lighthouseTest;
19
+ exports.playwrightLighthouseTest = playwrightLighthouseTest.playwrightLighthouseTest;
20
+ exports.storybookPlaywright = storybookPlaywright.storybookPlaywright;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from './hooks';
2
- export * from './lighthouseReports';
3
- export * from './lighthouseTest';
1
+ export * from './hooks.js';
2
+ export * from './lighthouseReports.js';
3
+ export * from './playwrightLighthouseTest.js';
4
+ export * from './storybookPlaywright.js';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { lighthousePlaywrightTeardown, lighthouseSetup } from "./hooks.js";
2
2
  import { getScores, writeCsvResult, writeHtmlListEntryWithRetry } from "./lighthouseReports.js";
3
- import { lighthouseTest } from "./lighthouseTest.js";
3
+ import { playwrightLighthouseTest } from "./playwrightLighthouseTest.js";
4
+ import { storybookPlaywright } from "./storybookPlaywright.js";
4
5
  import "os";
5
6
  import "path";
6
7
  import "fs-extra";
@@ -12,7 +13,8 @@ export {
12
13
  getScores,
13
14
  lighthousePlaywrightTeardown,
14
15
  lighthouseSetup,
15
- lighthouseTest,
16
+ playwrightLighthouseTest,
17
+ storybookPlaywright,
16
18
  writeCsvResult,
17
19
  writeHtmlListEntryWithRetry
18
20
  };
@@ -169,7 +169,7 @@
169
169
  }
170
170
  throw new Error("No available ports found");
171
171
  }
172
- const lighthouseTest = test.test.extend({
172
+ const playwrightLighthouseTest = test.test.extend({
173
173
  port: [
174
174
  // eslint-disable-next-line no-empty-pattern
175
175
  async ({}, use) => {
@@ -192,10 +192,30 @@
192
192
  { scope: "test" }
193
193
  ]
194
194
  });
195
+ const storybookPlaywright = {
196
+ getStories: (pathToStorybookIndexJson, storyFilterFn) => {
197
+ if (!fse.existsSync(pathToStorybookIndexJson)) {
198
+ console.log(pathToStorybookIndexJson, "doesn't exist.");
199
+ throw new Error("Please build storybook before running tests!");
200
+ }
201
+ const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
202
+ const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
203
+ return stories;
204
+ },
205
+ captureScreenshot: async (story, context) => {
206
+ const page = context.pages()[0];
207
+ await page.goto(`/iframe.html?id=${story.id}`);
208
+ await test.expect(page.locator(".sb-show-main")).toBeVisible();
209
+ await test.expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
210
+ await page.waitForLoadState("networkidle");
211
+ await test.expect(page).toHaveScreenshot(`${story.id}.png`);
212
+ }
213
+ };
195
214
  exports2.getScores = getScores;
196
215
  exports2.lighthousePlaywrightTeardown = lighthousePlaywrightTeardown;
197
216
  exports2.lighthouseSetup = lighthouseSetup;
198
- exports2.lighthouseTest = lighthouseTest;
217
+ exports2.playwrightLighthouseTest = playwrightLighthouseTest;
218
+ exports2.storybookPlaywright = storybookPlaywright;
199
219
  exports2.writeCsvResult = writeCsvResult;
200
220
  exports2.writeHtmlListEntryWithRetry = writeHtmlListEntryWithRetry;
201
221
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
@@ -5,7 +5,7 @@ const path = require("path");
5
5
  const getPort = require("get-port");
6
6
  const test = require("@playwright/test");
7
7
  const constants = require("./constants-667b8033.cjs");
8
- const lighthouseTest = test.test.extend({
8
+ const playwrightLighthouseTest = test.test.extend({
9
9
  port: [
10
10
  // eslint-disable-next-line no-empty-pattern
11
11
  async ({}, use) => {
@@ -28,4 +28,4 @@ const lighthouseTest = test.test.extend({
28
28
  { scope: "test" }
29
29
  ]
30
30
  });
31
- exports.lighthouseTest = lighthouseTest;
31
+ exports.playwrightLighthouseTest = playwrightLighthouseTest;
@@ -1,5 +1,5 @@
1
1
  import type { BrowserContext } from '@playwright/test';
2
- export declare const lighthouseTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
2
+ export declare const playwrightLighthouseTest: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
3
3
  context: BrowserContext;
4
4
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
5
5
  port: number;
@@ -3,7 +3,7 @@ import path from "path";
3
3
  import getPort from "get-port";
4
4
  import { test, chromium } from "@playwright/test";
5
5
  import { P as PW_TMP_DIR } from "./constants-226e9774.js";
6
- const lighthouseTest = test.extend({
6
+ const playwrightLighthouseTest = test.extend({
7
7
  port: [
8
8
  // eslint-disable-next-line no-empty-pattern
9
9
  async ({}, use) => {
@@ -27,5 +27,5 @@ const lighthouseTest = test.extend({
27
27
  ]
28
28
  });
29
29
  export {
30
- lighthouseTest
30
+ playwrightLighthouseTest
31
31
  };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ 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 stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
13
+ return stories;
14
+ },
15
+ captureScreenshot: async (story, context) => {
16
+ const page = context.pages()[0];
17
+ await page.goto(`/iframe.html?id=${story.id}`);
18
+ await test.expect(page.locator(".sb-show-main")).toBeVisible();
19
+ await test.expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
20
+ await page.waitForLoadState("networkidle");
21
+ await test.expect(page).toHaveScreenshot(`${story.id}.png`);
22
+ }
23
+ };
24
+ exports.storybookPlaywright = storybookPlaywright;
@@ -0,0 +1,15 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ export interface StorybookIndexStory {
3
+ id: string;
4
+ title: string;
5
+ name: string;
6
+ importPath: string;
7
+ tags: Array<string>;
8
+ type: 'story' | 'docs';
9
+ }
10
+ type StoriesFilterFn = (story: StorybookIndexStory) => boolean;
11
+ export declare const storybookPlaywright: {
12
+ getStories: (pathToStorybookIndexJson: string, storyFilterFn: StoriesFilterFn) => StorybookIndexStory[];
13
+ captureScreenshot: (story: StorybookIndexStory, context: BrowserContext) => Promise<void>;
14
+ };
15
+ export {};
@@ -0,0 +1,24 @@
1
+ import fse from "fs-extra";
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 stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
11
+ return stories;
12
+ },
13
+ captureScreenshot: async (story, context) => {
14
+ const page = context.pages()[0];
15
+ await page.goto(`/iframe.html?id=${story.id}`);
16
+ await expect(page.locator(".sb-show-main")).toBeVisible();
17
+ await expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
18
+ await page.waitForLoadState("networkidle");
19
+ await expect(page).toHaveScreenshot(`${story.id}.png`);
20
+ }
21
+ };
22
+ export {
23
+ storybookPlaywright
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse-reporting",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build && vite build -c vite.umd.config.ts && tsc -p ./tsconfig.build.json",
@@ -22,8 +22,9 @@
22
22
  "default": "./dist/index.cjs"
23
23
  }
24
24
  },
25
- "peerDependencies": {
26
- "@playwright/test": "1"
25
+ "optionalDependencies": {
26
+ "@playwright/test": "^1",
27
+ "get-port": "^6"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@playwright/test": "^1.34.2",
@@ -43,8 +44,7 @@
43
44
  "vite-plugin-static-copy": "^0.15.0"
44
45
  },
45
46
  "dependencies": {
46
- "fs-extra": "^11.1.1",
47
- "get-port": "^6.1.2"
47
+ "fs-extra": "^11.1.1"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",