@zest-pw/test 1.0.9 → 1.0.11

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/dist/config.d.ts CHANGED
@@ -55,6 +55,11 @@ export interface ZestConfig {
55
55
  * @default false
56
56
  */
57
57
  saveToDisk?: boolean;
58
+ /**
59
+ * Capture full page screenshot (scrolls to capture entire page)
60
+ * @default true
61
+ */
62
+ fullPage?: boolean;
58
63
  };
59
64
  /**
60
65
  * Zephyr Scale integration settings
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;;WAGG;QACH,cAAc,CAAC,EAAE,OAAO,CAAC;QAEzB;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB;;;WAGG;QACH,cAAc,CAAC,EAAE,OAAO,CAAC;QAEzB;;;;WAIG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IAEF;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ;;;WAGG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAElB;;;WAGG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;QAE1B;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QAExB;;;WAGG;QACH,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;IAEF;;OAEG;IACH,MAAM,CAAC,EAAE;QACP;;;WAGG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAElB;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB;;WAEG;QACH,YAAY,CAAC,EAAE,MAAM,CAAC;QAEtB;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;C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AAE,MAAM,CAAC;QAEtB;;;WAGG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,UAAU,CAqB9C,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,CAiBzE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,QAAQ,CAAC,UAAU,CAAC,CAEpD;AAED;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAgBpE"}
package/dist/config.js CHANGED
@@ -58,6 +58,7 @@ exports.defaultConfig = {
58
58
  includeInReport: true,
59
59
  onlyOnFailure: false,
60
60
  saveToDisk: false,
61
+ fullPage: true,
61
62
  },
62
63
  zephyr: {
63
64
  enabled: false,
@@ -129,7 +130,9 @@ async function loadZestConfig() {
129
130
  const configPath = process.cwd() + '/zest.config.ts';
130
131
  const userConfig = await Promise.resolve(`${configPath}`).then(s => __importStar(require(s)));
131
132
  if (userConfig.default) {
132
- return userConfig.default;
133
+ // Update global loadedConfig so getZestConfig() returns the same values
134
+ loadedConfig = userConfig.default;
135
+ return loadedConfig;
133
136
  }
134
137
  return loadedConfig;
135
138
  }
@@ -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;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"}
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,iBAsD3D"}
@@ -23,10 +23,14 @@ async function processTestResults(fullResult, testResults) {
23
23
  const enrichedResults = (0, enrich_test_results_1.enrichTestResultsWithPlannedSteps)(transformedResults);
24
24
  // Add formatted file names to actualResult
25
25
  const finalResults = (0, add_file_names_1.addFileNamesToResults)(enrichedResults);
26
+ // Remove screenshot bodies from report if includeInReport is false
27
+ const resultsForReport = config.screenshots.includeInReport
28
+ ? finalResults
29
+ : removeScreenshotBodies(finalResults);
26
30
  // Save JSON report if enabled
27
31
  if (config.reporter.saveJsonReport) {
28
32
  try {
29
- (0, save_json_report_1.saveTestResultsToJson)(finalResults, config.reporter.outputDir);
33
+ (0, save_json_report_1.saveTestResultsToJson)(resultsForReport, config.reporter.outputDir);
30
34
  }
31
35
  catch (error) {
32
36
  console.error('Error saving JSON report:', error);
@@ -60,3 +64,32 @@ async function processTestResults(fullResult, testResults) {
60
64
  }
61
65
  }
62
66
  }
67
+ /**
68
+ * Removes screenshot bodies (base64 data) from test results while keeping metadata
69
+ * This is used when includeInReport is false to reduce JSON file size
70
+ * @param results - Test results object
71
+ * @returns Test results with screenshot bodies removed
72
+ */
73
+ function removeScreenshotBodies(results) {
74
+ return {
75
+ ...results,
76
+ tests: results.tests.map((test) => ({
77
+ ...test,
78
+ steps: test.steps.map((step) => ({
79
+ ...step,
80
+ actualResult: step.actualResult?.map((att) => {
81
+ // If it's a screenshot (image/png), remove the body but keep metadata
82
+ if (att.image === 'image/png') {
83
+ return {
84
+ fileName: att.fileName,
85
+ image: att.image,
86
+ // body is omitted
87
+ };
88
+ }
89
+ // For other attachments, keep as is
90
+ return att;
91
+ }) || []
92
+ }))
93
+ }))
94
+ };
95
+ }
@@ -3,16 +3,22 @@
3
3
  */
4
4
  import type { Page, TestInfo } from "@playwright/test";
5
5
  /**
6
- * Takes a screenshot after each test step (always, regardless of result)
6
+ * Takes a screenshot after each test step
7
+ *
8
+ * Screenshot behavior is controlled by configuration:
9
+ * - screenshots.enabled: If false, no screenshots are taken
10
+ * - screenshots.onlyOnFailure: If true, screenshots are only taken when step fails
11
+ * - screenshots.fullPage: Controls whether to capture full page or viewport only
7
12
  *
8
13
  * To save screenshots to disk (from base64 results):
9
14
  * 1. Add to .env file: SAVE_SCREENSHOTS=true
10
15
  * 2. Or pass via command: SAVE_SCREENSHOTS=true npx playwright test
16
+ * 3. Or set screenshots.saveToDisk: true in config
11
17
  *
12
18
  * @param page - Playwright Page object
13
- * @param stepInfo - Step information object
14
19
  * @param testInfo - Playwright TestInfo object for attaching screenshots
15
20
  * @param stepTitle - Optional step title for attachment name
21
+ * @param hasError - Whether the step failed (used for onlyOnFailure logic)
16
22
  */
17
- export declare function takeScreenshotAfterStep(page: Page, testInfo: TestInfo, stepTitle?: string): Promise<void>;
23
+ export declare function takeScreenshotAfterStep(page: Page, testInfo: TestInfo, stepTitle?: string, hasError?: boolean): Promise<void>;
18
24
  //# 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,QAAQ,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAaf"}
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;AAGvD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -4,22 +4,41 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.takeScreenshotAfterStep = takeScreenshotAfterStep;
7
+ const config_1 = require("../config");
7
8
  /**
8
- * Takes a screenshot after each test step (always, regardless of result)
9
+ * Takes a screenshot after each test step
10
+ *
11
+ * Screenshot behavior is controlled by configuration:
12
+ * - screenshots.enabled: If false, no screenshots are taken
13
+ * - screenshots.onlyOnFailure: If true, screenshots are only taken when step fails
14
+ * - screenshots.fullPage: Controls whether to capture full page or viewport only
9
15
  *
10
16
  * To save screenshots to disk (from base64 results):
11
17
  * 1. Add to .env file: SAVE_SCREENSHOTS=true
12
18
  * 2. Or pass via command: SAVE_SCREENSHOTS=true npx playwright test
19
+ * 3. Or set screenshots.saveToDisk: true in config
13
20
  *
14
21
  * @param page - Playwright Page object
15
- * @param stepInfo - Step information object
16
22
  * @param testInfo - Playwright TestInfo object for attaching screenshots
17
23
  * @param stepTitle - Optional step title for attachment name
24
+ * @param hasError - Whether the step failed (used for onlyOnFailure logic)
18
25
  */
19
- async function takeScreenshotAfterStep(page, testInfo, stepTitle) {
26
+ async function takeScreenshotAfterStep(page, testInfo, stepTitle, hasError) {
20
27
  try {
21
28
  if (page && testInfo) {
22
- const screenshotBuffer = await page.screenshot({ fullPage: true });
29
+ const config = (0, config_1.getZestConfig)();
30
+ // Check if screenshots are enabled
31
+ if (!config.screenshots.enabled) {
32
+ return;
33
+ }
34
+ // Check if we should only take screenshots on failure
35
+ // If onlyOnFailure is true, only take screenshot when hasError is explicitly true
36
+ if (config.screenshots.onlyOnFailure && !hasError) {
37
+ return;
38
+ }
39
+ const screenshotBuffer = await page.screenshot({
40
+ fullPage: config.screenshots.fullPage
41
+ });
23
42
  await testInfo.attach(stepTitle || 'screenshot', {
24
43
  body: screenshotBuffer,
25
44
  contentType: 'image/png',
@@ -10,10 +10,10 @@ const take_screenshots_1 = require("./take-screenshots");
10
10
  function wrapTestStepWithScreenshots(test, getCurrentContext) {
11
11
  const originalTestStep = test.step.bind(test);
12
12
  const originalTestStepSkip = test.step.skip.bind(test);
13
- const takeScreenshot = async (title) => {
13
+ const takeScreenshot = async (title, hasError = false) => {
14
14
  const context = getCurrentContext();
15
15
  try {
16
- await (0, take_screenshots_1.takeScreenshotAfterStep)(context.page, context.testInfo, title);
16
+ await (0, take_screenshots_1.takeScreenshotAfterStep)(context.page, context.testInfo, title, hasError);
17
17
  }
18
18
  catch (screenshotError) {
19
19
  console.error('Error taking screenshot after step error:', screenshotError);
@@ -23,11 +23,11 @@ function wrapTestStepWithScreenshots(test, getCurrentContext) {
23
23
  return originalTestStep(title, async (stepInfo) => {
24
24
  try {
25
25
  const result = await body(stepInfo);
26
- await takeScreenshot(title);
26
+ await takeScreenshot(title, false);
27
27
  return result;
28
28
  }
29
29
  catch (error) {
30
- await takeScreenshot(title);
30
+ await takeScreenshot(title, true);
31
31
  throw error;
32
32
  }
33
33
  }, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zest-pw/test",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
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",