screenright-client 0.9.7 → 0.9.9
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.mjs +0 -69
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' })
|
package/dist/index.mjs
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
|
-
import * as fs from 'fs';
|
11
|
-
import fetch from 'node-fetch';
|
12
|
-
const tmpDir = 'screenright/tmp';
|
13
|
-
const result = { screenshotItemAttributes: [] };
|
14
|
-
let deploymentId = null;
|
15
|
-
export const initializeScreenwright = () => __awaiter(void 0, void 0, void 0, function* () {
|
16
|
-
const baseUrl = `${process.env.SCREENRIGHT_ENDPOINT}/client_api`;
|
17
|
-
const diagramId = process.env.SCREENRIGHT_DIAGRAM_ID;
|
18
|
-
const deploymentToken = process.env.SCREENRIGHT_DEVELOPMENT_TOKEN;
|
19
|
-
const response = yield fetch(`${baseUrl}/diagrams/${diagramId}/deployments`, {
|
20
|
-
method: 'POST',
|
21
|
-
body: JSON.stringify({ deployment_token: deploymentToken }),
|
22
|
-
headers: { 'Content-Type': 'application/json' }
|
23
|
-
});
|
24
|
-
const body = yield response.text();
|
25
|
-
const json = JSON.parse(body);
|
26
|
-
deploymentId = json.id;
|
27
|
-
process.on('exit', (exitCode) => __awaiter(void 0, void 0, void 0, function* () {
|
28
|
-
if (exitCode === 0) {
|
29
|
-
fs.writeFileSync(`${tmpDir}/result.json`, JSON.stringify({
|
30
|
-
screenshotItemAttributes: result.screenshotItemAttributes,
|
31
|
-
}));
|
32
|
-
yield fetch(`${baseUrl}/diagrams/${diagramId}/deployments/${deploymentId}/done_upload`, {
|
33
|
-
method: 'PUT',
|
34
|
-
body: JSON.stringify({ deployment_token: deploymentToken }),
|
35
|
-
headers: { 'Content-Type': 'application/json' }
|
36
|
-
});
|
37
|
-
}
|
38
|
-
}));
|
39
|
-
});
|
40
|
-
initializeScreenwright();
|
41
|
-
export const capture = (page, key, title, parentKey) => __awaiter(void 0, void 0, void 0, function* () {
|
42
|
-
if (deploymentId === null) {
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
46
|
-
const path = `${tmpDir}/${key}.png`;
|
47
|
-
yield page.screenshot({ path, fullPage: true });
|
48
|
-
const attribute = {
|
49
|
-
key,
|
50
|
-
title,
|
51
|
-
src: path,
|
52
|
-
childrens: [],
|
53
|
-
};
|
54
|
-
if (parentKey) {
|
55
|
-
const searchParent = (attributes) => {
|
56
|
-
for (let i = 0; i < attributes.length; i++) {
|
57
|
-
if (attributes[i].key === parentKey) {
|
58
|
-
attributes[i].childrens.push(attribute);
|
59
|
-
break;
|
60
|
-
}
|
61
|
-
searchParent(attributes[i].childrens);
|
62
|
-
}
|
63
|
-
};
|
64
|
-
searchParent(result.screenshotItemAttributes);
|
65
|
-
}
|
66
|
-
else {
|
67
|
-
result.screenshotItemAttributes.push(attribute);
|
68
|
-
}
|
69
|
-
});
|