@zest-pw/test 1.0.1 → 1.0.2

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.
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../types/types.ts"],"names":[],"mappings":""}
File without changes
@@ -14,5 +14,5 @@ import type { Page, TestInfo } from "@playwright/test";
14
14
  * @param testInfo - Playwright TestInfo object for attaching screenshots
15
15
  * @param stepTitle - Optional step title for attachment name
16
16
  */
17
- export declare function takeScreenshotAfterStep(page: Page, stepInfo: any, testInfo: TestInfo, stepTitle?: string): Promise<void>;
17
+ export declare function takeScreenshotAfterStep(page: Page, testInfo: TestInfo, stepTitle?: string): Promise<void>;
18
18
  //# sourceMappingURL=take-screenshots.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"take-screenshots.d.ts","sourceRoot":"","sources":["../../utils/take-screenshots.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,QAAQ,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAef"}
1
+ {"version":3,"file":"take-screenshots.d.ts","sourceRoot":"","sources":["../../utils/take-screenshots.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAaf"}
@@ -16,13 +16,11 @@ exports.takeScreenshotAfterStep = takeScreenshotAfterStep;
16
16
  * @param testInfo - Playwright TestInfo object for attaching screenshots
17
17
  * @param stepTitle - Optional step title for attachment name
18
18
  */
19
- async function takeScreenshotAfterStep(page, stepInfo, testInfo, stepTitle) {
19
+ async function takeScreenshotAfterStep(page, testInfo, stepTitle) {
20
20
  try {
21
21
  if (page && testInfo) {
22
- const screenshotBuffer = await page.screenshot({
23
- fullPage: true
24
- });
25
- await testInfo.attach(stepTitle || stepInfo?.title || 'screenshot', {
22
+ const screenshotBuffer = await page.screenshot({ fullPage: true });
23
+ await testInfo.attach(stepTitle || 'screenshot', {
26
24
  body: screenshotBuffer,
27
25
  contentType: 'image/png',
28
26
  });
@@ -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,CAoBlD"}
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,CAsBlD"}
@@ -47,14 +47,18 @@ function printTestResults(result) {
47
47
  return;
48
48
  }
49
49
  result.tests.forEach((test) => {
50
- printTestInfo(test);
51
50
  const allSteps = test.steps || [];
52
51
  const executedSteps = allSteps.filter((step) => step.statusName !== 'In Progress');
53
52
  const testFileName = test.testCaseKey || 'test';
54
53
  const sanitizedTitle = test.testTitle.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-|-$/g, '');
55
54
  const projectName = test.projectName || 'chromium';
56
55
  const outputDir = path.join('test-results', `${testFileName}-${sanitizedTitle}-${projectName}`);
56
+ console.log('');
57
+ console.log('');
58
+ console.log(`\x1b[30m––––––––––––––––––––––––––––––––––\x1b[0m ${test.testCaseKey} \x1b[30m––––––––––––––––––––––––––––––––––\x1b[0m`);
59
+ printTestInfo(test);
57
60
  printTestSteps(executedSteps.length, allSteps, test.testTitle, outputDir);
61
+ console.log('');
58
62
  });
59
63
  }
60
64
  /**
@@ -62,7 +66,7 @@ function printTestResults(result) {
62
66
  * @param test - Test object containing testCaseKey and testTitle
63
67
  */
64
68
  function printTestInfo(test) {
65
- console.log(`\n${test.testCaseKey}: ${test.testTitle}`);
69
+ console.log(`\n\x1b[30mTEST CASE:\x1b[0m ${test.testTitle}`);
66
70
  }
67
71
  /**
68
72
  * Prints test step information
@@ -72,26 +76,30 @@ function printTestInfo(test) {
72
76
  * @param outputDir - Optional output directory path for saving screenshots
73
77
  */
74
78
  function printTestSteps(executedCount, allSteps, testTitle, outputDir) {
75
- if (allSteps.length === 0) {
76
- console.log(' Steps: none');
77
- return;
78
- }
79
79
  const totalCount = allSteps.length;
80
- console.log(` Steps (${executedCount}/${totalCount}):`);
80
+ console.log('');
81
81
  allSteps.forEach((step, stepIndex) => {
82
- const statusEmoji = step.statusName === 'pass' ? 'passed - ✅' : step.statusName === 'failed' ? 'fail - ❌' : step.statusName === 'In Progress' ? 'skipped - ⏭️' : '⏱️';
83
- console.log(` ${stepIndex + 1}. ${step.stepTitle}`);
82
+ const statusEmoji = step.statusName === 'pass' ? '\x1b[32mPASSED ✓\x1b[0m' : step.statusName === 'fail' ? '\x1b[31mFAILED ✗\x1b[0m' : step.statusName === 'In Progress' ? '\x1b[30mSKIPPED ⊘\x1b[0m' : '⏱️';
84
83
  if (step.error) {
85
- console.log(` ❌ Error: ${step.error.message}`);
86
- if (step.error.stack) {
87
- const stackLines = step.error.stack.split('\n').slice(0, 3);
88
- stackLines.forEach((line) => console.log(` ${line}`));
89
- }
84
+ console.log('\x1b[31m- - - - - - - - - - - - - ERROR - - - - - - - - - - - - -\x1b[0m');
85
+ console.log('');
90
86
  }
87
+ console.log(`\x1b[30mTest Step ${stepIndex + 1}:\x1b[0m ${step.stepTitle}`);
91
88
  printStepAttachments(step, testTitle, outputDir, stepIndex + 1);
92
- console.log(` Status: ${statusEmoji}`);
93
89
  console.log('');
90
+ console.log(`\x1b[30mstatus:\x1b[0m ${statusEmoji}\x1b[0m`);
91
+ console.log('');
92
+ if (step.error) {
93
+ const stackLines = step.error.message.split('\n').slice(0, 4);
94
+ stackLines.forEach((line) => console.log(`${line}`));
95
+ console.log('');
96
+ console.log('\x1b[31m- - - - - - - - - - - - - ERROR - - - - - - - - - - - - -\x1b[0m');
97
+ console.log('');
98
+ }
94
99
  });
100
+ console.log('');
101
+ console.log(`\x1b[30mTotal results:\x1b[0m \x1b[32m${executedCount} passed,\x1b[0m \x1b[31m${totalCount - executedCount} failed\x1b[0m`);
102
+ console.log('');
95
103
  }
96
104
  /**
97
105
  * Prints step attachments (screenshots, etc.)
@@ -104,14 +112,14 @@ function printStepAttachments(step, testTitle, outputDir, _stepNumber) {
104
112
  if (!step.actualResult || step.actualResult.length === 0) {
105
113
  return;
106
114
  }
107
- console.log(` Screenshot:`);
115
+ console.log(`\x1b[30mScreenshot:\x1b[0m`);
108
116
  step.actualResult.forEach((att) => {
109
117
  const isErrorScreenshot = att.fileName?.includes('ERROR');
110
118
  const emoji = isErrorScreenshot ? '💥' : att.image === 'image/png' ? '📸' : '📄';
111
- const displayName = att.image === 'image/png' ? 'Decode: Base64' : att.fileName;
112
- console.log(` ${emoji} ${displayName}`);
119
+ const displayName = att.image === 'image/png' ? '\x1b[30mDecode:\x1b[0m Base64' : att.fileName;
120
+ console.log(` ${emoji} ${displayName}`);
113
121
  if (att.body && att.image === 'text/plain') {
114
- console.log(` ${att.body}`);
122
+ console.log(`${att.body}`);
115
123
  }
116
124
  const config = (0, config_1.getZestConfig)();
117
125
  const shouldSaveScreenshots = config.screenshots.saveToDisk || process.env.SAVE_SCREENSHOTS === 'true';
@@ -124,11 +132,11 @@ function printStepAttachments(step, testTitle, outputDir, _stepNumber) {
124
132
  else {
125
133
  (0, save_screenshots_1.saveBase64Screenshot)(att.body, filename, 'screenshots', testTitle);
126
134
  }
127
- console.log(` 💾 File saved: locally`);
128
- console.log(` 📄 File name: ${filename}`);
135
+ console.log(` \x1b[30m💾 File saved:\x1b[0m locally`);
136
+ console.log(` \x1b[30m📄 File name:\x1b[0m ${filename}`);
129
137
  }
130
138
  catch (error) {
131
- console.error(` ⚠️ Error saving screenshot: ${error}`);
139
+ console.error(` ⚠️ Error saving screenshot: ${error}`);
132
140
  }
133
141
  }
134
142
  });
@@ -1,10 +1,10 @@
1
- import type { TestInfo, TestType, Page } from '@playwright/test';
1
+ import type { TestInfo, Page, test as base } from '@playwright/test';
2
2
  /**
3
3
  * Wraps test.step to automatically create screenshots after each test step
4
4
  * @param test - Playwright test object
5
5
  * @param getCurrentContext - Function to get current test context (testInfo and page)
6
6
  */
7
- export declare function wrapTestStepWithScreenshots(test: TestType<any, any>, getCurrentContext: () => {
7
+ export declare function wrapTestStepWithScreenshots(test: typeof base, getCurrentContext: () => {
8
8
  testInfo: TestInfo;
9
9
  page: Page;
10
10
  } | null): void;
@@ -1 +1 @@
1
- {"version":3,"file":"test-step-wrapper.d.ts","sourceRoot":"","sources":["../../utils/test-step-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGjE;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EACxB,iBAAiB,EAAE,MAAM;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,GACjE,IAAI,CAsCN"}
1
+ {"version":3,"file":"test-step-wrapper.d.ts","sourceRoot":"","sources":["../../utils/test-step-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAgB,IAAI,IAAI,IAAI,EAAY,MAAM,kBAAkB,CAAC;AAG7F;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,OAAO,IAAI,EACjB,iBAAiB,EAAE,MAAM;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,GACjE,IAAI,CAmCN"}
@@ -9,27 +9,25 @@ const take_screenshots_1 = require("./take-screenshots");
9
9
  */
10
10
  function wrapTestStepWithScreenshots(test, getCurrentContext) {
11
11
  const originalTestStep = test.step.bind(test);
12
- const originalTestStepSkip = test.step.skip?.bind(test);
12
+ const originalTestStepSkip = test.step.skip.bind(test);
13
+ const takeScreenshot = async (title) => {
14
+ const context = getCurrentContext();
15
+ try {
16
+ await (0, take_screenshots_1.takeScreenshotAfterStep)(context.page, context.testInfo, title);
17
+ }
18
+ catch (screenshotError) {
19
+ console.error('Error taking screenshot after step error:', screenshotError);
20
+ }
21
+ };
13
22
  const stepWrapper = async function (title, body, options) {
14
23
  return originalTestStep(title, async (stepInfo) => {
15
24
  try {
16
25
  const result = await body(stepInfo);
17
- const context = getCurrentContext();
18
- if (context?.page && context?.testInfo) {
19
- await (0, take_screenshots_1.takeScreenshotAfterStep)(context.page, stepInfo, context.testInfo, title);
20
- }
26
+ await takeScreenshot(title);
21
27
  return result;
22
28
  }
23
29
  catch (error) {
24
- const context = getCurrentContext();
25
- if (context?.page && context?.testInfo) {
26
- try {
27
- await (0, take_screenshots_1.takeScreenshotAfterStep)(context.page, { ...stepInfo, error }, context.testInfo, title);
28
- }
29
- catch (screenshotError) {
30
- console.error('Error taking screenshot after step error:', screenshotError);
31
- }
32
- }
30
+ await takeScreenshot(title);
33
31
  throw error;
34
32
  }
35
33
  }, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zest-pw/test",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",