@wopee-io/wopee.pw 4.19.0 → 4.21.0

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.
@@ -8,6 +8,10 @@ on:
8
8
  branches:
9
9
  - 'dev'
10
10
 
11
+ permissions:
12
+ contents: read
13
+ packages: read
14
+
11
15
  jobs:
12
16
  npm-clean-install:
13
17
  runs-on: builder
@@ -21,7 +25,7 @@ jobs:
21
25
  - name: Install
22
26
  uses: ./.github/actions/npm_clean_install
23
27
  with:
24
- npm-token: ${{ secrets.CI_CD }}
28
+ npm-token: ${{ github.token }}
25
29
 
26
30
  static-check:
27
31
  needs: [npm-clean-install]
@@ -37,7 +41,7 @@ jobs:
37
41
  - name: Install
38
42
  uses: ./.github/actions/npm_clean_install
39
43
  with:
40
- npm-token: ${{ secrets.CI_CD }}
44
+ npm-token: ${{ github.token }}
41
45
 
42
46
  - name: Commitlint
43
47
  if: ${{ always() }}
@@ -71,7 +75,7 @@ jobs:
71
75
  - name: Install
72
76
  uses: ./.github/actions/npm_clean_install
73
77
  with:
74
- npm-token: ${{ secrets.CI_CD }}
78
+ npm-token: ${{ github.token }}
75
79
 
76
80
  - name: Unit tests
77
81
  shell: bash
@@ -90,7 +94,7 @@ jobs:
90
94
  - name: Install
91
95
  uses: ./.github/actions/npm_clean_install
92
96
  with:
93
- npm-token: ${{ secrets.CI_CD }}
97
+ npm-token: ${{ github.token }}
94
98
 
95
99
  - name: Build
96
100
  run: make build
@@ -108,7 +112,7 @@ jobs:
108
112
  - name: Install
109
113
  uses: ./.github/actions/npm_clean_install
110
114
  with:
111
- npm-token: ${{ secrets.CI_CD }}
115
+ npm-token: ${{ github.token }}
112
116
 
113
117
  - name: E2E test
114
118
  env:
@@ -128,21 +132,24 @@ jobs:
128
132
  needs: [before-build-test, after-build-test]
129
133
  if: github.event_name == 'push'
130
134
  runs-on: builder
135
+ permissions:
136
+ contents: write
137
+ packages: write
131
138
 
132
139
  steps:
133
140
  - name: Check-out
134
141
  uses: actions/checkout@v4
135
142
  with:
136
- fetch-depth: 1
143
+ fetch-depth: 0
137
144
 
138
145
  - name: Install
139
146
  uses: ./.github/actions/npm_clean_install
140
147
  with:
141
- npm-token: ${{ secrets.CI_CD }}
148
+ npm-token: ${{ github.token }}
142
149
 
143
150
  - name: Release
144
151
  shell: bash
145
152
  env:
146
- GH_TOKEN: ${{secrets.CI_CD}}
147
- NPM_TOKEN: ${{secrets.CI_CD}}
153
+ GH_TOKEN: ${{ github.token }}
154
+ NPM_TOKEN: ${{ github.token }}
148
155
  run: make release
@@ -3,8 +3,8 @@ 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.19.0"
7
- let hash = "3254881359949207b8d4e3f74cd24e852aa4ad19"
6
+ let version = "4.21.0"
7
+ let hash = "ce28566796ff4cc5a602ae2cfc1fe10643261c21"
8
8
  if (version === '__LOCAL__') {
9
9
  version = process.env.npm_package_version || '__LOCAL__';
10
10
  }
@@ -0,0 +1,3 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import 'dotenv/config';
3
+ export declare function buildAxiosConfig(url: string, headers: Record<string, string>): AxiosRequestConfig;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAxiosConfig = void 0;
4
+ require("dotenv/config");
5
+ const http_proxy_agent_1 = require("http-proxy-agent");
6
+ const https_proxy_agent_1 = require("https-proxy-agent");
7
+ const proxy_from_env_1 = require("proxy-from-env");
8
+ function isIpv4(value) {
9
+ const parts = value.split('.');
10
+ if (parts.length !== 4)
11
+ return false;
12
+ return parts.every((part) => {
13
+ const num = Number(part);
14
+ return Number.isInteger(num) && num >= 0 && num <= 255;
15
+ });
16
+ }
17
+ function ipv4ToInt(value) {
18
+ return value
19
+ .split('.')
20
+ .map((part) => Number(part))
21
+ .reduce((acc, part) => (acc << 8) + part, 0);
22
+ }
23
+ function isCidrMatch(hostname, cidr) {
24
+ const [range, bitsString] = cidr.split('/');
25
+ if (!range || !bitsString)
26
+ return false;
27
+ if (!isIpv4(hostname) || !isIpv4(range))
28
+ return false;
29
+ const bits = Number(bitsString);
30
+ if (!Number.isInteger(bits) || bits < 0 || bits > 32)
31
+ return false;
32
+ const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;
33
+ return (ipv4ToInt(hostname) & mask) === (ipv4ToInt(range) & mask);
34
+ }
35
+ function splitHostPort(entry) {
36
+ const lastColon = entry.lastIndexOf(':');
37
+ if (lastColon > -1 && entry.indexOf(':') === lastColon) {
38
+ const host = entry.slice(0, lastColon);
39
+ const port = entry.slice(lastColon + 1);
40
+ if (host && port) {
41
+ return { host, port };
42
+ }
43
+ }
44
+ return { host: entry, port: '' };
45
+ }
46
+ function isNoProxyMatch(url, noProxy) {
47
+ if (!noProxy)
48
+ return false;
49
+ let hostname = '';
50
+ let port = '';
51
+ try {
52
+ const parsed = new URL(url);
53
+ hostname = parsed.hostname.toLowerCase();
54
+ port = parsed.port;
55
+ }
56
+ catch (_a) {
57
+ return false;
58
+ }
59
+ const entries = noProxy
60
+ .split(',')
61
+ .map((entry) => entry.trim())
62
+ .filter(Boolean);
63
+ for (const entry of entries) {
64
+ if (entry === '*')
65
+ return true;
66
+ if (entry.includes('/')) {
67
+ if (isCidrMatch(hostname, entry))
68
+ return true;
69
+ continue;
70
+ }
71
+ const { host, port: entryPort } = splitHostPort(entry.toLowerCase());
72
+ if (entryPort && port && entryPort !== port) {
73
+ continue;
74
+ }
75
+ if (host.startsWith('.')) {
76
+ if (hostname.endsWith(host))
77
+ return true;
78
+ continue;
79
+ }
80
+ if (hostname === host)
81
+ return true;
82
+ if (hostname.endsWith(`.${host}`))
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ function getProxyDecision(url) {
88
+ const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'] || '';
89
+ if (!url) {
90
+ return { proxyUrl: null, noProxy };
91
+ }
92
+ if (isNoProxyMatch(url, noProxy)) {
93
+ return { proxyUrl: null, noProxy };
94
+ }
95
+ try {
96
+ const proxyUrl = (0, proxy_from_env_1.getProxyForUrl)(url);
97
+ return { proxyUrl: proxyUrl || null, noProxy };
98
+ }
99
+ catch (_a) {
100
+ return { proxyUrl: null, noProxy };
101
+ }
102
+ }
103
+ function buildAxiosConfig(url, headers) {
104
+ const config = {
105
+ headers,
106
+ proxy: false,
107
+ };
108
+ const { proxyUrl } = getProxyDecision(url);
109
+ if (!proxyUrl) {
110
+ return config;
111
+ }
112
+ if (url.startsWith('https:')) {
113
+ config.httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
114
+ }
115
+ else {
116
+ config.httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl);
117
+ }
118
+ return config;
119
+ }
120
+ exports.buildAxiosConfig = buildAxiosConfig;
121
+ //# sourceMappingURL=axios-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios-config.js","sourceRoot":"","sources":["../../../../lib/tools/wopee-reporter/helpers/axios-config.ts"],"names":[],"mappings":";;;AACA,yBAAuB;AACvB,uDAAkD;AAClD,yDAAoD;AACpD,mDAAgD;AAOhD,SAAS,MAAM,CAAC,KAAa;IAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,OA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AAM,GAAuB;QACjC,OAAO;QACP,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,CAAC,UAAU,GAAG,IAAI,mCAAe,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,SAAS,GAAG,IAAI,iCAAc,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,4CAkBC","sourcesContent":["import type { AxiosRequestConfig } from 'axios';\nimport 'dotenv/config';\nimport { HttpProxyAgent } from 'http-proxy-agent';\nimport { HttpsProxyAgent } from 'https-proxy-agent';\nimport { getProxyForUrl } from 'proxy-from-env';\n\ntype ProxyDecision = {\n proxyUrl: string | null;\n noProxy: string;\n};\n\nfunction isIpv4(value: string) {\n const parts = value.split('.');\n if (parts.length !== 4) return false;\n return parts.every((part) => {\n const num = Number(part);\n return Number.isInteger(num) && num >= 0 && num <= 255;\n });\n}\n\nfunction ipv4ToInt(value: string) {\n return value\n .split('.')\n .map((part) => Number(part))\n .reduce((acc, part) => (acc << 8) + part, 0);\n}\n\nfunction isCidrMatch(hostname: string, cidr: string) {\n const [range, bitsString] = cidr.split('/');\n if (!range || !bitsString) return false;\n if (!isIpv4(hostname) || !isIpv4(range)) return false;\n\n const bits = Number(bitsString);\n if (!Number.isInteger(bits) || bits < 0 || bits > 32) return false;\n\n const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;\n return (ipv4ToInt(hostname) & mask) === (ipv4ToInt(range) & mask);\n}\n\nfunction splitHostPort(entry: string) {\n const lastColon = entry.lastIndexOf(':');\n if (lastColon > -1 && entry.indexOf(':') === lastColon) {\n const host = entry.slice(0, lastColon);\n const port = entry.slice(lastColon + 1);\n if (host && port) {\n return { host, port };\n }\n }\n return { host: entry, port: '' };\n}\n\nfunction isNoProxyMatch(url: string, noProxy: string) {\n if (!noProxy) return false;\n let hostname = '';\n let port = '';\n try {\n const parsed = new URL(url);\n hostname = parsed.hostname.toLowerCase();\n port = parsed.port;\n } catch {\n return false;\n }\n\n const entries = noProxy\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean);\n\n for (const entry of entries) {\n if (entry === '*') return true;\n\n if (entry.includes('/')) {\n if (isCidrMatch(hostname, entry)) return true;\n continue;\n }\n\n const { host, port: entryPort } = splitHostPort(entry.toLowerCase());\n if (entryPort && port && entryPort !== port) {\n continue;\n }\n\n if (host.startsWith('.')) {\n if (hostname.endsWith(host)) return true;\n continue;\n }\n\n if (hostname === host) return true;\n if (hostname.endsWith(`.${host}`)) return true;\n }\n\n return false;\n}\n\nfunction getProxyDecision(url: string): ProxyDecision {\n const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'] || '';\n\n if (!url) {\n return { proxyUrl: null, noProxy };\n }\n\n if (isNoProxyMatch(url, noProxy)) {\n return { proxyUrl: null, noProxy };\n }\n\n try {\n const proxyUrl = getProxyForUrl(url);\n return { proxyUrl: proxyUrl || null, noProxy };\n } catch {\n return { proxyUrl: null, noProxy };\n }\n}\n\nexport function buildAxiosConfig(url: string, headers: Record<string, string>): AxiosRequestConfig {\n const config: AxiosRequestConfig = {\n headers,\n proxy: false,\n };\n\n const { proxyUrl } = getProxyDecision(url);\n if (!proxyUrl) {\n return config;\n }\n\n if (url.startsWith('https:')) {\n config.httpsAgent = new HttpsProxyAgent(proxyUrl);\n } else {\n config.httpAgent = new HttpProxyAgent(proxyUrl);\n }\n\n return config;\n}\n"]}
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.WopeeReporter = void 0;
16
16
  const helpers_1 = require("./helpers");
17
+ const axios_config_js_1 = require("./helpers/axios-config.js");
17
18
  const wopeeReporter_interface_js_1 = require("./types/wopeeReporter.interface.js");
18
19
  const axios_1 = __importDefault(require("axios"));
19
20
  require("dotenv/config");
@@ -96,18 +97,19 @@ class WopeeReporter {
96
97
  var _c, _d;
97
98
  try {
98
99
  const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';
99
- const response = yield axios_1.default.post(apiUrl, { query, variables }, {
100
- headers: {
101
- api_key: WOPEE_API_KEY,
102
- },
103
- });
100
+ const headers = {
101
+ api_key: WOPEE_API_KEY,
102
+ };
103
+ const config = (0, axios_config_js_1.buildAxiosConfig)(apiUrl, headers);
104
+ const response = yield axios_1.default.post(apiUrl, { query, variables }, config);
104
105
  resolve(response);
105
106
  }
106
107
  catch (error) {
107
108
  if (axios_1.default.isAxiosError(error)) {
108
109
  const status = (_c = error.response) === null || _c === void 0 ? void 0 : _c.status;
109
110
  const errorData = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data;
110
- console.error('[WOPEE_REPORTER_ERROR]', errorData);
111
+ const errorMessage = error.message;
112
+ console.error('[WOPEE_REPORTER_ERROR]', errorMessage, errorData);
111
113
  reject(new Error(`API request failed with status code: ${status}.`));
112
114
  }
113
115
  reject(new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error === null || error === void 0 ? void 0 : error.message}`));
@@ -1 +1 @@
1
- {"version":3,"file":"wopeeReporter.js","sourceRoot":"","sources":["../../../lib/tools/wopee-reporter/wopeeReporter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAsF;AACtF,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,S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AAC,QAAQ,0CAAE,MAAM,CAAC;oBACtC,MAAM,SAAS,GAAG,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,CAAC;oBACvC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;oBACnD,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;AArID,sCAqIC","sourcesContent":["import { generateTestRunId, parseError, parseNestedSteps, replacer } from './helpers';\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 },\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 response = await axios.post(\n apiUrl,\n { query, variables },\n {\n headers: {\n api_key: WOPEE_API_KEY,\n },\n },\n );\n resolve(response);\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const status = error.response?.status;\n const errorData = error.response?.data;\n console.error('[WOPEE_REPORTER_ERROR]', 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,MAA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oBACT,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlID,sCAkIC","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 },\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"]}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ApolloAdapter = void 0;
7
7
  const core_1 = require("../../../core");
8
8
  const shared_1 = require("../../../shared");
9
+ const axios_config_1 = require("./axios-config");
9
10
  const factories_1 = require("./factories");
10
11
  const interface_1 = require("./interface");
11
12
  const mutations_1 = require("./mutations");
@@ -22,14 +23,15 @@ class ApolloAdapter extends core_1.ApiPort {
22
23
  }
23
24
  async _post(query, variables) {
24
25
  try {
25
- return await axios_1.default.post(this._config.apiUrl, { query, variables }, {
26
- headers: { api_key: this._config.apiKey },
27
- });
26
+ const headers = { api_key: this._config.apiKey };
27
+ const config = (0, axios_config_1.buildAxiosConfig)(this._config.apiUrl, headers);
28
+ return await axios_1.default.post(this._config.apiUrl, { query, variables }, config);
28
29
  }
29
30
  catch (error) {
30
31
  if (axios_1.default.isAxiosError(error)) {
31
32
  const status = error.response?.status;
32
- throw new shared_1.WopeeError(`API request failed with status code: ${status}.`);
33
+ const errorMessage = error.message;
34
+ throw new shared_1.WopeeError(`API request failed with status code: ${status}. ${errorMessage}`);
33
35
  }
34
36
  throw new Error('Unexpected error occurred during API call.');
35
37
  }
@@ -0,0 +1,4 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import 'dotenv/config';
3
+ export declare function buildAxiosConfig(url: string, headers: Record<string, string>): AxiosRequestConfig;
4
+ //# sourceMappingURL=axios-config.d.ts.map
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAxiosConfig = buildAxiosConfig;
4
+ require("dotenv/config");
5
+ const http_proxy_agent_1 = require("http-proxy-agent");
6
+ const https_proxy_agent_1 = require("https-proxy-agent");
7
+ const proxy_from_env_1 = require("proxy-from-env");
8
+ function isIpv4(value) {
9
+ const parts = value.split('.');
10
+ if (parts.length !== 4)
11
+ return false;
12
+ return parts.every((part) => {
13
+ const num = Number(part);
14
+ return Number.isInteger(num) && num >= 0 && num <= 255;
15
+ });
16
+ }
17
+ function ipv4ToInt(value) {
18
+ return value
19
+ .split('.')
20
+ .map((part) => Number(part))
21
+ .reduce((acc, part) => (acc << 8) + part, 0);
22
+ }
23
+ function isCidrMatch(hostname, cidr) {
24
+ const [range, bitsString] = cidr.split('/');
25
+ if (!range || !bitsString)
26
+ return false;
27
+ if (!isIpv4(hostname) || !isIpv4(range))
28
+ return false;
29
+ const bits = Number(bitsString);
30
+ if (!Number.isInteger(bits) || bits < 0 || bits > 32)
31
+ return false;
32
+ const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;
33
+ return (ipv4ToInt(hostname) & mask) === (ipv4ToInt(range) & mask);
34
+ }
35
+ function splitHostPort(entry) {
36
+ const lastColon = entry.lastIndexOf(':');
37
+ if (lastColon > -1 && entry.indexOf(':') === lastColon) {
38
+ const host = entry.slice(0, lastColon);
39
+ const port = entry.slice(lastColon + 1);
40
+ if (host && port) {
41
+ return { host, port };
42
+ }
43
+ }
44
+ return { host: entry, port: '' };
45
+ }
46
+ function isNoProxyMatch(url, noProxy) {
47
+ if (!noProxy)
48
+ return false;
49
+ let hostname = '';
50
+ let port = '';
51
+ try {
52
+ const parsed = new URL(url);
53
+ hostname = parsed.hostname.toLowerCase();
54
+ port = parsed.port;
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ const entries = noProxy
60
+ .split(',')
61
+ .map((entry) => entry.trim())
62
+ .filter(Boolean);
63
+ for (const entry of entries) {
64
+ if (entry === '*')
65
+ return true;
66
+ if (entry.includes('/')) {
67
+ if (isCidrMatch(hostname, entry))
68
+ return true;
69
+ continue;
70
+ }
71
+ const { host, port: entryPort } = splitHostPort(entry.toLowerCase());
72
+ if (entryPort && port && entryPort !== port) {
73
+ continue;
74
+ }
75
+ if (host.startsWith('.')) {
76
+ if (hostname.endsWith(host))
77
+ return true;
78
+ continue;
79
+ }
80
+ if (hostname === host)
81
+ return true;
82
+ if (hostname.endsWith(`.${host}`))
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ function getProxyDecision(url) {
88
+ const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'] || '';
89
+ if (!url) {
90
+ return { proxyUrl: null, noProxy };
91
+ }
92
+ if (isNoProxyMatch(url, noProxy)) {
93
+ return { proxyUrl: null, noProxy };
94
+ }
95
+ try {
96
+ const proxyUrl = (0, proxy_from_env_1.getProxyForUrl)(url);
97
+ return { proxyUrl: proxyUrl || null, noProxy };
98
+ }
99
+ catch {
100
+ return { proxyUrl: null, noProxy };
101
+ }
102
+ }
103
+ function buildAxiosConfig(url, headers) {
104
+ const config = {
105
+ headers,
106
+ proxy: false,
107
+ };
108
+ const { proxyUrl } = getProxyDecision(url);
109
+ if (!proxyUrl) {
110
+ return config;
111
+ }
112
+ if (url.startsWith('https:')) {
113
+ config.httpsAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
114
+ }
115
+ else {
116
+ config.httpAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl);
117
+ }
118
+ return config;
119
+ }
120
+ //# sourceMappingURL=axios-config.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hash = exports.version = void 0;
4
- exports.version = "3.6.0"
5
- exports.hash = "491c8181f954b65844e6a38969c64cc45e8f5b22"
4
+ exports.version = "3.7.0"
5
+ exports.hash = "86bfd81f90dfa6241022fd2af81849de9d2c2da0"
6
6
  //# sourceMappingURL=versionMetadata.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomous-testing/sdk",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "scripts": {
5
5
  "build:win": "rm -rf ./build/ && npx tsc && node utils/addVersionToBuild.mjs"
6
6
  },
@@ -20,6 +20,7 @@
20
20
  "dependencies": {
21
21
  "axios": "0.30.0",
22
22
  "process": "^0.11.10",
23
+ "proxy-from-env": "^1.1.0",
23
24
  "zod": "^3.23.0"
24
25
  },
25
26
  "devDependencies": {
@@ -34,6 +35,7 @@
34
35
  "@types/jest": "^29.5.12",
35
36
  "@types/lodash": "^4.17.0",
36
37
  "@types/node": "^20.12.7",
38
+ "@types/proxy-from-env": "^1.0.4",
37
39
  "@typescript-eslint/eslint-plugin": "^7.6.0",
38
40
  "canvas": "^2.11.2",
39
41
  "copyfiles": "^2.4.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopee-io/wopee.pw",
3
- "version": "4.19.0",
3
+ "version": "4.21.0",
4
4
  "description": "Wopee's Playwright integration.",
5
5
  "keywords": [
6
6
  "visual testing",
@@ -26,14 +26,15 @@
26
26
  "types": "./build/index.d.ts",
27
27
  "type": "commonjs",
28
28
  "dependencies": {
29
- "@autonomous-testing/sdk": "3.6.0",
29
+ "@autonomous-testing/sdk": "3.7.0",
30
30
  "dotenv": "^16.6.1",
31
- "lodash": "^4.17.21"
31
+ "lodash": "^4.17.21",
32
+ "proxy-from-env": "^1.1.0"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@commitlint/cli": "^19.2.1",
35
36
  "@commitlint/config-angular": "^19.1.0",
36
- "@playwright/test": "^1.43.1",
37
+ "@playwright/test": "^1.57.0",
37
38
  "@semantic-release/changelog": "^6.0.3",
38
39
  "@semantic-release/exec": "^6.0.3",
39
40
  "@semantic-release/git": "^10.0.1",
@@ -42,6 +43,7 @@
42
43
  "@types/fs-extra": "^11.0.4",
43
44
  "@types/lodash": "^4.17.0",
44
45
  "@types/node": "^20.12.7",
46
+ "@types/proxy-from-env": "^1.0.4",
45
47
  "@typescript-eslint/eslint-plugin": "^7.6.0",
46
48
  "copyfiles": "^2.4.1",
47
49
  "eslint": "^8.57.0",