lighthouse-reporting 1.1.0 → 1.3.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.
@@ -202,13 +202,16 @@
202
202
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
203
203
  return stories;
204
204
  },
205
- captureScreenshot: async (story, context) => {
205
+ captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
206
206
  const page = context.pages()[0];
207
207
  await page.goto(`/iframe.html?id=${story.id}`);
208
208
  await test.expect(page.locator(".sb-show-main")).toBeVisible();
209
209
  await test.expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
210
210
  await page.waitForLoadState("networkidle");
211
- await test.expect(page).toHaveScreenshot(`${story.id}.png`);
211
+ if (actionBeforeScreenshot) {
212
+ await actionBeforeScreenshot(page);
213
+ }
214
+ await test.expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
212
215
  }
213
216
  };
214
217
  exports2.getScores = getScores;
@@ -1,4 +1,4 @@
1
- import type { BrowserContext } from '@playwright/test';
1
+ import { BrowserContext } from '@playwright/test';
2
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 & {
@@ -12,13 +12,16 @@ const storybookPlaywright = {
12
12
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
13
13
  return stories;
14
14
  },
15
- captureScreenshot: async (story, context) => {
15
+ captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
16
16
  const page = context.pages()[0];
17
17
  await page.goto(`/iframe.html?id=${story.id}`);
18
18
  await test.expect(page.locator(".sb-show-main")).toBeVisible();
19
19
  await test.expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
20
20
  await page.waitForLoadState("networkidle");
21
- await test.expect(page).toHaveScreenshot(`${story.id}.png`);
21
+ if (actionBeforeScreenshot) {
22
+ await actionBeforeScreenshot(page);
23
+ }
24
+ await test.expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
22
25
  }
23
26
  };
24
27
  exports.storybookPlaywright = storybookPlaywright;
@@ -1,4 +1,4 @@
1
- import type { BrowserContext } from '@playwright/test';
1
+ import { BrowserContext, Locator, Page } from '@playwright/test';
2
2
  export interface StorybookIndexStory {
3
3
  id: string;
4
4
  title: string;
@@ -10,6 +10,85 @@ export interface StorybookIndexStory {
10
10
  type StoriesFilterFn = (story: StorybookIndexStory) => boolean;
11
11
  export declare const storybookPlaywright: {
12
12
  getStories: (pathToStorybookIndexJson: string, storyFilterFn: StoriesFilterFn) => StorybookIndexStory[];
13
- captureScreenshot: (story: StorybookIndexStory, context: BrowserContext) => Promise<void>;
13
+ captureScreenshot: (story: StorybookIndexStory, context: BrowserContext, screenshotOptions?: {
14
+ /**
15
+ * When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different
16
+ * treatment depending on their duration:
17
+ * - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.
18
+ * - infinite animations are canceled to initial state, and then played over after the screenshot.
19
+ *
20
+ * Defaults to `"disabled"` that disables animations.
21
+ */
22
+ animations?: 'disabled' | 'allow';
23
+ /**
24
+ * When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be
25
+ * changed. Defaults to `"hide"`.
26
+ */
27
+ caret?: 'hide' | 'initial';
28
+ /**
29
+ * An object which specifies clipping of the resulting image.
30
+ */
31
+ clip?: {
32
+ /**
33
+ * x-coordinate of top-left corner of clip area
34
+ */
35
+ x: number;
36
+ /**
37
+ * y-coordinate of top-left corner of clip area
38
+ */
39
+ y: number;
40
+ /**
41
+ * width of clipping area
42
+ */
43
+ width: number;
44
+ /**
45
+ * height of clipping area
46
+ */
47
+ height: number;
48
+ };
49
+ /**
50
+ * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
51
+ * `false`.
52
+ */
53
+ fullPage?: boolean;
54
+ /**
55
+ * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
56
+ * box `#FF00FF` that completely covers its bounding box.
57
+ */
58
+ mask?: Array<Locator>;
59
+ /**
60
+ * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is
61
+ * configurable with `TestConfig.expect`. Unset by default.
62
+ */
63
+ maxDiffPixelRatio?: number;
64
+ /**
65
+ * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by
66
+ * default.
67
+ */
68
+ maxDiffPixels?: number;
69
+ /**
70
+ * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.
71
+ * Defaults to `false`.
72
+ */
73
+ omitBackground?: boolean;
74
+ /**
75
+ * When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this
76
+ * will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so
77
+ * screenshots of high-dpi devices will be twice as large or even larger.
78
+ *
79
+ * Defaults to `"css"`.
80
+ */
81
+ scale?: 'css' | 'device';
82
+ /**
83
+ * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the
84
+ * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
85
+ * `TestConfig.expect`. Defaults to `0.2`.
86
+ */
87
+ threshold?: number;
88
+ /**
89
+ * Time to retry the assertion for. Defaults to `timeout` in `TestConfig.expect`.
90
+ */
91
+ timeout?: number;
92
+ }, actionBeforeScreenshot?: ((page: Page) => Promise<void>) | undefined) => Promise<void>;
14
93
  };
15
94
  export {};
@@ -10,13 +10,16 @@ const storybookPlaywright = {
10
10
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
11
11
  return stories;
12
12
  },
13
- captureScreenshot: async (story, context) => {
13
+ captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
14
14
  const page = context.pages()[0];
15
15
  await page.goto(`/iframe.html?id=${story.id}`);
16
16
  await expect(page.locator(".sb-show-main")).toBeVisible();
17
17
  await expect(page.locator(".sb-show-errordisplay")).not.toBeVisible();
18
18
  await page.waitForLoadState("networkidle");
19
- await expect(page).toHaveScreenshot(`${story.id}.png`);
19
+ if (actionBeforeScreenshot) {
20
+ await actionBeforeScreenshot(page);
21
+ }
22
+ await expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
20
23
  }
21
24
  };
22
25
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse-reporting",
3
- "version": "1.1.0",
3
+ "version": "1.3.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",
@@ -27,14 +27,15 @@
27
27
  "get-port": "^6"
28
28
  },
29
29
  "devDependencies": {
30
- "@playwright/test": "^1.34.2",
30
+ "@playwright/test": "^1.34.3",
31
31
  "@types/fs-extra": "^11.0.1",
32
- "@types/node": "^20.2.3",
32
+ "@types/node": "^20.2.4",
33
33
  "@typescript-eslint/eslint-plugin": "^5.59.7",
34
34
  "@typescript-eslint/parser": "^5.59.7",
35
35
  "eslint": "^8.41.0",
36
36
  "eslint-config-prettier": "^8.8.0",
37
37
  "eslint-plugin-prettier": "^4.2.1",
38
+ "get-port": "^6.1.2",
38
39
  "husky": "^8.0.3",
39
40
  "npm-run-all": "^4.1.5",
40
41
  "prettier": "^2.8.8",