screenright-client 0.9.6 → 0.9.8

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.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  import { Page } from '@playwright/test';
2
2
  export declare const initializeScreenwright: () => Promise<void>;
3
3
  export declare const finalize: () => Promise<void>;
4
- export declare const capture: (page: Page, key: string, title: string, parentKey?: string) => Promise<void>;
4
+ /**
5
+ * Get screen capture.
6
+ * @param {Page} page - Playwright's page object.
7
+ * @param {string} key - Unique key. cannot contain slashes.
8
+ * @param {string} title - Page title.
9
+ * @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
10
+ * @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
11
+ */
12
+ export declare const capture: (page: Page, key: string, title: string, parentKey?: string, options?: {
13
+ waitMilliseconds: number;
14
+ }) => Promise<void>;
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import fetch from 'node-fetch';
11
11
  import process from 'node:process';
12
12
  import FormData from 'form-data';
13
+ import { setTimeout } from 'timers/promises';
13
14
  const result = { screenshotItemAttributes: [] };
14
15
  let deploymentId = null;
15
16
  const deploymentToken = process.env.SCREENRIGHT_DEPLOYMENT_TOKEN || '';
@@ -55,10 +56,29 @@ export const finalize = () => __awaiter(void 0, void 0, void 0, function* () {
55
56
  });
56
57
  deploymentId = null;
57
58
  });
58
- export const capture = (page, key, title, parentKey) => __awaiter(void 0, void 0, void 0, function* () {
59
+ /**
60
+ * Get screen capture.
61
+ * @param {Page} page - Playwright's page object.
62
+ * @param {string} key - Unique key. cannot contain slashes.
63
+ * @param {string} title - Page title.
64
+ * @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
65
+ * @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
66
+ */
67
+ export const capture = (page, key, title, parentKey, options = { waitMilliseconds: 0 }) => __awaiter(void 0, void 0, void 0, function* () {
59
68
  if (deploymentId === null) {
60
69
  return;
61
70
  }
71
+ if (0 <= key.indexOf('/')) {
72
+ errorOccurred('Capture argument[key] cannot contain slashes.');
73
+ return;
74
+ }
75
+ const { waitMilliseconds } = options;
76
+ if (waitMilliseconds) {
77
+ const nWaitMilliseconds = Number(waitMilliseconds);
78
+ if (0 < waitMilliseconds) {
79
+ yield setTimeout(waitMilliseconds);
80
+ }
81
+ }
62
82
  const fileName = `${key}.jpg`;
63
83
  try {
64
84
  const buffer = yield page.screenshot({ fullPage: true, type: 'jpeg' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenright-client",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "screenright's nodejs client library",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import { Page } from '@playwright/test'
3
3
  import fetch from 'node-fetch'
4
4
  import process from 'node:process'
5
5
  import FormData from 'form-data'
6
+ import { setTimeout } from 'timers/promises'
6
7
 
7
8
  type ScreenshotItemAttribute = {
8
9
  key: string
@@ -71,16 +72,39 @@ export const finalize = async () => {
71
72
  deploymentId = null
72
73
  }
73
74
 
75
+ /**
76
+ * Get screen capture.
77
+ * @param {Page} page - Playwright's page object.
78
+ * @param {string} key - Unique key. cannot contain slashes.
79
+ * @param {string} title - Page title.
80
+ * @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
81
+ * @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
82
+ */
74
83
  export const capture = async (
75
84
  page: Page,
76
85
  key: string,
77
86
  title: string,
78
- parentKey?: string
87
+ parentKey?: string,
88
+ options: { waitMilliseconds: number } = { waitMilliseconds: 0 },
79
89
  ) => {
80
90
  if (deploymentId === null) {
81
91
  return
82
92
  }
83
93
 
94
+ if (0 <= key.indexOf('/')) {
95
+ errorOccurred('Capture argument[key] cannot contain slashes.')
96
+ return
97
+ }
98
+
99
+ const { waitMilliseconds } = options
100
+
101
+ if (waitMilliseconds) {
102
+ const nWaitMilliseconds = Number(waitMilliseconds)
103
+ if (0 < waitMilliseconds) {
104
+ await setTimeout(waitMilliseconds)
105
+ }
106
+ }
107
+
84
108
  const fileName = `${key}.jpg`
85
109
  try {
86
110
  const buffer = await page.screenshot({ fullPage: true, type: 'jpeg' })