@zest-pw/test 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"result-processor.d.ts","sourceRoot":"","sources":["../../reporter/result-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AASlF;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,iBAwC3D"}
1
+ {"version":3,"file":"result-processor.d.ts","sourceRoot":"","sources":["../../reporter/result-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAUlF;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,iBAiD3D"}
@@ -4,6 +4,7 @@ exports.processTestResults = processTestResults;
4
4
  const terminal_reporter_1 = require("../utils/terminal-reporter");
5
5
  const test_result_transformer_1 = require("../utils/test-result-transformer");
6
6
  const save_json_report_1 = require("../utils/save-json-report");
7
+ const save_screenshots_1 = require("../utils/save-screenshots");
7
8
  const enrich_test_results_1 = require("../utils/enrich-test-results");
8
9
  const add_file_names_1 = require("../utils/add-file-names");
9
10
  const update_execution_result_1 = require("../zephyr-api/update-execution-result");
@@ -40,6 +41,15 @@ async function processTestResults(fullResult, testResults) {
40
41
  console.error('Error printing test results:', error);
41
42
  }
42
43
  }
44
+ // Save screenshots to disk if enabled
45
+ if (config.screenshots.saveToDisk) {
46
+ try {
47
+ (0, save_screenshots_1.saveScreenshotToDisk)(finalResults);
48
+ }
49
+ catch (error) {
50
+ console.error('Error saving screenshots to disk:', error);
51
+ }
52
+ }
43
53
  // Update test results in Zephyr if enabled
44
54
  if (config.zephyr.enabled && config.zephyr.updateResults) {
45
55
  try {
@@ -7,4 +7,9 @@
7
7
  * @returns Full path to the saved screenshot file
8
8
  */
9
9
  export declare function saveBase64Screenshot(base64String: string, filename: string, outputDir?: string, testTitle?: string): string;
10
+ /**
11
+ * Saves all screenshots from test results to disk
12
+ * @param result - Test results object containing tests array with steps and actualResult attachments
13
+ */
14
+ export declare function saveScreenshotToDisk(result: any): void;
10
15
  //# sourceMappingURL=save-screenshots.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"save-screenshots.d.ts","sourceRoot":"","sources":["../../utils/save-screenshots.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAsB,EACjC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAiBR"}
1
+ {"version":3,"file":"save-screenshots.d.ts","sourceRoot":"","sources":["../../utils/save-screenshots.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAsB,EACjC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAiBR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAwBtD"}
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.saveBase64Screenshot = saveBase64Screenshot;
37
+ exports.saveScreenshotToDisk = saveScreenshotToDisk;
37
38
  const fs = __importStar(require("fs"));
38
39
  const path = __importStar(require("path"));
39
40
  /**
@@ -66,3 +67,32 @@ function saveBase64Screenshot(base64String, filename, outputDir = 'screenshots',
66
67
  fs.writeFileSync(filepath, buffer);
67
68
  return filepath;
68
69
  }
70
+ /**
71
+ * Saves all screenshots from test results to disk
72
+ * @param result - Test results object containing tests array with steps and actualResult attachments
73
+ */
74
+ function saveScreenshotToDisk(result) {
75
+ result.tests.forEach((test) => {
76
+ const allSteps = test.steps || [];
77
+ const testFileName = test.testCaseKey || 'test';
78
+ const sanitizedTitle = test.testTitle.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-|-$/g, '');
79
+ const projectName = test.projectName || 'chromium';
80
+ const outputDir = path.join('test-results', `${testFileName}-${sanitizedTitle}-${projectName}`);
81
+ const actualResult = allSteps.map((test) => test.actualResult);
82
+ actualResult.forEach((att) => {
83
+ try {
84
+ const filename = att[0].fileName;
85
+ const body = att[0].body;
86
+ if (outputDir) {
87
+ saveBase64Screenshot(body, filename, outputDir);
88
+ }
89
+ else {
90
+ saveBase64Screenshot(body, filename);
91
+ }
92
+ }
93
+ catch (error) {
94
+ console.error(` ⚠️ Error saving screenshot: ${error}`);
95
+ }
96
+ });
97
+ });
98
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-reporter.d.ts","sourceRoot":"","sources":["../../utils/terminal-reporter.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAuClD"}
1
+ {"version":3,"file":"terminal-reporter.d.ts","sourceRoot":"","sources":["../../utils/terminal-reporter.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,CAqClD"}
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.printTestResults = printTestResults;
37
37
  const path = __importStar(require("path"));
38
- const save_screenshots_1 = require("./save-screenshots");
39
38
  const config_1 = require("../config");
40
39
  /**
41
40
  * Formats and prints test results after completion
@@ -48,7 +47,6 @@ function printTestResults(result) {
48
47
  }
49
48
  result.tests.forEach((test) => {
50
49
  const allSteps = test.steps || [];
51
- const executedSteps = allSteps.filter((step) => step.statusName !== 'In Progress');
52
50
  const testFileName = test.testCaseKey || 'test';
53
51
  const sanitizedTitle = test.testTitle.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-|-$/g, '');
54
52
  const projectName = test.projectName || 'chromium';
@@ -57,7 +55,7 @@ function printTestResults(result) {
57
55
  const remainder = (63 - testTitle.length) < 0 ? 0 : (63 - testTitle.length);
58
56
  const spaces = '\x1b[40m \x1b[0m'.repeat(remainder);
59
57
  console.log(`\n\x1b[40m${testTitle}${spaces}\x1b[0m`);
60
- printTestSteps(executedSteps.length, allSteps, test.testTitle, outputDir);
58
+ printTestSteps(allSteps, test.testTitle, outputDir);
61
59
  });
62
60
  let passedCount = 0;
63
61
  let failedCount = 0;
@@ -82,12 +80,11 @@ function printTestResults(result) {
82
80
  }
83
81
  /**
84
82
  * Prints test step information
85
- * @param executedCount - Number of executed steps
86
83
  * @param allSteps - Array of all steps (executed and planned)
87
84
  * @param testTitle - Title of the test
88
85
  * @param outputDir - Optional output directory path for saving screenshots
89
86
  */
90
- function printTestSteps(executedCount, allSteps, testTitle, outputDir) {
87
+ function printTestSteps(allSteps, testTitle, outputDir) {
91
88
  console.log('');
92
89
  allSteps.forEach((step, stepIndex) => {
93
90
  if (step.statusName === 'In Progress') {
@@ -96,7 +93,7 @@ function printTestSteps(executedCount, allSteps, testTitle, outputDir) {
96
93
  let stepTitle;
97
94
  switch (step.statusName) {
98
95
  case 'fail':
99
- stepTitle = `\x1b[31m ${step.stepTitle}\x1b[0m`;
96
+ stepTitle = `\x1b[31m${step.stepTitle}\x1b[0m`;
100
97
  break;
101
98
  default:
102
99
  stepTitle = step.stepTitle;
@@ -132,26 +129,15 @@ function printStepAttachments(step, testTitle, outputDir, _stepNumber) {
132
129
  }
133
130
  console.log(`\x1b[30mscreenshot:\x1b[0m`);
134
131
  step.actualResult.forEach((att) => {
135
- const isErrorScreenshot = att.fileName?.includes('ERROR');
136
- const emoji = isErrorScreenshot ? '💥' : att.image === 'image/png' ? '📸' : '📄';
137
- const displayName = att.image === 'image/png' ? '\x1b[30mDecode:\x1b[0m Base64' : att.fileName;
138
- console.log(` ${emoji} ${displayName}`);
139
- if (att.body && att.image === 'text/plain') {
140
- console.log(`${att.body}`);
141
- }
132
+ const displayName = att.image === 'image/png' ? '\x1b[30m-decode:\x1b[0m Base64' : att.fileName;
133
+ console.log(` ${displayName}`);
142
134
  const config = (0, config_1.getZestConfig)();
143
135
  const shouldSaveScreenshots = config.screenshots.saveToDisk || process.env.SAVE_SCREENSHOTS === 'true';
144
- if (att.body && shouldSaveScreenshots && att.image === 'image/png') {
136
+ if (att.body && shouldSaveScreenshots) {
145
137
  try {
146
138
  const filename = att.fileName;
147
- if (outputDir) {
148
- (0, save_screenshots_1.saveBase64Screenshot)(att.body, filename, outputDir);
149
- }
150
- else {
151
- (0, save_screenshots_1.saveBase64Screenshot)(att.body, filename, 'screenshots', testTitle);
152
- }
153
- console.log(` \x1b[30m💾 saved:\x1b[0m Locally`);
154
- console.log(` \x1b[30m📄 name:\x1b[0m ${filename}`);
139
+ console.log(` \x1b[30m -saved:\x1b[0m Locally`);
140
+ console.log(` \x1b[30m -name:\x1b[0m ${filename}`);
155
141
  }
156
142
  catch (error) {
157
143
  console.error(` ⚠️ Error saving screenshot: ${error}`);
@@ -1 +1 @@
1
- {"version":3,"file":"get-results-from-json.d.ts","sourceRoot":"","sources":["../../zephyr-api/get-results-from-json.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAsB,kBAAkB,iBAoBvC"}
1
+ {"version":3,"file":"get-results-from-json.d.ts","sourceRoot":"","sources":["../../zephyr-api/get-results-from-json.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAsB,kBAAkB,iBA+BvC"}
@@ -67,7 +67,18 @@ async function getResultsFromJson() {
67
67
  const { projectName, testTitle, testCaseKey, ...testData } = test;
68
68
  acc[testCaseKey] = {
69
69
  ...testData,
70
- steps: test.steps.map(({ stepTitle, ...step }) => step)
70
+ steps: test.steps.map(({ stepTitle, actualResult, ...step }) => {
71
+ let processedActualResult = actualResult;
72
+ if (actualResult && Array.isArray(actualResult)) {
73
+ processedActualResult = actualResult.map(item => {
74
+ return `<img src="data:${item.image || ''};base64,${item.body || ''}" alt="${item.fileName || ''}">`;
75
+ }).join('');
76
+ }
77
+ return {
78
+ actualResult: processedActualResult,
79
+ ...step
80
+ };
81
+ })
71
82
  };
72
83
  return acc;
73
84
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zest-pw/test",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",