lighthouse-reporting 1.2.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,12 +202,15 @@
202
202
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
203
203
  return stories;
204
204
  },
205
- captureScreenshot: async (story, context, screenshotOptions) => {
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
+ if (actionBeforeScreenshot) {
212
+ await actionBeforeScreenshot(page);
213
+ }
211
214
  await test.expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
212
215
  }
213
216
  };
@@ -12,12 +12,15 @@ const storybookPlaywright = {
12
12
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
13
13
  return stories;
14
14
  },
15
- captureScreenshot: async (story, context, screenshotOptions) => {
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
+ if (actionBeforeScreenshot) {
22
+ await actionBeforeScreenshot(page);
23
+ }
21
24
  await test.expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
22
25
  }
23
26
  };
@@ -1,4 +1,4 @@
1
- import { 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;
@@ -46,6 +46,49 @@ export declare const storybookPlaywright: {
46
46
  */
47
47
  height: number;
48
48
  };
49
- }) => Promise<void>;
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>;
50
93
  };
51
94
  export {};
@@ -10,12 +10,15 @@ const storybookPlaywright = {
10
10
  const stories = Object.values(storybookIndexJson.entries).filter(storyFilterFn);
11
11
  return stories;
12
12
  },
13
- captureScreenshot: async (story, context, screenshotOptions) => {
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
+ if (actionBeforeScreenshot) {
20
+ await actionBeforeScreenshot(page);
21
+ }
19
22
  await expect(page).toHaveScreenshot(`${story.id}.png`, screenshotOptions);
20
23
  }
21
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse-reporting",
3
- "version": "1.2.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",
@@ -29,7 +29,7 @@
29
29
  "devDependencies": {
30
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",