@wopee-io/wopee.pw 4.24.0 → 4.24.3
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/.github/workflows/ci_cd.yaml +30 -12
- package/README.md +13 -0
- package/build/core/ports/configPort/configPort.js +2 -0
- package/build/core/ports/configPort/configPort.js.map +1 -1
- package/build/core/ports/configPort/configValidation.d.ts +2 -0
- package/build/core/ports/configPort/configValidation.js +49 -0
- package/build/core/ports/configPort/configValidation.js.map +1 -0
- package/build/core/services/wopeeService/wopee.js +7 -0
- package/build/core/services/wopeeService/wopee.js.map +1 -1
- package/build/shared/metadata/versionMetadata.js +15 -6
- package/build/shared/metadata/versionMetadata.js.map +1 -1
- package/build/tools/wopee-reporter/wopeeReporter.d.ts +6 -0
- package/build/tools/wopee-reporter/wopeeReporter.js +73 -11
- package/build/tools/wopee-reporter/wopeeReporter.js.map +1 -1
- package/docs/configuration.md +39 -15
- package/docs/troubleshooting.md +59 -0
- package/node_modules/@autonomous-testing/sdk/.github/workflows/ci_cd.yaml +47 -20
- package/node_modules/@autonomous-testing/sdk/README.md +129 -36
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/adapter.js +4 -8
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/axios-config.d.ts +12 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/axios-config.js +5 -4
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/errors.d.ts +20 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/errors.js +178 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/interface.d.ts +1 -1
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/interface.js +13 -3
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/services/apolloAdapterService/apolloAdapterService.js +6 -2
- package/node_modules/@autonomous-testing/sdk/build/shared/metadata/versionMetadata.js +2 -2
- package/node_modules/@autonomous-testing/sdk/build/shared/utils/error.interface.d.ts +13 -1
- package/node_modules/@autonomous-testing/sdk/build/shared/utils/error.interface.js +8 -1
- package/node_modules/@autonomous-testing/sdk/build/shared/utils/index.d.ts +2 -2
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/README.md +145 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/index.d.ts +78 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/index.js +203 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/index.js.map +1 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/promisify.d.ts +4 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/promisify.js +18 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/dist/src/promisify.js.map +1 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/package.json +64 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/src/index.ts +345 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/agent-base/src/promisify.ts +33 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/README.md +137 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/agent.d.ts +30 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/agent.js +177 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/agent.js.map +1 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/index.d.ts +23 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/index.js +14 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/index.js.map +1 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +7 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/parse-proxy-response.js +66 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
- package/node_modules/@autonomous-testing/sdk/node_modules/https-proxy-agent/package.json +56 -0
- package/node_modules/@autonomous-testing/sdk/package.json +18 -6
- package/node_modules/agent-base/LICENSE +22 -0
- package/node_modules/agent-base/README.md +69 -0
- package/node_modules/agent-base/dist/helpers.d.ts +15 -0
- package/node_modules/agent-base/dist/helpers.d.ts.map +1 -0
- package/node_modules/agent-base/dist/helpers.js +66 -0
- package/node_modules/agent-base/dist/helpers.js.map +1 -0
- package/node_modules/agent-base/dist/index.d.ts +41 -0
- package/node_modules/agent-base/dist/index.d.ts.map +1 -0
- package/node_modules/agent-base/dist/index.js +178 -0
- package/node_modules/agent-base/dist/index.js.map +1 -0
- package/node_modules/agent-base/package.json +46 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/http-proxy-agent/LICENSE +22 -0
- package/node_modules/http-proxy-agent/README.md +44 -0
- package/node_modules/http-proxy-agent/dist/index.d.ts +44 -0
- package/node_modules/http-proxy-agent/dist/index.d.ts.map +1 -0
- package/node_modules/http-proxy-agent/dist/index.js +148 -0
- package/node_modules/http-proxy-agent/dist/index.js.map +1 -0
- package/node_modules/http-proxy-agent/package.json +47 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/package.json +3 -3
- package/tsconfig.build.json +4 -0
- package/.github/actions/npm_clean_install/action.yaml +0 -35
- package/node_modules/@autonomous-testing/sdk/.github/actions/npm_clean_install/action.yaml +0 -35
|
@@ -15,15 +15,18 @@ permissions:
|
|
|
15
15
|
jobs:
|
|
16
16
|
npm-clean-install:
|
|
17
17
|
runs-on: builder
|
|
18
|
+
container:
|
|
19
|
+
image: node:24
|
|
20
|
+
options: --user 1000
|
|
18
21
|
|
|
19
22
|
steps:
|
|
20
23
|
- name: Check-out
|
|
21
|
-
uses: actions/checkout@
|
|
24
|
+
uses: actions/checkout@v7
|
|
22
25
|
with:
|
|
23
26
|
fetch-depth: 1
|
|
24
27
|
|
|
25
28
|
- name: Install
|
|
26
|
-
uses:
|
|
29
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
27
30
|
with:
|
|
28
31
|
npm-token: ${{ github.token }}
|
|
29
32
|
|
|
@@ -31,15 +34,18 @@ jobs:
|
|
|
31
34
|
needs: [npm-clean-install]
|
|
32
35
|
if: github.event_name == 'pull_request'
|
|
33
36
|
runs-on: builder
|
|
37
|
+
container:
|
|
38
|
+
image: node:24
|
|
39
|
+
options: --user 1000
|
|
34
40
|
|
|
35
41
|
steps:
|
|
36
42
|
- name: Check-out
|
|
37
|
-
uses: actions/checkout@
|
|
43
|
+
uses: actions/checkout@v7
|
|
38
44
|
with:
|
|
39
45
|
fetch-depth: 0
|
|
40
46
|
|
|
41
47
|
- name: Install
|
|
42
|
-
uses:
|
|
48
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
43
49
|
with:
|
|
44
50
|
npm-token: ${{ github.token }}
|
|
45
51
|
|
|
@@ -65,15 +71,18 @@ jobs:
|
|
|
65
71
|
before-build-test:
|
|
66
72
|
needs: [npm-clean-install]
|
|
67
73
|
runs-on: builder
|
|
74
|
+
container:
|
|
75
|
+
image: node:24
|
|
76
|
+
options: --user 1000
|
|
68
77
|
|
|
69
78
|
steps:
|
|
70
79
|
- name: Check-out
|
|
71
|
-
uses: actions/checkout@
|
|
80
|
+
uses: actions/checkout@v7
|
|
72
81
|
with:
|
|
73
82
|
fetch-depth: 1
|
|
74
83
|
|
|
75
84
|
- name: Install
|
|
76
|
-
uses:
|
|
85
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
77
86
|
with:
|
|
78
87
|
npm-token: ${{ github.token }}
|
|
79
88
|
|
|
@@ -84,15 +93,18 @@ jobs:
|
|
|
84
93
|
build:
|
|
85
94
|
needs: [npm-clean-install]
|
|
86
95
|
runs-on: builder
|
|
96
|
+
container:
|
|
97
|
+
image: node:24
|
|
98
|
+
options: --user 1000
|
|
87
99
|
|
|
88
100
|
steps:
|
|
89
101
|
- name: Check-out
|
|
90
|
-
uses: actions/checkout@
|
|
102
|
+
uses: actions/checkout@v7
|
|
91
103
|
with:
|
|
92
104
|
fetch-depth: 1
|
|
93
105
|
|
|
94
106
|
- name: Install
|
|
95
|
-
uses:
|
|
107
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
96
108
|
with:
|
|
97
109
|
npm-token: ${{ github.token }}
|
|
98
110
|
|
|
@@ -102,15 +114,18 @@ jobs:
|
|
|
102
114
|
after-build-test:
|
|
103
115
|
needs: [build]
|
|
104
116
|
runs-on: builder
|
|
117
|
+
container:
|
|
118
|
+
image: node:24
|
|
119
|
+
options: --user 1000
|
|
105
120
|
|
|
106
121
|
steps:
|
|
107
122
|
- name: Check-out
|
|
108
|
-
uses: actions/checkout@
|
|
123
|
+
uses: actions/checkout@v7
|
|
109
124
|
with:
|
|
110
125
|
fetch-depth: 1
|
|
111
126
|
|
|
112
127
|
- name: Install
|
|
113
|
-
uses:
|
|
128
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
114
129
|
with:
|
|
115
130
|
npm-token: ${{ github.token }}
|
|
116
131
|
|
|
@@ -132,18 +147,21 @@ jobs:
|
|
|
132
147
|
needs: [before-build-test, after-build-test]
|
|
133
148
|
if: github.event_name == 'push'
|
|
134
149
|
runs-on: builder
|
|
150
|
+
container:
|
|
151
|
+
image: node:24
|
|
152
|
+
options: --user 1000
|
|
135
153
|
permissions:
|
|
136
154
|
contents: write
|
|
137
155
|
packages: write
|
|
138
156
|
|
|
139
157
|
steps:
|
|
140
158
|
- name: Check-out
|
|
141
|
-
uses: actions/checkout@
|
|
159
|
+
uses: actions/checkout@v7
|
|
142
160
|
with:
|
|
143
161
|
fetch-depth: 0
|
|
144
162
|
|
|
145
163
|
- name: Install
|
|
146
|
-
uses:
|
|
164
|
+
uses: autonomous-testing/npm-install-action@v3
|
|
147
165
|
with:
|
|
148
166
|
npm-token: ${{ github.token }}
|
|
149
167
|
|
package/README.md
CHANGED
|
@@ -29,6 +29,19 @@ test('visual check', async ({ page }) => {
|
|
|
29
29
|
});
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Two environment variables are required. Get both from your project at [cmd.wopee.io](https://cmd.wopee.io) — the key from Project Settings → API Keys, the UUID from Project Settings:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export WOPEE_API_KEY=<your api key>
|
|
38
|
+
export WOPEE_PROJECT_UUID=<your project uuid>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Set them in your shell, in a `.env` file next to your Playwright config, or as CI secrets. If either is missing, `new Wopee()` fails immediately with a message naming the variable.
|
|
42
|
+
|
|
43
|
+
Self-hosted instances also set `WOPEE_API_URL`, and are typically reachable only from the customer network — see [docs/configuration.md](./docs/configuration.md) for the full variable list and proxy support, and [docs/troubleshooting.md](./docs/troubleshooting.md) if a run cannot reach the API.
|
|
44
|
+
|
|
32
45
|
## Features
|
|
33
46
|
|
|
34
47
|
- **Visual regression testing** — pixel-level and AI-powered comparison
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfigPort = void 0;
|
|
4
4
|
const configDefaults_js_1 = require("./configDefaults.js");
|
|
5
|
+
const configValidation_js_1 = require("./configValidation.js");
|
|
5
6
|
class ConfigPort {
|
|
6
7
|
loadConfig() {
|
|
7
8
|
this._config = (0, configDefaults_js_1.setWopeeOptionsDefaults)(this._loadConfig());
|
|
9
|
+
(0, configValidation_js_1.assertScreenshotValidationConfig)(this._config.screenshotValidation);
|
|
8
10
|
return this._config;
|
|
9
11
|
}
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configPort.js","sourceRoot":"","sources":["../../../../lib/core/ports/configPort/configPort.ts"],"names":[],"mappings":";;;AACA,2DAA8D;
|
|
1
|
+
{"version":3,"file":"configPort.js","sourceRoot":"","sources":["../../../../lib/core/ports/configPort/configPort.ts"],"names":[],"mappings":";;;AACA,2DAA8D;AAC9D,+DAAyE;AAEzE,MAAsB,UAAU;IAK9B,UAAU;QACR,IAAI,CAAC,OAAO,GAAG,IAAA,2CAAuB,EAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAE3D,IAAA,sDAAgC,EAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAXD,gCAWC","sourcesContent":["import { WopeeOptions } from '../../domain/configuration/config.interface.js';\nimport { setWopeeOptionsDefaults } from './configDefaults.js';\nimport { assertScreenshotValidationConfig } from './configValidation.js';\n\nexport abstract class ConfigPort {\n private _config: WopeeOptions;\n\n abstract _loadConfig(): WopeeOptions;\n\n loadConfig(): WopeeOptions {\n this._config = setWopeeOptionsDefaults(this._loadConfig());\n // Validated after defaults are merged, so the enabled flag is resolved.\n assertScreenshotValidationConfig(this._config.screenshotValidation);\n return this._config;\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertScreenshotValidationConfig = assertScreenshotValidationConfig;
|
|
4
|
+
const sdk_1 = require("@autonomous-testing/sdk");
|
|
5
|
+
const DOCS_URL = 'https://docs.wopee.io/playwright-visual-testing/';
|
|
6
|
+
const CMD_URL = 'https://cmd.wopee.io';
|
|
7
|
+
const REQUIRED_OPTIONS = [
|
|
8
|
+
{
|
|
9
|
+
key: 'apiKey',
|
|
10
|
+
env: 'WOPEE_API_KEY',
|
|
11
|
+
where: `Project Settings → API Keys at ${CMD_URL}`,
|
|
12
|
+
placeholder: '<your api key>',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
key: 'projectUuid',
|
|
16
|
+
env: 'WOPEE_PROJECT_UUID',
|
|
17
|
+
where: `Project Settings at ${CMD_URL}`,
|
|
18
|
+
placeholder: '<your project uuid>',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
function isMissing(value) {
|
|
22
|
+
return value === undefined || value === null || String(value).trim() === '';
|
|
23
|
+
}
|
|
24
|
+
function assertScreenshotValidationConfig(options) {
|
|
25
|
+
if (!(options === null || options === void 0 ? void 0 : options.screenshotValidationEnabled)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const missing = REQUIRED_OPTIONS.filter((option) => isMissing(options[option.key]));
|
|
29
|
+
if (missing.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const width = Math.max(...missing.map((option) => option.env.length));
|
|
33
|
+
const message = [
|
|
34
|
+
'Wopee is not configured — missing required environment variables.',
|
|
35
|
+
'',
|
|
36
|
+
' Missing:',
|
|
37
|
+
...missing.map((option) => ` • ${option.env.padEnd(width)} — ${option.where}`),
|
|
38
|
+
'',
|
|
39
|
+
' Set them in your shell, in a .env file next to your Playwright config, or as',
|
|
40
|
+
' CI secrets:',
|
|
41
|
+
'',
|
|
42
|
+
...missing.map((option) => ` ${option.env}=${option.placeholder}`),
|
|
43
|
+
' WOPEE_API_URL=https://api.wopee.io # only for self-hosted instances',
|
|
44
|
+
'',
|
|
45
|
+
` Docs: ${DOCS_URL}`,
|
|
46
|
+
].join('\n');
|
|
47
|
+
throw new sdk_1.WopeeError(message, { code: 'WOPEE_CONFIG_INVALID' });
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=configValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;QAClF,EAAE;QACF,gFAAgF;QAChF,eAAe;QACf,EAAE;QACF,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACrE,2EAA2E;QAC3E,EAAE;QACF,WAAW,QAAQ,EAAE;KACtB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAIb,MAAM,IAAI,gBAAU,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { ScreenshotValidationOptions } from '../../domain/configuration/config.interface.js';\nimport { WopeeError } from '@autonomous-testing/sdk';\n\nconst DOCS_URL = 'https://docs.wopee.io/playwright-visual-testing/';\nconst CMD_URL = 'https://cmd.wopee.io';\n\n/*\nMirrors the mapping in EnvConfigAdapter. Kept here so the error can name the\nenvironment variable the user actually has to set, rather than the internal\nconfig field.\n*/\nconst REQUIRED_OPTIONS = [\n {\n key: 'apiKey',\n env: 'WOPEE_API_KEY',\n where: `Project Settings → API Keys at ${CMD_URL}`,\n placeholder: '<your api key>',\n },\n {\n key: 'projectUuid',\n env: 'WOPEE_PROJECT_UUID',\n where: `Project Settings at ${CMD_URL}`,\n placeholder: '<your project uuid>',\n },\n] as const;\n\n/*\nWOPEE_API_URL is deliberately not required — it has a working SaaS default in\nthe SDK schema, and requiring it would break every existing SaaS user.\n*/\n\nfunction isMissing(value: unknown): boolean {\n return value === undefined || value === null || String(value).trim() === '';\n}\n\n/**\n * Fails fast, before the SDK adapter is constructed, so the user sees which\n * variable to set instead of a validation dump from deeper in the stack.\n */\nexport function assertScreenshotValidationConfig(options?: ScreenshotValidationOptions): void {\n // Same expression Wopee uses to decide whether to build the adapter, so the\n // two can never disagree about whether Wopee is switched on.\n if (!options?.screenshotValidationEnabled) {\n return;\n }\n\n const missing = REQUIRED_OPTIONS.filter((option) => isMissing(options[option.key]));\n if (missing.length === 0) {\n return;\n }\n\n const width = Math.max(...missing.map((option) => option.env.length));\n const message = [\n 'Wopee is not configured — missing required environment variables.',\n '',\n ' Missing:',\n ...missing.map((option) => ` • ${option.env.padEnd(width)} — ${option.where}`),\n '',\n ' Set them in your shell, in a .env file next to your Playwright config, or as',\n ' CI secrets:',\n '',\n ...missing.map((option) => ` ${option.env}=${option.placeholder}`),\n ' WOPEE_API_URL=https://api.wopee.io # only for self-hosted instances',\n '',\n ` Docs: ${DOCS_URL}`,\n ].join('\\n');\n\n // Same code the SDK uses for its own configuration failures, so callers can\n // branch on error.code regardless of which layer rejected the config.\n throw new WopeeError(message, { code: 'WOPEE_CONFIG_INVALID' });\n}\n"]}
|
|
@@ -54,6 +54,7 @@ class Wopee {
|
|
|
54
54
|
}
|
|
55
55
|
startScenario(scenarioName, testInfo) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
57
58
|
if (this._config.screenshotValidation.screenshotValidationEnabled) {
|
|
58
59
|
const scenario = yield this._screenshotValidation.createIntegrationScenario({ scenarioName });
|
|
59
60
|
if (testInfo) {
|
|
@@ -61,6 +62,12 @@ class Wopee {
|
|
|
61
62
|
contentType: 'text/plain',
|
|
62
63
|
body: scenario === null || scenario === void 0 ? void 0 : scenario.uuid,
|
|
63
64
|
});
|
|
65
|
+
if ((_a = this._screenshotValidation.suite) === null || _a === void 0 ? void 0 : _a.uuid) {
|
|
66
|
+
yield testInfo.attach('wopee-suite-uuid', {
|
|
67
|
+
contentType: 'text/plain',
|
|
68
|
+
body: this._screenshotValidation.suite.uuid,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
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C,oBAAoB,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAQK,YAAY,CAAC,mBAAwC;;YACzD,IAAI,WAAW,GAAG,IAAI,CAAC;YACvB,IAAI,mBAAmB,CAAC,WAAW,EAAE,CAAC;gBACpC,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC;YAChD,CAAC;iBAAM,IAAI,mBAAmB,CAAC,IAAI,EAAE,CAAC;gBACpC,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChE,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC;YACD,MAAM,OAAO,GAAwB,+BAAyB,CAAC,KAAK,CAAC;gBACnE,WAAW;gBACX,MAAM,EAAE,mBAAmB,CAAC,MAAM;gBAClC,OAAO,EAAE,mBAAmB,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;KAAA;CACF;AAnOD,sBAmOC","sourcesContent":["import { EnvConfigAdapter } from '../../../infrastructure/adapters/envConfigAdapter/envConfigAdapter.js';\nimport { logVersionMetadata } from '../../../shared/index.js';\nimport { WopeeOptions } from '../../domain/configuration/config.interface.js';\nimport {\n TrackElementOptions,\n TrackFullPageOptions,\n TrackImageOptions,\n TrackViewportOptions,\n} from '../../domain/valueObjects/track.interface.js';\nimport { VisualAssertOptions } from '../../domain/valueObjects/visualAssert.interface.js';\nimport {\n ApolloAdapter,\n ApolloAdapterConfig,\n CreateIntegrationStepPayload,\n CreateIntegrationStepPayloadSchema,\n IntegrationStep,\n VisualAssert,\n VisualAssertPayload,\n VisualAssertPayloadSchema,\n createApolloTrackAdapter,\n} from '@autonomous-testing/sdk';\nimport { LocatorScreenshotOptions, PageScreenshotOptions, TestInfo } from '@playwright/test';\n\n/**\n * The Wopee class provides methods to configure and manage screenshot validation\n * for testing environments, leveraging external APIs and customized options.\n */\nexport class Wopee {\n private _config: WopeeOptions = null;\n private _screenshotValidation: ApolloAdapter;\n\n /**\n * Initializes the class by logging version metadata, parsing configuration,\n * and setting up instance options based on environmental variables or defaults.\n */\n constructor() {\n logVersionMetadata();\n this._config = new EnvConfigAdapter().loadConfig();\n\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n this._screenshotValidation = this._createApolloTrackAdapter();\n }\n }\n\n /**\n * Creates an ApolloTrackAdapter for tracking and validating screenshots.\n * @returns {ApolloTrackAdapter} The initialized tracking adapter.\n */\n private _createApolloTrackAdapter(): ApolloAdapter {\n const apolloAdapterConfig: ApolloAdapterConfig = {\n apiKey: this._config.screenshotValidation.apiKey,\n apiUrl: this._config.screenshotValidation.apiUrl,\n branchName: this._config.screenshotValidation?.branchName,\n enableSoftAssert: this._config.screenshotValidation?.enableSoftAssert,\n projectUuid: this._config.screenshotValidation.projectUuid,\n browser: this._config.screenshotValidation?.browser,\n comment: this._config.screenshotValidation?.comment,\n device: this._config.screenshotValidation?.device,\n os: this._config.screenshotValidation?.os,\n pixelToPixelDiffTolerance: this._config.screenshotValidation.pixelToPixelDiffTolerance,\n viewport: this._config.screenshotValidation?.viewport,\n customTags: this._config.screenshotValidation?.customTags,\n baselineBranchName: this._config.screenshotValidation?.baselineBranchName,\n suiteUuid: this._config.screenshotValidation?.suiteUuid,\n };\n return createApolloTrackAdapter({\n apolloAdapterConfig: apolloAdapterConfig,\n loggerOptions: { logger: 'ConsoleLogger' },\n });\n }\n\n /**\n * Starts the screenshot validation process, create/connect to Suite.\n */\n async startSuite(suiteName: string): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n await this._screenshotValidation.createIntegrationSuite({ suiteName });\n }\n }\n\n /**\n * Starts the screenshot validation process, create/connect to Suite.\n */\n async startScenario(scenarioName: string, testInfo?: TestInfo): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const scenario = await this._screenshotValidation.createIntegrationScenario({ scenarioName });\n if (testInfo) {\n await testInfo.attach('wopee-scenario-uuid', {\n contentType: 'text/plain',\n body: scenario?.uuid,\n });\n }\n }\n }\n\n /**\n * Stops the screenshot validation process.\n */\n async stopScenario(): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n await this._screenshotValidation.stopIntegrationScenario();\n }\n }\n\n async _trackImage(trackImageOptions: TrackImageOptions): Promise<IntegrationStep> {\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackImageOptions,\n });\n return await this._screenshotValidation.createIntegrationStep(payload);\n }\n\n /**\n * Submits a given image for tracking and validation.\n * @param trackImageOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackImage(trackImageOptions: TrackImageOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackImage(trackImageOptions);\n }\n return null;\n }\n\n async _trackFullPage(trackFullPageOptions: TrackFullPageOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n let pageContentBase64 = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const pageScreenshotOptions: PageScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n fullPage: true,\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackFullPageOptions.page.screenshot(pageScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n if (this._config.screenshotValidation.collectPageContent) {\n const pageContent = await trackFullPageOptions.page.content();\n pageContentBase64 = Buffer.from(pageContent, 'utf-8').toString('base64');\n }\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackFullPageOptions,\n imageBase64,\n pageContentBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a full page screenshot for validation.\n * @param trackFullPageOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackFullPage(trackFullPageOptions: TrackFullPageOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackFullPage(trackFullPageOptions);\n }\n return null;\n }\n\n async _trackElement(trackElementOptions: TrackElementOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const locatorScreenshotOptions: LocatorScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackElementOptions.locator.screenshot(locatorScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackElementOptions,\n imageBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a element screenshot for validation.\n * @param trackElementOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackElement(trackElementOptions: TrackElementOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackElement(trackElementOptions);\n }\n return null;\n }\n\n async _trackViewport(trackViewportOptions: TrackViewportOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n let pageContentBase64 = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const pageScreenshotOptions: PageScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n fullPage: false,\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackViewportOptions.page.screenshot(pageScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n if (this._config.screenshotValidation.collectPageContent) {\n const pageContent = await trackViewportOptions.page.content();\n pageContentBase64 = Buffer.from(pageContent, 'utf-8').toString('base64');\n }\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackViewportOptions,\n imageBase64,\n pageContentBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a viewport screenshot for validation.\n * @param TrackViewportOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackViewport(trackViewportOptions: TrackViewportOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackViewport(trackViewportOptions);\n }\n return null;\n }\n\n /**\n * Visual assert based on provided context, prompt (question) against an image.\n * Provide either imageBase64 or page object to take a screenshot at the current state.\n * @param VisualAssertOptions Parameters for visual assertion.\n * @returns {VisualAssert} The result of the visual assertion operation.\n */\n async visualAssert(visualAssertOptions: VisualAssertOptions): Promise<VisualAssert> {\n let imageBase64 = null;\n if (visualAssertOptions.imageBase64) {\n imageBase64 = visualAssertOptions.imageBase64;\n } else if (visualAssertOptions.page) {\n const imageBuffer = await visualAssertOptions.page.screenshot();\n imageBase64 = imageBuffer.toString('base64');\n }\n const payload: VisualAssertPayload = VisualAssertPayloadSchema.parse({\n imageBase64,\n prompt: visualAssertOptions.prompt,\n context: visualAssertOptions.context,\n });\n return await this._screenshotValidation.visualAssert(payload);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wopee.js","sourceRoot":"","sources":["../../../../lib/core/services/wopeeService/wopee.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+GAAyG;AACzG,uDAA8D;AAS9D,iDAUiC;AAOjC,MAAa,KAAK;IAQhB;QAPQ,YAAO,GAAiB,IAAI,CAAC;QAQnC,IAAA,6BAAkB,GAAE,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,sCAAgB,EAAE,CAAC,UAAU,EAAE,CAAC;QAEnD,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,2BAA2B,EAAE,CAAC;YAClE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,yBAAyB,EAAE,C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BACpC,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC;YAChD,CAAC;iBAAM,IAAI,mBAAmB,CAAC,IAAI,EAAE,CAAC;gBACpC,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChE,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC;YACD,MAAM,OAAO,GAAwB,+BAAyB,CAAC,KAAK,CAAC;gBACnE,WAAW;gBACX,MAAM,EAAE,mBAAmB,CAAC,MAAM;gBAClC,OAAO,EAAE,mBAAmB,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;KAAA;CACF;AA1OD,sBA0OC","sourcesContent":["import { EnvConfigAdapter } from '../../../infrastructure/adapters/envConfigAdapter/envConfigAdapter.js';\nimport { logVersionMetadata } from '../../../shared/index.js';\nimport { WopeeOptions } from '../../domain/configuration/config.interface.js';\nimport {\n TrackElementOptions,\n TrackFullPageOptions,\n TrackImageOptions,\n TrackViewportOptions,\n} from '../../domain/valueObjects/track.interface.js';\nimport { VisualAssertOptions } from '../../domain/valueObjects/visualAssert.interface.js';\nimport {\n ApolloAdapter,\n ApolloAdapterConfig,\n CreateIntegrationStepPayload,\n CreateIntegrationStepPayloadSchema,\n IntegrationStep,\n VisualAssert,\n VisualAssertPayload,\n VisualAssertPayloadSchema,\n createApolloTrackAdapter,\n} from '@autonomous-testing/sdk';\nimport { LocatorScreenshotOptions, PageScreenshotOptions, TestInfo } from '@playwright/test';\n\n/**\n * The Wopee class provides methods to configure and manage screenshot validation\n * for testing environments, leveraging external APIs and customized options.\n */\nexport class Wopee {\n private _config: WopeeOptions = null;\n private _screenshotValidation: ApolloAdapter;\n\n /**\n * Initializes the class by logging version metadata, parsing configuration,\n * and setting up instance options based on environmental variables or defaults.\n */\n constructor() {\n logVersionMetadata();\n this._config = new EnvConfigAdapter().loadConfig();\n\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n this._screenshotValidation = this._createApolloTrackAdapter();\n }\n }\n\n /**\n * Creates an ApolloTrackAdapter for tracking and validating screenshots.\n * @returns {ApolloTrackAdapter} The initialized tracking adapter.\n */\n private _createApolloTrackAdapter(): ApolloAdapter {\n const apolloAdapterConfig: ApolloAdapterConfig = {\n apiKey: this._config.screenshotValidation.apiKey,\n apiUrl: this._config.screenshotValidation.apiUrl,\n branchName: this._config.screenshotValidation?.branchName,\n enableSoftAssert: this._config.screenshotValidation?.enableSoftAssert,\n projectUuid: this._config.screenshotValidation.projectUuid,\n browser: this._config.screenshotValidation?.browser,\n comment: this._config.screenshotValidation?.comment,\n device: this._config.screenshotValidation?.device,\n os: this._config.screenshotValidation?.os,\n pixelToPixelDiffTolerance: this._config.screenshotValidation.pixelToPixelDiffTolerance,\n viewport: this._config.screenshotValidation?.viewport,\n customTags: this._config.screenshotValidation?.customTags,\n baselineBranchName: this._config.screenshotValidation?.baselineBranchName,\n suiteUuid: this._config.screenshotValidation?.suiteUuid,\n };\n return createApolloTrackAdapter({\n apolloAdapterConfig: apolloAdapterConfig,\n loggerOptions: { logger: 'ConsoleLogger' },\n });\n }\n\n /**\n * Starts the screenshot validation process, create/connect to Suite.\n */\n async startSuite(suiteName: string): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n await this._screenshotValidation.createIntegrationSuite({ suiteName });\n }\n }\n\n /**\n * Starts the screenshot validation process, create/connect to Suite.\n */\n async startScenario(scenarioName: string, testInfo?: TestInfo): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const scenario = await this._screenshotValidation.createIntegrationScenario({ scenarioName });\n if (testInfo) {\n await testInfo.attach('wopee-scenario-uuid', {\n contentType: 'text/plain',\n body: scenario?.uuid,\n });\n // Lets the wopee reporter stop the suite at the end of the run (worker → reporter channel).\n if (this._screenshotValidation.suite?.uuid) {\n await testInfo.attach('wopee-suite-uuid', {\n contentType: 'text/plain',\n body: this._screenshotValidation.suite.uuid,\n });\n }\n }\n }\n }\n\n /**\n * Stops the screenshot validation process.\n */\n async stopScenario(): Promise<void> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n await this._screenshotValidation.stopIntegrationScenario();\n }\n }\n\n async _trackImage(trackImageOptions: TrackImageOptions): Promise<IntegrationStep> {\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackImageOptions,\n });\n return await this._screenshotValidation.createIntegrationStep(payload);\n }\n\n /**\n * Submits a given image for tracking and validation.\n * @param trackImageOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackImage(trackImageOptions: TrackImageOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackImage(trackImageOptions);\n }\n return null;\n }\n\n async _trackFullPage(trackFullPageOptions: TrackFullPageOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n let pageContentBase64 = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const pageScreenshotOptions: PageScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n fullPage: true,\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackFullPageOptions.page.screenshot(pageScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n if (this._config.screenshotValidation.collectPageContent) {\n const pageContent = await trackFullPageOptions.page.content();\n pageContentBase64 = Buffer.from(pageContent, 'utf-8').toString('base64');\n }\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackFullPageOptions,\n imageBase64,\n pageContentBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a full page screenshot for validation.\n * @param trackFullPageOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackFullPage(trackFullPageOptions: TrackFullPageOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackFullPage(trackFullPageOptions);\n }\n return null;\n }\n\n async _trackElement(trackElementOptions: TrackElementOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const locatorScreenshotOptions: LocatorScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackElementOptions.locator.screenshot(locatorScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackElementOptions,\n imageBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a element screenshot for validation.\n * @param trackElementOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackElement(trackElementOptions: TrackElementOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackElement(trackElementOptions);\n }\n return null;\n }\n\n async _trackViewport(trackViewportOptions: TrackViewportOptions): Promise<IntegrationStep> {\n let apolloTrackResult: IntegrationStep = null;\n let pageContentBase64 = null;\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n const pageScreenshotOptions: PageScreenshotOptions = {\n animations: 'disabled',\n caret: 'initial',\n fullPage: false,\n scale: 'css',\n type: 'png',\n };\n const imageBuffer = await trackViewportOptions.page.screenshot(pageScreenshotOptions);\n const imageBase64 = imageBuffer.toString('base64');\n if (this._config.screenshotValidation.collectPageContent) {\n const pageContent = await trackViewportOptions.page.content();\n pageContentBase64 = Buffer.from(pageContent, 'utf-8').toString('base64');\n }\n const payload: CreateIntegrationStepPayload = CreateIntegrationStepPayloadSchema.parse({\n ...trackViewportOptions,\n imageBase64,\n pageContentBase64,\n });\n apolloTrackResult = await this._screenshotValidation.createIntegrationStep(payload);\n }\n return apolloTrackResult;\n }\n\n /**\n * Captures and tracks a viewport screenshot for validation.\n * @param TrackViewportOptions Parameters for image tracking.\n * @returns {ApolloTrackResult} The result of the tracking operation.\n */\n async trackViewport(trackViewportOptions: TrackViewportOptions): Promise<IntegrationStep> {\n if (this._config.screenshotValidation.screenshotValidationEnabled) {\n return await this._trackViewport(trackViewportOptions);\n }\n return null;\n }\n\n /**\n * Visual assert based on provided context, prompt (question) against an image.\n * Provide either imageBase64 or page object to take a screenshot at the current state.\n * @param VisualAssertOptions Parameters for visual assertion.\n * @returns {VisualAssert} The result of the visual assertion operation.\n */\n async visualAssert(visualAssertOptions: VisualAssertOptions): Promise<VisualAssert> {\n let imageBase64 = null;\n if (visualAssertOptions.imageBase64) {\n imageBase64 = visualAssertOptions.imageBase64;\n } else if (visualAssertOptions.page) {\n const imageBuffer = await visualAssertOptions.page.screenshot();\n imageBase64 = imageBuffer.toString('base64');\n }\n const payload: VisualAssertPayload = VisualAssertPayloadSchema.parse({\n imageBase64,\n prompt: visualAssertOptions.prompt,\n context: visualAssertOptions.context,\n });\n return await this._screenshotValidation.visualAssert(payload);\n }\n}\n"]}
|
|
@@ -3,16 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.logVersionMetadata = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const logVersionMetadata = () => {
|
|
6
|
-
let version = "4.24.
|
|
7
|
-
let hash = "
|
|
6
|
+
let version = "4.24.3"
|
|
7
|
+
let hash = "c84faff7087b54769a978877d85ff6ab0a669b37"
|
|
8
8
|
if (version === '__LOCAL__') {
|
|
9
9
|
version = process.env.npm_package_version || '__LOCAL__';
|
|
10
10
|
}
|
|
11
11
|
if (hash === '__LOCAL__') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
try {
|
|
13
|
+
hash = (0, child_process_1.execSync)('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
14
|
+
.toString()
|
|
15
|
+
.trim();
|
|
16
|
+
const status = (0, child_process_1.execSync)('git status --porcelain', { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
17
|
+
.toString()
|
|
18
|
+
.trim();
|
|
19
|
+
if (status) {
|
|
20
|
+
hash = `${hash}: ${status.split('\n').join(', ')}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
hash = '__LOCAL__';
|
|
16
25
|
}
|
|
17
26
|
}
|
|
18
27
|
console.log('info', `Initializing Wopee's Playwright integration: version(${version}), hash(${hash})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versionMetadata.js","sourceRoot":"","sources":["../../../lib/shared/metadata/versionMetadata.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAElC,MAAM,kBAAkB,GAAG,GAAS,EAAE;IAC3C,IAAI,OAAO,GAAW,WAAW,CAAC;IAClC,IAAI,IAAI,GAAW,WAAW,CAAC;IAG/B,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,WAAW,CAAC;IAC3D,CAAC;
|
|
1
|
+
{"version":3,"file":"versionMetadata.js","sourceRoot":"","sources":["../../../lib/shared/metadata/versionMetadata.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAElC,MAAM,kBAAkB,GAAG,GAAS,EAAE;IAC3C,IAAI,OAAO,GAAW,WAAW,CAAC;IAClC,IAAI,IAAI,GAAW,WAAW,CAAC;IAG/B,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,WAAW,CAAC;IAC3D,CAAC;IAMD,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,IAAI,GAAG,IAAA,wBAAQ,EAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;iBAC3E,QAAQ,EAAE;iBACV,IAAI,EAAE,CAAC;YACV,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;iBACvF,QAAQ,EAAE;iBACV,IAAI,EAAE,CAAC;YACV,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,GAAG,GAAG,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,CAAC;QACH,CAAC;QAAC,WAAM,CAAC;YACP,IAAI,GAAG,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,wDAAwD,OAAO,WAAW,IAAI,GAAG,CAAC,CAAC;AACzG,CAAC,CAAC;AA9BW,QAAA,kBAAkB,sBA8B7B","sourcesContent":["import { execSync } from 'child_process';\n\nexport const logVersionMetadata = (): void => {\n let version: string = '__LOCAL__';\n let hash: string = '__LOCAL__';\n\n // If version is not \"__LOCAL__,\" get it from npm package\n if (version === '__LOCAL__') {\n version = process.env.npm_package_version || '__LOCAL__';\n }\n\n // If hash is not \"__LOCAL__,\" get it from Git. Guarded because this runs\n // first in the Wopee constructor, and an unpacked template is not a git\n // checkout — an unhandled git error here would mask the real configuration\n // problem the user needs to see.\n if (hash === '__LOCAL__') {\n try {\n hash = execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'] })\n .toString()\n .trim();\n const status = execSync('git status --porcelain', { stdio: ['ignore', 'pipe', 'ignore'] })\n .toString()\n .trim();\n if (status) {\n hash = `${hash}: ${status.split('\\n').join(', ')}`;\n }\n } catch {\n hash = '__LOCAL__';\n }\n }\n\n console.log('info', `Initializing Wopee's Playwright integration: version(${version}), hash(${hash})`);\n};\n"]}
|
|
@@ -2,8 +2,14 @@ import type { Reporter, TestCase, TestResult } from '@playwright/test/reporter';
|
|
|
2
2
|
import 'dotenv/config';
|
|
3
3
|
export declare class WopeeReporter implements Reporter {
|
|
4
4
|
private uploadQueue;
|
|
5
|
+
private suiteUuids;
|
|
6
|
+
private configWarned;
|
|
5
7
|
constructor();
|
|
8
|
+
private env;
|
|
9
|
+
private hasCredentials;
|
|
6
10
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
7
11
|
onExit(): Promise<void>;
|
|
12
|
+
private apiRequestConfig;
|
|
13
|
+
private stopSuites;
|
|
8
14
|
printsToStdio(): boolean;
|
|
9
15
|
}
|
|
@@ -19,16 +19,40 @@ const wopeeReporter_interface_js_1 = require("./types/wopeeReporter.interface.js
|
|
|
19
19
|
const axios_1 = __importDefault(require("axios"));
|
|
20
20
|
require("dotenv/config");
|
|
21
21
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
22
|
-
const { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID } = process.env;
|
|
23
22
|
class WopeeReporter {
|
|
24
23
|
constructor() {
|
|
25
24
|
this.uploadQueue = [];
|
|
25
|
+
this.suiteUuids = new Set();
|
|
26
|
+
this.configWarned = false;
|
|
27
|
+
}
|
|
28
|
+
env() {
|
|
29
|
+
const { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID } = process.env;
|
|
30
|
+
return { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID };
|
|
31
|
+
}
|
|
32
|
+
hasCredentials() {
|
|
33
|
+
const { WOPEE_API_KEY, WOPEE_PROJECT_UUID } = this.env();
|
|
34
|
+
const missing = [
|
|
35
|
+
...((WOPEE_API_KEY === null || WOPEE_API_KEY === void 0 ? void 0 : WOPEE_API_KEY.trim()) ? [] : ['WOPEE_API_KEY']),
|
|
36
|
+
...((WOPEE_PROJECT_UUID === null || WOPEE_PROJECT_UUID === void 0 ? void 0 : WOPEE_PROJECT_UUID.trim()) ? [] : ['WOPEE_PROJECT_UUID']),
|
|
37
|
+
];
|
|
38
|
+
if (missing.length === 0) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (!this.configWarned) {
|
|
42
|
+
this.configWarned = true;
|
|
43
|
+
console.error(`[WOPEE_REPORTER_ERROR]: Wopee reporter is disabled — ${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} not set. Get credentials from Project Settings → API Keys at https://cmd.wopee.io and set them in your shell, a .env file, or CI secrets. Test results will not be uploaded.`);
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
26
46
|
}
|
|
27
47
|
onTestEnd(test, result) {
|
|
28
|
-
var _a, _b;
|
|
48
|
+
var _a, _b, _c, _d;
|
|
29
49
|
const testRunId = (0, helpers_1.generateTestRunId)();
|
|
30
|
-
const
|
|
31
|
-
|
|
50
|
+
const wopeeSuiteUuid = (_b = (_a = result.attachments.find((a) => (a === null || a === void 0 ? void 0 : a.name) === 'wopee-suite-uuid')) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.toString('utf-8');
|
|
51
|
+
if (wopeeSuiteUuid) {
|
|
52
|
+
this.suiteUuids.add(wopeeSuiteUuid);
|
|
53
|
+
}
|
|
54
|
+
const wopeeScenarioUuid = (_d = (_c = result.attachments
|
|
55
|
+
.find((a) => (a === null || a === void 0 ? void 0 : a.name) === 'wopee-scenario-uuid')) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.toString('utf-8');
|
|
32
56
|
const failedStep = [...result.steps].reverse().find((step) => step.error);
|
|
33
57
|
const createStepId = (step) => `${step.title}-${step.category}-${step.startTime}`;
|
|
34
58
|
const failedStepId = failedStep ? createStepId(failedStep) : null;
|
|
@@ -66,6 +90,9 @@ class WopeeReporter {
|
|
|
66
90
|
if (!wopeeScenarioUuid) {
|
|
67
91
|
return console.error('[WOPEE_REPORTER_ERROR]: Scenario UUID is required, please propagate "testInfo" as second argument in "test.beforeEach" hook and pass it to "wopee.startScenario("scenarioTitle", testInfo)" method as second argument if you want to use features of Wopee reporter');
|
|
68
92
|
}
|
|
93
|
+
if (!this.hasCredentials()) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
69
96
|
const steps = result.steps.map((step, index) => ({
|
|
70
97
|
testRunId,
|
|
71
98
|
number: index + 1,
|
|
@@ -86,7 +113,7 @@ class WopeeReporter {
|
|
|
86
113
|
extendIntegrationScenario(input: $input)
|
|
87
114
|
}`;
|
|
88
115
|
const extendIntegrationScenarioPayload = {
|
|
89
|
-
input: Object.assign(Object.assign({ projectUuid: WOPEE_PROJECT_UUID, scenarioUuid: wopeeScenarioUuid, pwSteps: JSON.stringify(steps, helpers_1.replacer) }, (process.env.GITHUB_RUN_ID && {
|
|
116
|
+
input: Object.assign(Object.assign({ projectUuid: this.env().WOPEE_PROJECT_UUID, scenarioUuid: wopeeScenarioUuid, pwSteps: JSON.stringify(steps, helpers_1.replacer) }, (process.env.GITHUB_RUN_ID && {
|
|
90
117
|
githubRunId: process.env.GITHUB_RUN_ID,
|
|
91
118
|
})), (process.env.GITHUB_RUN_ATTEMPT && {
|
|
92
119
|
githubRunAttempt: Number(process.env.GITHUB_RUN_ATTEMPT),
|
|
@@ -96,11 +123,7 @@ class WopeeReporter {
|
|
|
96
123
|
const uploadPromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
97
124
|
var _a, _b;
|
|
98
125
|
try {
|
|
99
|
-
const apiUrl
|
|
100
|
-
const headers = {
|
|
101
|
-
api_key: WOPEE_API_KEY,
|
|
102
|
-
};
|
|
103
|
-
const config = (0, axios_config_js_1.buildAxiosConfig)(apiUrl, headers);
|
|
126
|
+
const { apiUrl, config } = this.apiRequestConfig();
|
|
104
127
|
const response = yield axios_1.default.post(apiUrl, { query, variables }, config);
|
|
105
128
|
resolve(response);
|
|
106
129
|
}
|
|
@@ -110,7 +133,7 @@ class WopeeReporter {
|
|
|
110
133
|
const errorData = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
111
134
|
const errorMessage = error.message;
|
|
112
135
|
console.error('[WOPEE_REPORTER_ERROR]', errorMessage, errorData);
|
|
113
|
-
reject(new Error(`API request failed with status code: ${status}.`));
|
|
136
|
+
return reject(new Error(`API request failed with status code: ${status}.`));
|
|
114
137
|
}
|
|
115
138
|
reject(new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error === null || error === void 0 ? void 0 : error.message}`));
|
|
116
139
|
}
|
|
@@ -132,6 +155,45 @@ class WopeeReporter {
|
|
|
132
155
|
this.uploadQueue = [];
|
|
133
156
|
}
|
|
134
157
|
}
|
|
158
|
+
yield this.stopSuites();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
apiRequestConfig() {
|
|
162
|
+
const { WOPEE_API_KEY, WOPEE_API_URL } = this.env();
|
|
163
|
+
const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';
|
|
164
|
+
const headers = {
|
|
165
|
+
api_key: WOPEE_API_KEY,
|
|
166
|
+
};
|
|
167
|
+
return { apiUrl, config: (0, axios_config_js_1.buildAxiosConfig)(apiUrl, headers) };
|
|
168
|
+
}
|
|
169
|
+
stopSuites() {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
if (this.suiteUuids.size > 0 && !this.hasCredentials()) {
|
|
173
|
+
this.suiteUuids.clear();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const query = `
|
|
177
|
+
mutation StopIntegrationSuite($suiteUuid: ID!) {
|
|
178
|
+
stopIntegrationSuite(suiteUuid: $suiteUuid) { uuid suiteRunningStatus }
|
|
179
|
+
}`;
|
|
180
|
+
for (const suiteUuid of this.suiteUuids) {
|
|
181
|
+
try {
|
|
182
|
+
const { apiUrl, config } = this.apiRequestConfig();
|
|
183
|
+
const response = yield axios_1.default.post(apiUrl, { query, variables: { suiteUuid } }, config);
|
|
184
|
+
const errors = (_a = response.data) === null || _a === void 0 ? void 0 : _a.errors;
|
|
185
|
+
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
186
|
+
console.error(`[WOPEE_REPORTER_ERROR] Failed to stop suite ${suiteUuid}:`, (_b = errors[0]) === null || _b === void 0 ? void 0 : _b.message);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log(`Suite(uuid=${suiteUuid}) is stopped.`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error(`[WOPEE_REPORTER_ERROR] Failed to stop suite ${suiteUuid}: ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
this.suiteUuids.clear();
|
|
135
197
|
});
|
|
136
198
|
}
|
|
137
199
|
printsToStdio() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wopeeReporter.js","sourceRoot":"","sources":["../../../lib/tools/wopee-reporter/wopeeReporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAsF;AACtF,+DAA6D;AAC7D,mFAG4C;AAE5C,kDAA0B;AAC1B,yBAAuB;AACvB,sDAAyB;AAEzB,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEzE,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,IAAc,EAAE,MAAkB;;QAC1C,MAAM,SAAS,GAAG,IAAA,2BAAiB,GAAE,CAAC;QAEtC,MAAM,iBAAiB,GAAG,MAAA,MAAA,MAAM,CAAC,WAAW;aACzC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,IAAI,MAAK,qBAAqB,CAAC,0CAC7C,IAAI,0CAAE,QAAQ,CAAC,OA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AM,MAAM,GAAG,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,CAAC;oBACtC,MAAM,SAAS,GAAG,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,CAAC;oBACvC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC;oBACnC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;oBACjE,MAAM,CAAC,IAAI,KAAK,CAAC,wCAAwC,MAAM,GAAG,CAAC,CAAC,CAAC;gBACvE,CAAC;gBACD,MAAM,CAAC,IAAI,KAAK,CAAC,qEAAqE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YAC3G,CAAC;QACH,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;IAEK,MAAM;;YACV,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,WAAW,CAAC,MAAM,4BAA4B,CAAC,CAAC;gBAC9E,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBACpC,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;gBACzD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;gBACxD,CAAC;wBAAS,CAAC;oBACT,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxID,sCAwIC","sourcesContent":["import { generateTestRunId, parseError, parseNestedSteps, replacer } from './helpers';\nimport { buildAxiosConfig } from './helpers/axios-config.js';\nimport {\n ExtendIntegrationScenarioPayload,\n ExtendIntegrationScenarioPayloadSchema,\n} from './types/wopeeReporter.interface.js';\nimport type { Reporter, TestCase, TestResult } from '@playwright/test/reporter';\nimport axios from 'axios';\nimport 'dotenv/config';\nimport fs from 'node:fs';\n\nconst { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID } = process.env;\n\nexport class WopeeReporter implements Reporter {\n private uploadQueue: Promise<any>[];\n\n constructor() {\n this.uploadQueue = [];\n }\n\n onTestEnd(test: TestCase, result: TestResult) {\n const testRunId = generateTestRunId();\n\n const wopeeScenarioUuid = result.attachments\n .find((a) => a?.name === 'wopee-scenario-uuid')\n ?.body?.toString('utf-8');\n\n const failedStep = [...result.steps].reverse().find((step) => step.error);\n\n const createStepId = (step: any) => `${step.title}-${step.category}-${step.startTime}`;\n const failedStepId = failedStep ? createStepId(failedStep) : null;\n\n let screenshotBase64: string | null = null;\n let videoBase64: string | null = null;\n\n for (const attachment of result.attachments) {\n if (attachment.name === 'screenshot' && attachment.contentType === 'image/png') {\n const filePath = attachment.path;\n if (filePath) {\n try {\n const imageBuffer = fs.readFileSync(filePath);\n screenshotBase64 = imageBuffer.toString('base64');\n } catch (error) {\n console.error('Error reading screenshot:', error);\n }\n }\n }\n\n if (\n attachment.name === 'video' &&\n (attachment.contentType === 'video/webm' ||\n attachment.contentType === 'video/mp4' ||\n attachment.contentType === 'video/avi')\n ) {\n const filePath = attachment.path;\n if (filePath) {\n try {\n const videoBuffer = fs.readFileSync(filePath);\n videoBase64 = videoBuffer.toString('base64');\n } catch (error) {\n console.error('Error reading video:', error);\n }\n }\n }\n }\n\n if (!wopeeScenarioUuid) {\n return console.error(\n '[WOPEE_REPORTER_ERROR]: Scenario UUID is required, please propagate \"testInfo\" as second argument in \"test.beforeEach\" hook and pass it to \"wopee.startScenario(\"scenarioTitle\", testInfo)\" method as second argument if you want to use features of Wopee reporter',\n );\n }\n\n const steps = result.steps.map((step, index) => ({\n testRunId,\n number: index + 1,\n testTitle: test.title,\n title: step.title,\n status: step.error ? 'failed' : 'passed',\n error: step.error ? parseError(step.error) : step.error,\n category: step.category,\n location: step.location,\n duration: step.duration,\n startTime: step.startTime,\n steps: parseNestedSteps(step.steps),\n screenshotBase64: createStepId(step) === failedStepId ? screenshotBase64 : null,\n videoBase64: createStepId(step) === failedStepId ? videoBase64 : null,\n }));\n\n const query = `\n mutation ExtendIntegrationScenario($input: ExtendIntegrationScenarioInput!) {\n extendIntegrationScenario(input: $input)\n }`;\n\n const extendIntegrationScenarioPayload: ExtendIntegrationScenarioPayload = {\n input: {\n projectUuid: WOPEE_PROJECT_UUID,\n scenarioUuid: wopeeScenarioUuid,\n pwSteps: JSON.stringify(steps, replacer),\n ...(process.env.GITHUB_RUN_ID && {\n githubRunId: process.env.GITHUB_RUN_ID,\n }),\n ...(process.env.GITHUB_RUN_ATTEMPT && {\n githubRunAttempt: Number(process.env.GITHUB_RUN_ATTEMPT),\n }),\n },\n };\n const variables = ExtendIntegrationScenarioPayloadSchema.parse(extendIntegrationScenarioPayload);\n\n const uploadPromise = new Promise(async (resolve, reject) => {\n try {\n const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';\n const headers = {\n api_key: WOPEE_API_KEY,\n };\n const config = buildAxiosConfig(apiUrl, headers);\n const response = await axios.post(apiUrl, { query, variables }, config);\n resolve(response);\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const status = error.response?.status;\n const errorData = error.response?.data;\n const errorMessage = error.message;\n console.error('[WOPEE_REPORTER_ERROR]', errorMessage, errorData);\n reject(new Error(`API request failed with status code: ${status}.`));\n }\n reject(new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error?.message}`));\n }\n });\n\n this.uploadQueue.push(uploadPromise);\n }\n\n async onExit(): Promise<void> {\n if (this.uploadQueue.length > 0) {\n console.log(`Uploading ${this.uploadQueue.length} remaining test results...`);\n try {\n await Promise.all(this.uploadQueue);\n console.log('Successfully uploaded all test results.');\n } catch (error) {\n console.error('Error uploading test results:', error);\n } finally {\n this.uploadQueue = [];\n }\n }\n }\n\n printsToStdio(): boolean {\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wopeeReporter.js","sourceRoot":"","sources":["../../../lib/tools/wopee-reporter/wopeeReporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAsF;AACtF,+DAA6D;AAC7D,mFAG4C;AAE5C,kDAA0B;AAC1B,yBAAuB;AACvB,sDAAyB;AAEzB,MAAa,aAAa;IAKxB;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;IAMO,GAAG;QACT,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QACzE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC;IAC9D,CAAC;IAOO,cAAc;QACpB,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzD,MAAM,OAAO,GAAG;YACd,GAAG,CAAC,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,EAAE,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;YACnD,GAAG,CAAC,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,IAAI,EAAE,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;SAC9D,CAAC;QAEF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,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CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,MAAM,KAAK,GAAG;;;MAGZ,CAAC;YAEH,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACxC,IAAI,CAAC;oBACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACnD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;oBACvF,MAAM,MAAM,GAAG,MAAA,QAAQ,CAAC,IAAI,0CAAE,MAAM,CAAC;oBACrC,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;wBACnB,OAAO,CAAC,KAAK,CAAC,+CAA+C,SAAS,GAAG,EAAE,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,OAAO,CAAC,CAAC;oBACjG,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,GAAG,CAAC,cAAc,SAAS,eAAe,CAAC,CAAC;oBACtD,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,OAAO,CAAC,KAAK,CAAC,+CAA+C,SAAS,KAAK,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAC;gBAC/F,CAAC;YACH,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;KAAA;IAED,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAhOD,sCAgOC","sourcesContent":["import { generateTestRunId, parseError, parseNestedSteps, replacer } from './helpers';\nimport { buildAxiosConfig } from './helpers/axios-config.js';\nimport {\n ExtendIntegrationScenarioPayload,\n ExtendIntegrationScenarioPayloadSchema,\n} from './types/wopeeReporter.interface.js';\nimport type { Reporter, TestCase, TestResult } from '@playwright/test/reporter';\nimport axios from 'axios';\nimport 'dotenv/config';\nimport fs from 'node:fs';\n\nexport class WopeeReporter implements Reporter {\n private uploadQueue: Promise<any>[];\n private suiteUuids: Set<string>;\n private configWarned: boolean;\n\n constructor() {\n this.uploadQueue = [];\n this.suiteUuids = new Set();\n this.configWarned = false;\n }\n\n /*\n Read lazily rather than at module load, so a playwright.config.ts that assigns\n process.env.WOPEE_* at runtime is picked up.\n */\n private env() {\n const { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID } = process.env;\n return { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID };\n }\n\n /*\n A reporter must never fail the run, so this warns and skips rather than\n throwing — otherwise an unauthenticated request is queued and its 401 is\n swallowed by onExit, leaving the user with silently missing results.\n */\n private hasCredentials(): boolean {\n const { WOPEE_API_KEY, WOPEE_PROJECT_UUID } = this.env();\n const missing = [\n ...(WOPEE_API_KEY?.trim() ? [] : ['WOPEE_API_KEY']),\n ...(WOPEE_PROJECT_UUID?.trim() ? [] : ['WOPEE_PROJECT_UUID']),\n ];\n\n if (missing.length === 0) {\n return true;\n }\n\n if (!this.configWarned) {\n this.configWarned = true;\n console.error(\n `[WOPEE_REPORTER_ERROR]: Wopee reporter is disabled — ${missing.join(' and ')} ${\n missing.length > 1 ? 'are' : 'is'\n } not set. Get credentials from Project Settings → API Keys at https://cmd.wopee.io and set them in your shell, a .env file, or CI secrets. Test results will not be uploaded.`,\n );\n }\n return false;\n }\n\n onTestEnd(test: TestCase, result: TestResult) {\n const testRunId = generateTestRunId();\n\n const wopeeSuiteUuid = result.attachments.find((a) => a?.name === 'wopee-suite-uuid')?.body?.toString('utf-8');\n if (wopeeSuiteUuid) {\n this.suiteUuids.add(wopeeSuiteUuid);\n }\n\n const wopeeScenarioUuid = result.attachments\n .find((a) => a?.name === 'wopee-scenario-uuid')\n ?.body?.toString('utf-8');\n\n const failedStep = [...result.steps].reverse().find((step) => step.error);\n\n const createStepId = (step: any) => `${step.title}-${step.category}-${step.startTime}`;\n const failedStepId = failedStep ? createStepId(failedStep) : null;\n\n let screenshotBase64: string | null = null;\n let videoBase64: string | null = null;\n\n for (const attachment of result.attachments) {\n if (attachment.name === 'screenshot' && attachment.contentType === 'image/png') {\n const filePath = attachment.path;\n if (filePath) {\n try {\n const imageBuffer = fs.readFileSync(filePath);\n screenshotBase64 = imageBuffer.toString('base64');\n } catch (error) {\n console.error('Error reading screenshot:', error);\n }\n }\n }\n\n if (\n attachment.name === 'video' &&\n (attachment.contentType === 'video/webm' ||\n attachment.contentType === 'video/mp4' ||\n attachment.contentType === 'video/avi')\n ) {\n const filePath = attachment.path;\n if (filePath) {\n try {\n const videoBuffer = fs.readFileSync(filePath);\n videoBase64 = videoBuffer.toString('base64');\n } catch (error) {\n console.error('Error reading video:', error);\n }\n }\n }\n }\n\n if (!wopeeScenarioUuid) {\n return console.error(\n '[WOPEE_REPORTER_ERROR]: Scenario UUID is required, please propagate \"testInfo\" as second argument in \"test.beforeEach\" hook and pass it to \"wopee.startScenario(\"scenarioTitle\", testInfo)\" method as second argument if you want to use features of Wopee reporter',\n );\n }\n\n if (!this.hasCredentials()) {\n return;\n }\n\n const steps = result.steps.map((step, index) => ({\n testRunId,\n number: index + 1,\n testTitle: test.title,\n title: step.title,\n status: step.error ? 'failed' : 'passed',\n error: step.error ? parseError(step.error) : step.error,\n category: step.category,\n location: step.location,\n duration: step.duration,\n startTime: step.startTime,\n steps: parseNestedSteps(step.steps),\n screenshotBase64: createStepId(step) === failedStepId ? screenshotBase64 : null,\n videoBase64: createStepId(step) === failedStepId ? videoBase64 : null,\n }));\n\n const query = `\n mutation ExtendIntegrationScenario($input: ExtendIntegrationScenarioInput!) {\n extendIntegrationScenario(input: $input)\n }`;\n\n const extendIntegrationScenarioPayload: ExtendIntegrationScenarioPayload = {\n input: {\n projectUuid: this.env().WOPEE_PROJECT_UUID,\n scenarioUuid: wopeeScenarioUuid,\n pwSteps: JSON.stringify(steps, replacer),\n ...(process.env.GITHUB_RUN_ID && {\n githubRunId: process.env.GITHUB_RUN_ID,\n }),\n ...(process.env.GITHUB_RUN_ATTEMPT && {\n githubRunAttempt: Number(process.env.GITHUB_RUN_ATTEMPT),\n }),\n },\n };\n const variables = ExtendIntegrationScenarioPayloadSchema.parse(extendIntegrationScenarioPayload);\n\n const uploadPromise = new Promise(async (resolve, reject) => {\n try {\n const { apiUrl, config } = this.apiRequestConfig();\n const response = await axios.post(apiUrl, { query, variables }, config);\n resolve(response);\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const status = error.response?.status;\n const errorData = error.response?.data;\n const errorMessage = error.message;\n console.error('[WOPEE_REPORTER_ERROR]', errorMessage, errorData);\n return reject(new Error(`API request failed with status code: ${status}.`));\n }\n reject(new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error?.message}`));\n }\n });\n\n this.uploadQueue.push(uploadPromise);\n }\n\n async onExit(): Promise<void> {\n if (this.uploadQueue.length > 0) {\n console.log(`Uploading ${this.uploadQueue.length} remaining test results...`);\n try {\n await Promise.all(this.uploadQueue);\n console.log('Successfully uploaded all test results.');\n } catch (error) {\n console.error('Error uploading test results:', error);\n } finally {\n this.uploadQueue = [];\n }\n }\n\n await this.stopSuites();\n }\n\n private apiRequestConfig() {\n const { WOPEE_API_KEY, WOPEE_API_URL } = this.env();\n const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';\n const headers = {\n api_key: WOPEE_API_KEY,\n };\n return { apiUrl, config: buildAxiosConfig(apiUrl, headers) };\n }\n\n // Teardown is best-effort: a failed stop must never fail the run — suites are also\n // finished lazily by the API when left IDLE.\n private async stopSuites(): Promise<void> {\n // Without credentials this would fire unauthenticated requests whose 401s\n // contradict the \"results will not be uploaded\" warning already logged.\n if (this.suiteUuids.size > 0 && !this.hasCredentials()) {\n this.suiteUuids.clear();\n return;\n }\n\n const query = `\n mutation StopIntegrationSuite($suiteUuid: ID!) {\n stopIntegrationSuite(suiteUuid: $suiteUuid) { uuid suiteRunningStatus }\n }`;\n\n for (const suiteUuid of this.suiteUuids) {\n try {\n const { apiUrl, config } = this.apiRequestConfig();\n const response = await axios.post(apiUrl, { query, variables: { suiteUuid } }, config);\n const errors = response.data?.errors;\n if (errors?.length) {\n console.error(`[WOPEE_REPORTER_ERROR] Failed to stop suite ${suiteUuid}:`, errors[0]?.message);\n } else {\n console.log(`Suite(uuid=${suiteUuid}) is stopped.`);\n }\n } catch (error: any) {\n console.error(`[WOPEE_REPORTER_ERROR] Failed to stop suite ${suiteUuid}: ${error?.message}`);\n }\n }\n this.suiteUuids.clear();\n }\n\n printsToStdio(): boolean {\n return false;\n }\n}\n"]}
|