@wopee-io/wopee.pw 4.14.1 → 4.15.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.
@@ -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.14.1"
7
- let hash = "c5e8377f8b84a3682cb66ca3568d3d688893f461"
6
+ let version = "4.15.0"
7
+ let hash = "e3eb60128311d9fbc21ab0a17e1a89e9f3461b2f"
8
8
  if (version === '__LOCAL__') {
9
9
  version = process.env.npm_package_version || '__LOCAL__';
10
10
  }
@@ -1,5 +1,8 @@
1
1
  import type { Reporter, TestCase, TestResult } from '@playwright/test/reporter';
2
2
  import 'dotenv/config';
3
3
  export declare class WopeeReporter implements Reporter {
4
- onTestEnd(test: TestCase, result: TestResult): Promise<void | import("axios").AxiosResponse<any, any>>;
4
+ private uploadQueue;
5
+ constructor();
6
+ onTestEnd(test: TestCase, result: TestResult): void;
7
+ onExit(): Promise<void>;
5
8
  }
@@ -20,74 +20,97 @@ require("dotenv/config");
20
20
  const node_fs_1 = __importDefault(require("node:fs"));
21
21
  const { WOPEE_API_KEY, WOPEE_API_URL, WOPEE_PROJECT_UUID } = process.env;
22
22
  class WopeeReporter {
23
+ constructor() {
24
+ this.uploadQueue = [];
25
+ }
23
26
  onTestEnd(test, result) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- var _a, _b, _c, _d;
26
- const testRunId = (0, helpers_1.generateTestRunId)();
27
- const wopeeScenarioUuid = (_b = (_a = result.attachments
28
- .find((a) => (a === null || a === void 0 ? void 0 : a.name) === 'wopee-scenario-uuid')) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.toString('utf-8');
29
- const failedStep = [...result.steps].reverse().find((step) => step.error);
30
- let screenshotBase64 = null;
31
- for (const attachment of result.attachments) {
32
- if (attachment.name === 'screenshot' && attachment.contentType === 'image/png') {
33
- const filePath = attachment.path;
34
- if (filePath) {
35
- try {
36
- const imageBuffer = node_fs_1.default.readFileSync(filePath);
37
- screenshotBase64 = imageBuffer.toString('base64');
38
- break;
39
- }
40
- catch (error) {
41
- console.error('Error reading screenshot:', error);
42
- }
27
+ var _a, _b;
28
+ const testRunId = (0, helpers_1.generateTestRunId)();
29
+ const wopeeScenarioUuid = (_b = (_a = result.attachments
30
+ .find((a) => (a === null || a === void 0 ? void 0 : a.name) === 'wopee-scenario-uuid')) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.toString('utf-8');
31
+ const failedStep = [...result.steps].reverse().find((step) => step.error);
32
+ let screenshotBase64 = null;
33
+ for (const attachment of result.attachments) {
34
+ if (attachment.name === 'screenshot' && attachment.contentType === 'image/png') {
35
+ const filePath = attachment.path;
36
+ if (filePath) {
37
+ try {
38
+ const imageBuffer = node_fs_1.default.readFileSync(filePath);
39
+ screenshotBase64 = imageBuffer.toString('base64');
40
+ break;
41
+ }
42
+ catch (error) {
43
+ console.error('Error reading screenshot:', error);
43
44
  }
44
45
  }
45
46
  }
46
- if (!wopeeScenarioUuid) {
47
- 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');
48
- }
49
- const steps = result.steps.map((step, index) => ({
50
- testRunId,
51
- number: index + 1,
52
- testTitle: test.title,
53
- title: step.title,
54
- status: step.error ? 'failed' : 'passed',
55
- error: step.error ? (0, helpers_1.parseError)(step.error) : step.error,
56
- category: step.category,
57
- location: step.location,
58
- duration: step.duration,
59
- startTime: step.startTime,
60
- steps: (0, helpers_1.parseNestedSteps)(step.steps),
61
- screenshotBase64: step === failedStep ? screenshotBase64 : null,
62
- }));
63
- const query = `
47
+ }
48
+ if (!wopeeScenarioUuid) {
49
+ 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');
50
+ }
51
+ const steps = result.steps.map((step, index) => ({
52
+ testRunId,
53
+ number: index + 1,
54
+ testTitle: test.title,
55
+ title: step.title,
56
+ status: step.error ? 'failed' : 'passed',
57
+ error: step.error ? (0, helpers_1.parseError)(step.error) : step.error,
58
+ category: step.category,
59
+ location: step.location,
60
+ duration: step.duration,
61
+ startTime: step.startTime,
62
+ steps: (0, helpers_1.parseNestedSteps)(step.steps),
63
+ screenshotBase64: step === failedStep ? screenshotBase64 : null,
64
+ }));
65
+ const query = `
64
66
  mutation ExtendIntegrationScenario($input: ExtendIntegrationScenarioInput!) {
65
67
  extendIntegrationScenario(input: $input)
66
68
  }`;
67
- const extendIntegrationScenarioPayload = {
68
- input: {
69
- projectUuid: WOPEE_PROJECT_UUID,
70
- scenarioUuid: wopeeScenarioUuid,
71
- pwSteps: JSON.stringify(steps, helpers_1.replacer),
72
- },
73
- };
74
- const variables = wopeeReporter_interface_js_1.ExtendIntegrationScenarioPayloadSchema.parse(extendIntegrationScenarioPayload);
69
+ const extendIntegrationScenarioPayload = {
70
+ input: {
71
+ projectUuid: WOPEE_PROJECT_UUID,
72
+ scenarioUuid: wopeeScenarioUuid,
73
+ pwSteps: JSON.stringify(steps, helpers_1.replacer),
74
+ },
75
+ };
76
+ const variables = wopeeReporter_interface_js_1.ExtendIntegrationScenarioPayloadSchema.parse(extendIntegrationScenarioPayload);
77
+ const uploadPromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
78
+ var _c, _d;
75
79
  try {
76
80
  const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';
77
- return yield axios_1.default.post(apiUrl, { query, variables }, {
81
+ const response = yield axios_1.default.post(apiUrl, { query, variables }, {
78
82
  headers: {
79
83
  api_key: WOPEE_API_KEY,
80
84
  },
81
85
  });
86
+ resolve(response);
82
87
  }
83
88
  catch (error) {
84
89
  if (axios_1.default.isAxiosError(error)) {
85
90
  const status = (_c = error.response) === null || _c === void 0 ? void 0 : _c.status;
86
91
  const errorData = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data;
87
92
  console.error('[WOPEE_REPORTER_ERROR]', errorData);
88
- throw new Error(`API request failed with status code: ${status}.`);
93
+ reject(new Error(`API request failed with status code: ${status}.`));
94
+ }
95
+ reject(new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error === null || error === void 0 ? void 0 : error.message}`));
96
+ }
97
+ }));
98
+ this.uploadQueue.push(uploadPromise);
99
+ }
100
+ onExit() {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ if (this.uploadQueue.length > 0) {
103
+ console.log(`Uploading ${this.uploadQueue.length} remaining test results...`);
104
+ try {
105
+ yield Promise.all(this.uploadQueue);
106
+ console.log('Successfully uploaded all test results.');
107
+ }
108
+ catch (error) {
109
+ console.error('Error uploading test results:', error);
110
+ }
111
+ finally {
112
+ this.uploadQueue = [];
89
113
  }
90
- throw new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error === null || error === void 0 ? void 0 : error.message}`);
91
114
  }
92
115
  });
93
116
  }
@@ -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;IAClB,SAAS,CAAC,IAAc,EAAE,MAAkB;;;YAChD,MAAM,SAAS,GAAG,IAAA,2BAAiB,GAAE,CAAC;YAEtC,MAAM,iBAAiB,GAAG,MAAA,MAAA,MAAM,CAAC,WAAW;iBACzC,IAAI,CAAC,CAAC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AA,KAAK,CAAC,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,IAAI,KAAK,CAAC,wCAAwC,MAAM,GAAG,CAAC,CAAC;gBACrE,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,qEAAqE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAC;YACzG,CAAC;QACH,CAAC;KAAA;CACF;AAlFD,sCAkFC","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 async 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 let screenshotBase64: string | null = null;\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 break;\n } catch (error) {\n console.error('Error reading screenshot:', 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: step === failedStep ? screenshotBase64 : 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 try {\n const apiUrl = WOPEE_API_URL || 'https://api.wopee.io';\n return await axios.post(\n apiUrl,\n { query, variables },\n {\n headers: {\n api_key: WOPEE_API_KEY,\n },\n },\n );\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 throw new Error(`API request failed with status code: ${status}.`);\n }\n throw new Error(`[WOPEE_REPORTER_ERROR] Unexpected error occurred during API call: ${error?.message}`);\n }\n }\n}\n"]}
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,SAA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EAAE,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF;AA3GD,sCA2GC","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 let screenshotBase64: string | null = null;\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 break;\n } catch (error) {\n console.error('Error reading screenshot:', 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: step === failedStep ? screenshotBase64 : 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopee-io/wopee.pw",
3
- "version": "4.14.1",
3
+ "version": "4.15.0",
4
4
  "description": "Wopee's Playwright integration.",
5
5
  "keywords": [
6
6
  "visual testing",