@empiricalrun/playwright-utils 0.8.3 → 0.8.5
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/CHANGELOG.md +17 -0
- package/dist/captcha.js +6 -6
- package/dist/reporter/base.d.ts +2 -0
- package/dist/reporter/base.d.ts.map +1 -1
- package/dist/reporter/base.js +2 -0
- package/dist/reporter/custom.d.ts +2 -0
- package/dist/reporter/custom.d.ts.map +1 -1
- package/dist/reporter/custom.js +7 -5
- package/dist/reporter/reporterV2.d.ts +3 -2
- package/dist/reporter/reporterV2.d.ts.map +1 -1
- package/dist/reporter/reporterV2.js +2 -81
- package/dist/reporter/util.d.ts +2 -0
- package/dist/reporter/util.d.ts.map +1 -1
- package/dist/reporter/util.js +2 -0
- package/dist/{reporter/types/htmlReporter.d.ts → third_party/html-reporter-types.d.ts} +6 -5
- package/dist/third_party/html-reporter-types.d.ts.map +1 -0
- package/dist/{reporter/types/htmlReporter.js → third_party/html-reporter-types.js} +1 -0
- package/package.json +3 -2
- package/dist/reporter/types/htmlReporter.d.ts.map +0 -1
- package/dist/reporter/upload.d.ts +0 -11
- package/dist/reporter/upload.d.ts.map +0 -1
- package/dist/reporter/upload.js +0 -135
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @empiricalrun/playwright-utils
|
|
2
2
|
|
|
3
|
+
## 0.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9a8ed62: feat: add third party license and documentation for the code adapted from playwright repo
|
|
8
|
+
- 6a1288a: feat: create r2 uploader package and support for retry
|
|
9
|
+
- Updated dependencies [6a1288a]
|
|
10
|
+
- @empiricalrun/r2-uploader@0.1.0
|
|
11
|
+
|
|
12
|
+
## 0.8.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- a851891: feat: remove need to crop image with sharp lib
|
|
17
|
+
- Updated dependencies [a851891]
|
|
18
|
+
- @empiricalrun/llm@0.8.3
|
|
19
|
+
|
|
3
20
|
## 0.8.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/captcha.js
CHANGED
|
@@ -40,15 +40,15 @@ async function clickImageTile(frame, nth) {
|
|
|
40
40
|
await image.dispatchEvent("click");
|
|
41
41
|
}
|
|
42
42
|
async function handleCaptcha(cf) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const screenshot = await cf.frame
|
|
44
|
+
.locator(".rc-imageselect-challenge")
|
|
45
|
+
.screenshot();
|
|
46
|
+
const gridBoxesToSelect = await (0, vision_1.solveRecaptchaGrid)({
|
|
46
47
|
captchaType: cf.type,
|
|
47
|
-
pageScreenshotBase64: screenshot.toString("base64"),
|
|
48
|
-
captchaBoundingBox: (await gridLocator.boundingBox()),
|
|
49
48
|
captchaObject: (await getObjectiveCaptcha(cf)),
|
|
49
|
+
screenshotBase64: screenshot.toString("base64"),
|
|
50
50
|
});
|
|
51
|
-
for (const n of
|
|
51
|
+
for (const n of gridBoxesToSelect) {
|
|
52
52
|
await clickImageTile(cf.frame, n - 1);
|
|
53
53
|
}
|
|
54
54
|
const verifyButton = cf.frame.getByRole("button", { name: "Verify" });
|
package/dist/reporter/base.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/base.ts
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
3
5
|
*
|
|
4
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/reporter/base.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"base.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/reporter/base.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/base.ts
|
|
3
4
|
* Copyright (c) Microsoft Corporation.
|
|
5
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
4
6
|
*
|
|
5
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
8
|
* you may not use this file except in compliance with the License.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/html.ts
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
3
5
|
*
|
|
4
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/reporter/custom.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/reporter/custom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EAEV,KAAK,EACL,QAAQ,IAAI,cAAc,EAC1B,SAAS,EACT,UAAU,IAAI,gBAAgB,EAE/B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAML,UAAU,EAMX,MAAM,2BAA2B,CAAC;AA2BnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAsB/C,QAAA,MAAM,iBAAiB,UAAoC,CAAC;AAC5D,KAAK,oBAAoB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAM/D,KAA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,KAAK,EAAE,SAAS,GAAG,IAAI;IAIzB,KAAK,CAAC,MAAM,EAAE,UAAU;IAkFxB,MAAM;CA8Bb;AAkCD,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,IAAI,GAAE,MAAoB,EAC1B,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM,iBAqBhB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAsBhE;AAqiBD,eAAe,YAAY,CAAC"}
|
package/dist/reporter/custom.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/html.ts
|
|
3
4
|
* Copyright (c) Microsoft Corporation.
|
|
5
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
4
6
|
*
|
|
5
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
8
|
* you may not use this file except in compliance with the License.
|
|
@@ -20,6 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
23
|
exports.startHtmlReportServer = exports.showHTMLReport = void 0;
|
|
22
24
|
const code_frame_1 = require("@babel/code-frame");
|
|
25
|
+
const r2_uploader_1 = require("@empiricalrun/r2-uploader");
|
|
23
26
|
const fs_1 = __importDefault(require("fs"));
|
|
24
27
|
const path_1 = __importDefault(require("path"));
|
|
25
28
|
const utils_1 = require("playwright-core/lib/utils");
|
|
@@ -29,7 +32,6 @@ const utilsBundle_1 = require("playwright-core/lib/utilsBundle");
|
|
|
29
32
|
const zipBundle_1 = require("playwright-core/lib/zipBundle");
|
|
30
33
|
const stream_1 = require("stream");
|
|
31
34
|
const base_1 = require("./base");
|
|
32
|
-
const upload_1 = require("./upload");
|
|
33
35
|
const util_1 = require("./util");
|
|
34
36
|
const htmlReportOptions = ["always", "never", "on-failure"];
|
|
35
37
|
const isHtmlReportOption = (type) => {
|
|
@@ -73,7 +75,7 @@ class HtmlReporter {
|
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
77
|
try {
|
|
76
|
-
await (0,
|
|
78
|
+
await (0, r2_uploader_1.uploadDirectory)({
|
|
77
79
|
sourceDir: this._outputFolder + "/data/" + folderName,
|
|
78
80
|
destinationDir: process.env.PROJECT_NAME +
|
|
79
81
|
"/" +
|
|
@@ -144,7 +146,7 @@ class HtmlReporter {
|
|
|
144
146
|
}).format(startTime));
|
|
145
147
|
try {
|
|
146
148
|
await Promise.allSettled([
|
|
147
|
-
(0,
|
|
149
|
+
(0, r2_uploader_1.uploadDirectory)({
|
|
148
150
|
sourceDir: this._outputFolder + "/trace",
|
|
149
151
|
destinationDir: process.env.PROJECT_NAME +
|
|
150
152
|
"/" +
|
|
@@ -153,7 +155,7 @@ class HtmlReporter {
|
|
|
153
155
|
uploadBucket: "test-report",
|
|
154
156
|
}),
|
|
155
157
|
// upload index.html
|
|
156
|
-
(0,
|
|
158
|
+
(0, r2_uploader_1.uploadDirectory)({
|
|
157
159
|
sourceDir: this._outputFolder,
|
|
158
160
|
fileList: [path_1.default.join(this._outputFolder, "index.html")],
|
|
159
161
|
destinationDir: process.env.PROJECT_NAME +
|
|
@@ -162,7 +164,7 @@ class HtmlReporter {
|
|
|
162
164
|
uploadBucket: "test-report",
|
|
163
165
|
}),
|
|
164
166
|
// upload summary.json
|
|
165
|
-
(0,
|
|
167
|
+
(0, r2_uploader_1.uploadDirectory)({
|
|
166
168
|
sourceDir: this._outputFolder,
|
|
167
169
|
fileList: [path_1.default.join(this._outputFolder, "summary.json")],
|
|
168
170
|
destinationDir: process.env.PROJECT_NAME +
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/reporterV2.ts
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
3
5
|
*
|
|
4
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
* limitations under the License.
|
|
15
17
|
*/
|
|
16
18
|
/// <reference types="node" />
|
|
17
|
-
import type { FullConfig, FullResult,
|
|
19
|
+
import type { FullConfig, FullResult, Suite, TestCase, TestError, TestResult, TestStep } from "@playwright/test/reporter";
|
|
18
20
|
export interface ReporterV2 {
|
|
19
21
|
onConfigure(config: FullConfig): void;
|
|
20
22
|
onBegin(suite: Suite): void;
|
|
@@ -32,5 +34,4 @@ export interface ReporterV2 {
|
|
|
32
34
|
printsToStdio(): boolean;
|
|
33
35
|
version(): "v2";
|
|
34
36
|
}
|
|
35
|
-
export declare function wrapReporterAsV2(reporter: Reporter | ReporterV2): ReporterV2;
|
|
36
37
|
//# sourceMappingURL=reporterV2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporterV2.d.ts","sourceRoot":"","sources":["../../src/reporter/reporterV2.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"reporterV2.d.ts","sourceRoot":"","sources":["../../src/reporter/reporterV2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;;AAEH,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,UAAU;IACzB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7E,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACpD,KAAK,CACH,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;KAAE,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACxE,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtE,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACpE,aAAa,IAAI,OAAO,CAAC;IACzB,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/reporters/reporterV2.ts
|
|
3
4
|
* Copyright (c) Microsoft Corporation.
|
|
5
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
4
6
|
*
|
|
5
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
8
|
* you may not use this file except in compliance with the License.
|
|
@@ -15,84 +17,3 @@
|
|
|
15
17
|
* limitations under the License.
|
|
16
18
|
*/
|
|
17
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.wrapReporterAsV2 = void 0;
|
|
19
|
-
function wrapReporterAsV2(reporter) {
|
|
20
|
-
try {
|
|
21
|
-
if ("version" in reporter && reporter.version() === "v2")
|
|
22
|
-
return reporter;
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.log("reporter", reporter);
|
|
26
|
-
}
|
|
27
|
-
return new ReporterV2Wrapper(reporter);
|
|
28
|
-
}
|
|
29
|
-
exports.wrapReporterAsV2 = wrapReporterAsV2;
|
|
30
|
-
class ReporterV2Wrapper {
|
|
31
|
-
_reporter;
|
|
32
|
-
_deferred = [];
|
|
33
|
-
_config;
|
|
34
|
-
constructor(reporter) {
|
|
35
|
-
this._reporter = reporter;
|
|
36
|
-
}
|
|
37
|
-
version() {
|
|
38
|
-
return "v2";
|
|
39
|
-
}
|
|
40
|
-
onConfigure(config) {
|
|
41
|
-
this._config = config;
|
|
42
|
-
}
|
|
43
|
-
onBegin(suite) {
|
|
44
|
-
this._reporter.onBegin?.(this._config, suite);
|
|
45
|
-
const deferred = this._deferred;
|
|
46
|
-
this._deferred = null;
|
|
47
|
-
for (const item of deferred) {
|
|
48
|
-
if (item.error)
|
|
49
|
-
this.onError(item.error);
|
|
50
|
-
if (item.stdout)
|
|
51
|
-
this.onStdOut(item.stdout.chunk, item.stdout.test, item.stdout.result);
|
|
52
|
-
if (item.stderr)
|
|
53
|
-
this.onStdErr(item.stderr.chunk, item.stderr.test, item.stderr.result);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
onTestBegin(test, result) {
|
|
57
|
-
this._reporter.onTestBegin?.(test, result);
|
|
58
|
-
}
|
|
59
|
-
onStdOut(chunk, test, result) {
|
|
60
|
-
if (this._deferred) {
|
|
61
|
-
this._deferred.push({ stdout: { chunk, test, result } });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this._reporter.onStdOut?.(chunk, test, result);
|
|
65
|
-
}
|
|
66
|
-
onStdErr(chunk, test, result) {
|
|
67
|
-
if (this._deferred) {
|
|
68
|
-
this._deferred.push({ stderr: { chunk, test, result } });
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
this._reporter.onStdErr?.(chunk, test, result);
|
|
72
|
-
}
|
|
73
|
-
async onTestEnd(test, result) {
|
|
74
|
-
this._reporter.onTestEnd?.(test, result);
|
|
75
|
-
}
|
|
76
|
-
async onEnd(result) {
|
|
77
|
-
return await this._reporter.onEnd?.(result);
|
|
78
|
-
}
|
|
79
|
-
async onExit() {
|
|
80
|
-
await this._reporter.onExit?.();
|
|
81
|
-
}
|
|
82
|
-
onError(error) {
|
|
83
|
-
if (this._deferred) {
|
|
84
|
-
this._deferred.push({ error });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this._reporter.onError?.(error);
|
|
88
|
-
}
|
|
89
|
-
onStepBegin(test, result, step) {
|
|
90
|
-
this._reporter.onStepBegin?.(test, result, step);
|
|
91
|
-
}
|
|
92
|
-
onStepEnd(test, result, step) {
|
|
93
|
-
this._reporter.onStepEnd?.(test, result, step);
|
|
94
|
-
}
|
|
95
|
-
printsToStdio() {
|
|
96
|
-
return this._reporter.printsToStdio ? this._reporter.printsToStdio() : true;
|
|
97
|
-
}
|
|
98
|
-
}
|
package/dist/reporter/util.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/util.ts
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
3
5
|
*
|
|
4
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/reporter/util.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/reporter/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;;AAiBH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAmB7D;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAAG,SAAS,UAMhC;AAED,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5E,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAyCD"}
|
package/dist/reporter/util.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/playwright/src/util.ts
|
|
3
4
|
* Copyright (c) Microsoft Corporation.
|
|
5
|
+
* Modifications copyright (c) Forge AI Private Limited
|
|
4
6
|
*
|
|
5
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
8
|
* you may not use this file except in compliance with the License.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/html-reporter/src/types.ts
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
4
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
import type { Metadata } from
|
|
17
|
+
import type { Metadata } from '@playwright/test';
|
|
17
18
|
export type Stats = {
|
|
18
19
|
total: number;
|
|
19
20
|
expected: number;
|
|
@@ -63,7 +64,7 @@ export type TestCaseSummary = {
|
|
|
63
64
|
location: Location;
|
|
64
65
|
annotations: TestCaseAnnotation[];
|
|
65
66
|
tags: string[];
|
|
66
|
-
outcome:
|
|
67
|
+
outcome: 'skipped' | 'expected' | 'unexpected' | 'flaky';
|
|
67
68
|
duration: number;
|
|
68
69
|
ok: boolean;
|
|
69
70
|
results: TestResultSummary[];
|
|
@@ -75,7 +76,7 @@ export type TestResultSummary = {
|
|
|
75
76
|
path?: string;
|
|
76
77
|
}[];
|
|
77
78
|
};
|
|
78
|
-
export type TestCase = Omit<TestCaseSummary,
|
|
79
|
+
export type TestCase = Omit<TestCaseSummary, 'results'> & {
|
|
79
80
|
results: TestResult[];
|
|
80
81
|
};
|
|
81
82
|
export type TestAttachment = {
|
|
@@ -91,7 +92,7 @@ export type TestResult = {
|
|
|
91
92
|
steps: TestStep[];
|
|
92
93
|
errors: string[];
|
|
93
94
|
attachments: TestAttachment[];
|
|
94
|
-
status:
|
|
95
|
+
status: 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';
|
|
95
96
|
};
|
|
96
97
|
export type TestStep = {
|
|
97
98
|
title: string;
|
|
@@ -103,4 +104,4 @@ export type TestStep = {
|
|
|
103
104
|
steps: TestStep[];
|
|
104
105
|
count: number;
|
|
105
106
|
};
|
|
106
|
-
//# sourceMappingURL=
|
|
107
|
+
//# sourceMappingURL=html-reporter-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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AC9B,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;CACtE,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* Original file: https://github.com/microsoft/playwright/blob/cf8c14f884b6f24966350a5f49b1580c3e183d21/packages/html-reporter/src/types.ts
|
|
3
4
|
* Copyright (c) Microsoft Corporation.
|
|
4
5
|
*
|
|
5
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"md5": "^2.3.0",
|
|
37
37
|
"mime": "3.0.0",
|
|
38
38
|
"playwright-core": "^1.46.1",
|
|
39
|
-
"@empiricalrun/llm": "^0.8.
|
|
39
|
+
"@empiricalrun/llm": "^0.8.3",
|
|
40
|
+
"@empiricalrun/r2-uploader": "^0.1.0"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"dev": "tsc --build --watch",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"htmlReporter.d.ts","sourceRoot":"","s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UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;CACtE,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
interface FileMap {
|
|
2
|
-
[file: string]: string;
|
|
3
|
-
}
|
|
4
|
-
export declare function uploadDirectory({ sourceDir, fileList, destinationDir, uploadBucket, }: {
|
|
5
|
-
sourceDir: string;
|
|
6
|
-
fileList?: string[];
|
|
7
|
-
destinationDir: string;
|
|
8
|
-
uploadBucket: string;
|
|
9
|
-
}): Promise<FileMap>;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/reporter/upload.ts"],"names":[],"mappings":"AAsBA,UAAU,OAAO;IACf,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AA+GD,wBAAsB,eAAe,CAAC,EACpC,SAAS,EACT,QAAQ,EACR,cAAc,EACd,YAAY,GACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,OAAO,CAAC,CAYnB"}
|
package/dist/reporter/upload.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.uploadDirectory = void 0;
|
|
30
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
31
|
-
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
32
|
-
const fs = __importStar(require("fs"));
|
|
33
|
-
const md5_1 = __importDefault(require("md5"));
|
|
34
|
-
const path_1 = __importDefault(require("path"));
|
|
35
|
-
const getFileList = (dir) => {
|
|
36
|
-
let files = [];
|
|
37
|
-
const items = fs.readdirSync(dir, {
|
|
38
|
-
withFileTypes: true,
|
|
39
|
-
});
|
|
40
|
-
for (const item of items) {
|
|
41
|
-
const isDir = item.isDirectory();
|
|
42
|
-
const absolutePath = `${dir}/${item.name}`;
|
|
43
|
-
if (isDir) {
|
|
44
|
-
files = [...files, ...getFileList(absolutePath)];
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
files.push(absolutePath);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return files;
|
|
51
|
-
};
|
|
52
|
-
const run = async (config) => {
|
|
53
|
-
const map = new Map();
|
|
54
|
-
const urls = {};
|
|
55
|
-
const S3 = new client_s3_1.S3Client({
|
|
56
|
-
region: "auto",
|
|
57
|
-
endpoint: `https://${config.accountId}.r2.cloudflarestorage.com`,
|
|
58
|
-
credentials: {
|
|
59
|
-
accessKeyId: config.accessKeyId,
|
|
60
|
-
secretAccessKey: config.secretAccessKey,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
let files;
|
|
64
|
-
if (config.fileList) {
|
|
65
|
-
files = config.fileList;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
files = getFileList(config.sourceDir);
|
|
69
|
-
}
|
|
70
|
-
await Promise.all(files.map(async (file) => {
|
|
71
|
-
const fileStream = fs.readFileSync(file);
|
|
72
|
-
const fileName = file.replace(config.sourceDir, "");
|
|
73
|
-
const fileKey = path_1.default.join(config.destinationDir !== "" ? config.destinationDir : config.sourceDir, fileName);
|
|
74
|
-
if (fileKey.includes(".gitkeep"))
|
|
75
|
-
return;
|
|
76
|
-
// console.log(fileKey);
|
|
77
|
-
let mimeType = "application/octet-stream";
|
|
78
|
-
try {
|
|
79
|
-
const mime = (await import("mime")).default;
|
|
80
|
-
mimeType = mime.getType(file) || "application/octet-stream";
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
console.warn("Failed to get mime type for file", file, err);
|
|
84
|
-
}
|
|
85
|
-
const uploadParams = {
|
|
86
|
-
Bucket: config.bucket,
|
|
87
|
-
Key: fileKey,
|
|
88
|
-
Body: fileStream,
|
|
89
|
-
ContentLength: fs.statSync(file).size,
|
|
90
|
-
ContentType: mimeType ?? "application/octet-stream",
|
|
91
|
-
};
|
|
92
|
-
const cmd = new client_s3_1.PutObjectCommand(uploadParams);
|
|
93
|
-
const digest = (0, md5_1.default)(fileStream);
|
|
94
|
-
cmd.middlewareStack.add((next) => async (args) => {
|
|
95
|
-
args.request.headers["if-none-match"] = `"${digest}"`;
|
|
96
|
-
return await next(args);
|
|
97
|
-
}, {
|
|
98
|
-
step: "build",
|
|
99
|
-
name: "addETag",
|
|
100
|
-
});
|
|
101
|
-
try {
|
|
102
|
-
const data = await S3.send(cmd);
|
|
103
|
-
// console.log(`R2 Success - ${file}`);
|
|
104
|
-
map.set(file, data);
|
|
105
|
-
const fileUrl = await (0, s3_request_presigner_1.getSignedUrl)(S3, cmd);
|
|
106
|
-
urls[file] = fileUrl;
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
const error = err;
|
|
110
|
-
if (error["$metadata"]) {
|
|
111
|
-
if (error.$metadata.httpStatusCode !== 412) {
|
|
112
|
-
console.log(`R2 Error - ${file} ${config.sourceDir} ${config.destinationDir} \nError: ${error}`);
|
|
113
|
-
console.log("Upload response", error.$response, "with status", error.$metadata.httpStatusCode);
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return;
|
|
119
|
-
}));
|
|
120
|
-
return urls;
|
|
121
|
-
};
|
|
122
|
-
async function uploadDirectory({ sourceDir, fileList, destinationDir, uploadBucket, }) {
|
|
123
|
-
let config = {
|
|
124
|
-
accountId: process.env.R2_ACCOUNT_ID,
|
|
125
|
-
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
|
126
|
-
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
|
127
|
-
bucket: uploadBucket,
|
|
128
|
-
sourceDir,
|
|
129
|
-
destinationDir,
|
|
130
|
-
fileList,
|
|
131
|
-
};
|
|
132
|
-
const uploadedFiles = await run(config);
|
|
133
|
-
return uploadedFiles;
|
|
134
|
-
}
|
|
135
|
-
exports.uploadDirectory = uploadDirectory;
|