screenright-client 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +10 -1
- package/package.json +1 -1
- package/src/index.ts +13 -1
package/dist/index.d.ts
CHANGED
@@ -7,5 +7,8 @@ export declare const finalize: () => Promise<void>;
|
|
7
7
|
* @param {string} key - Unique key. cannot contain slashes.
|
8
8
|
* @param {string} title - Page title.
|
9
9
|
* @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
|
10
|
+
* @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
|
10
11
|
*/
|
11
|
-
export declare const capture: (page: Page, key: string, title: string, parentKey?: string
|
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 || '';
|
@@ -61,8 +62,9 @@ export const finalize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
62
|
* @param {string} key - Unique key. cannot contain slashes.
|
62
63
|
* @param {string} title - Page title.
|
63
64
|
* @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
|
65
|
+
* @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
|
64
66
|
*/
|
65
|
-
export const capture = (page, key, title, parentKey) => __awaiter(void 0, void 0, void 0, function* () {
|
67
|
+
export const capture = (page, key, title, parentKey, options = { waitMilliseconds: 0 }) => __awaiter(void 0, void 0, void 0, function* () {
|
66
68
|
if (deploymentId === null) {
|
67
69
|
return;
|
68
70
|
}
|
@@ -70,6 +72,13 @@ export const capture = (page, key, title, parentKey) => __awaiter(void 0, void 0
|
|
70
72
|
errorOccurred('Capture argument[key] cannot contain slashes.');
|
71
73
|
return;
|
72
74
|
}
|
75
|
+
const { waitMilliseconds } = options;
|
76
|
+
if (waitMilliseconds) {
|
77
|
+
const nWaitMilliseconds = Number(waitMilliseconds);
|
78
|
+
if (0 < waitMilliseconds) {
|
79
|
+
yield setTimeout(waitMilliseconds);
|
80
|
+
}
|
81
|
+
}
|
73
82
|
const fileName = `${key}.jpg`;
|
74
83
|
try {
|
75
84
|
const buffer = yield page.screenshot({ fullPage: true, type: 'jpeg' });
|
package/package.json
CHANGED
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
|
@@ -77,12 +78,14 @@ export const finalize = async () => {
|
|
77
78
|
* @param {string} key - Unique key. cannot contain slashes.
|
78
79
|
* @param {string} title - Page title.
|
79
80
|
* @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
|
81
|
+
* @param {{ waitMilliseconds: number }} [options] - Wait milliseconds before capture.
|
80
82
|
*/
|
81
83
|
export const capture = async (
|
82
84
|
page: Page,
|
83
85
|
key: string,
|
84
86
|
title: string,
|
85
|
-
parentKey?: string
|
87
|
+
parentKey?: string,
|
88
|
+
options: { waitMilliseconds: number } = { waitMilliseconds: 0 },
|
86
89
|
) => {
|
87
90
|
if (deploymentId === null) {
|
88
91
|
return
|
@@ -93,6 +96,15 @@ export const capture = async (
|
|
93
96
|
return
|
94
97
|
}
|
95
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
|
+
|
96
108
|
const fileName = `${key}.jpg`
|
97
109
|
try {
|
98
110
|
const buffer = await page.screenshot({ fullPage: true, type: 'jpeg' })
|