@zest-pw/test 1.0.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.
Files changed (58) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +415 -0
  3. package/dist/config.d.ts +127 -0
  4. package/dist/config.d.ts.map +1 -0
  5. package/dist/config.js +140 -0
  6. package/dist/fixtures/fixtures.d.ts +3 -0
  7. package/dist/fixtures/fixtures.d.ts.map +1 -0
  8. package/dist/fixtures/fixtures.js +24 -0
  9. package/dist/index.d.ts +13 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +36 -0
  12. package/dist/reporter/custom-reporter.d.ts +11 -0
  13. package/dist/reporter/custom-reporter.d.ts.map +1 -0
  14. package/dist/reporter/custom-reporter.js +19 -0
  15. package/dist/reporter/result-processor.d.ts +11 -0
  16. package/dist/reporter/result-processor.d.ts.map +1 -0
  17. package/dist/reporter/result-processor.js +52 -0
  18. package/dist/reporter/test-results-store.d.ts +31 -0
  19. package/dist/reporter/test-results-store.d.ts.map +1 -0
  20. package/dist/reporter/test-results-store.js +38 -0
  21. package/dist/utils/add-file-names.d.ts +9 -0
  22. package/dist/utils/add-file-names.d.ts.map +1 -0
  23. package/dist/utils/add-file-names.js +39 -0
  24. package/dist/utils/enrich-test-results.d.ts +6 -0
  25. package/dist/utils/enrich-test-results.d.ts.map +1 -0
  26. package/dist/utils/enrich-test-results.js +113 -0
  27. package/dist/utils/parse-test-steps.d.ts +8 -0
  28. package/dist/utils/parse-test-steps.d.ts.map +1 -0
  29. package/dist/utils/parse-test-steps.js +110 -0
  30. package/dist/utils/save-json-report.d.ts +17 -0
  31. package/dist/utils/save-json-report.d.ts.map +1 -0
  32. package/dist/utils/save-json-report.js +75 -0
  33. package/dist/utils/save-screenshots.d.ts +9 -0
  34. package/dist/utils/save-screenshots.d.ts.map +1 -0
  35. package/dist/utils/save-screenshots.js +66 -0
  36. package/dist/utils/take-screenshots.d.ts +13 -0
  37. package/dist/utils/take-screenshots.d.ts.map +1 -0
  38. package/dist/utils/take-screenshots.js +34 -0
  39. package/dist/utils/terminal-reporter.d.ts +8 -0
  40. package/dist/utils/terminal-reporter.d.ts.map +1 -0
  41. package/dist/utils/terminal-reporter.js +140 -0
  42. package/dist/utils/test-result-transformer.d.ts +13 -0
  43. package/dist/utils/test-result-transformer.d.ts.map +1 -0
  44. package/dist/utils/test-result-transformer.js +109 -0
  45. package/dist/utils/test-step-wrapper.d.ts +13 -0
  46. package/dist/utils/test-step-wrapper.d.ts.map +1 -0
  47. package/dist/utils/test-step-wrapper.js +48 -0
  48. package/dist/zephyr-api/get-results-from-json.d.ts +2 -0
  49. package/dist/zephyr-api/get-results-from-json.d.ts.map +1 -0
  50. package/dist/zephyr-api/get-results-from-json.js +71 -0
  51. package/dist/zephyr-api/update-execution-result.d.ts +2 -0
  52. package/dist/zephyr-api/update-execution-result.d.ts.map +1 -0
  53. package/dist/zephyr-api/update-execution-result.js +26 -0
  54. package/dist/zephyr-api/zephyr-api.d.ts +19 -0
  55. package/dist/zephyr-api/zephyr-api.d.ts.map +1 -0
  56. package/dist/zephyr-api/zephyr-api.js +89 -0
  57. package/package.json +69 -0
  58. package/scripts/install-config.js +92 -0
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTestResult = updateTestResult;
4
+ const get_results_from_json_1 = require("./get-results-from-json");
5
+ const zephyr_api_1 = require("./zephyr-api");
6
+ async function updateTestResult() {
7
+ console.log('Updating test result in Zephyr...');
8
+ const testResults = await (0, get_results_from_json_1.getResultsFromJson)();
9
+ if (!testResults) {
10
+ console.error('No test results found');
11
+ return;
12
+ }
13
+ // Iterate over object with testCaseKey as keys
14
+ for (const testCaseKey in testResults) {
15
+ const steps = testResults[testCaseKey];
16
+ const testCaseId = await (0, zephyr_api_1.getTestCaseId)(testCaseKey);
17
+ if (!testCaseId) {
18
+ console.warn(`Test case ID not found for key: ${testCaseKey}`);
19
+ continue;
20
+ }
21
+ const testExecutionKey = await (0, zephyr_api_1.getTestExecutionKey)(testCaseId);
22
+ if (testExecutionKey) {
23
+ await (0, zephyr_api_1.putTestExecution)(testExecutionKey, steps);
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Gets test case ID from Zephyr by its key
3
+ * @param testCaseKey - Test case key (e.g., "TC-001")
4
+ * @returns Test case ID or undefined in case of error
5
+ */
6
+ export declare function getTestCaseId(testCaseKey: string): Promise<string | undefined>;
7
+ /**
8
+ * Gets test execution key from Zephyr by test case ID
9
+ * @param testCaseId - Test case ID
10
+ * @returns Test execution key or null in case of error
11
+ */
12
+ export declare function getTestExecutionKey(testCaseId: string): Promise<string | null>;
13
+ /**
14
+ * Puts test execution in Zephyr
15
+ * @param testExecutionKey - Test execution key
16
+ * @param steps - Array of test steps to update
17
+ */
18
+ export declare function putTestExecution(testExecutionKey: string, steps: string[]): Promise<void>;
19
+ //# sourceMappingURL=zephyr-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zephyr-api.d.ts","sourceRoot":"","sources":["../../zephyr-api/zephyr-api.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,+BAmBtD;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,0BA2B3D;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,iBA2B/E"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTestCaseId = getTestCaseId;
4
+ exports.getTestExecutionKey = getTestExecutionKey;
5
+ exports.putTestExecution = putTestExecution;
6
+ // Common headers for all requests
7
+ const getHeaders = () => {
8
+ return {
9
+ 'Content-Type': 'application/json',
10
+ 'Authorization': `Bearer ${process.env.ZEPHYR_API_KEY}`
11
+ };
12
+ };
13
+ /**
14
+ * Gets test case ID from Zephyr by its key
15
+ * @param testCaseKey - Test case key (e.g., "TC-001")
16
+ * @returns Test case ID or undefined in case of error
17
+ */
18
+ async function getTestCaseId(testCaseKey) {
19
+ try {
20
+ const response = await fetch(process.env.ZEPHYR_API_URL + 'testcases/' + testCaseKey, {
21
+ method: 'GET',
22
+ headers: getHeaders(),
23
+ });
24
+ // Return only ID
25
+ const data = await response.json();
26
+ const id = data.id;
27
+ console.log('------------------------------------------');
28
+ console.log('Test case key:', testCaseKey);
29
+ return id;
30
+ }
31
+ catch (error) {
32
+ console.error('Error getting test case ID:', error);
33
+ return undefined;
34
+ }
35
+ }
36
+ /**
37
+ * Gets test execution key from Zephyr by test case ID
38
+ * @param testCaseId - Test case ID
39
+ * @returns Test execution key or null in case of error
40
+ */
41
+ async function getTestExecutionKey(testCaseId) {
42
+ try {
43
+ const response = await fetch(process.env.ZEPHYR_API_URL + 'testexecutions' + '?testCycle=' + process.env.ZEPHYR_TEST_CYCLE_KEY + '&maxResults=1000', {
44
+ method: 'GET',
45
+ headers: getHeaders()
46
+ });
47
+ // Find object in array by testCase.id
48
+ const data = await response.json();
49
+ const testExecution = data.values.find((execution) => execution.testCase.id === testCaseId);
50
+ if (testExecution) {
51
+ console.log('Test execution key:', testExecution.key);
52
+ return testExecution.key;
53
+ }
54
+ else {
55
+ console.log('Test execution not found for testCase ID:', testCaseId);
56
+ return null;
57
+ }
58
+ }
59
+ catch (error) {
60
+ console.error('Error getting test execution:', error);
61
+ return null;
62
+ }
63
+ }
64
+ /**
65
+ * Puts test execution in Zephyr
66
+ * @param testExecutionKey - Test execution key
67
+ * @param steps - Array of test steps to update
68
+ */
69
+ async function putTestExecution(testExecutionKey, steps) {
70
+ try {
71
+ const body = {
72
+ steps: steps
73
+ };
74
+ await fetch(process.env.ZEPHYR_API_URL + 'testexecutions/' + testExecutionKey + '/teststeps', {
75
+ method: 'PUT',
76
+ body: JSON.stringify(body),
77
+ headers: getHeaders()
78
+ });
79
+ console.log('Successfully sent test steps to Zephyr ✅');
80
+ console.log('------------------------------------------');
81
+ // Add 3 second pause after updating steps
82
+ console.log('Waiting 3 seconds before continuing... ⏳');
83
+ await new Promise(resolve => setTimeout(resolve, 3000));
84
+ }
85
+ catch (error) {
86
+ console.error('Error updating test steps:', error);
87
+ throw error;
88
+ }
89
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@zest-pw/test",
3
+ "version": "1.0.0",
4
+ "description": "Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "default": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ },
12
+ "./reporter": "./dist/reporter/custom-reporter.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "scripts",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "bin": {
21
+ "zest-pw-init": "scripts/install-config.js"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "test": "playwright test",
26
+ "prepublishOnly": "npm run build",
27
+ "type-check": "tsc --noEmit",
28
+ "postinstall": "node scripts/install-config.js",
29
+ "install": "node scripts/install-config.js"
30
+ },
31
+ "keywords": [
32
+ "playwright",
33
+ "testing",
34
+ "automation",
35
+ "zephyr",
36
+ "zephyr-scale",
37
+ "screenshots",
38
+ "test-framework",
39
+ "test-reporter",
40
+ "e2e",
41
+ "end-to-end"
42
+ ],
43
+ "author": "",
44
+ "license": "MIT",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/Capuchin33/zest-pw.git"
48
+ },
49
+ "homepage": "https://github.com/Capuchin33/zest-pw#readme",
50
+ "bugs": {
51
+ "url": "https://github.com/Capuchin33/zest-pw/issues"
52
+ },
53
+ "engines": {
54
+ "node": ">=16.0.0"
55
+ },
56
+ "peerDependencies": {
57
+ "@playwright/test": "^1.40.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "@playwright/test": {
61
+ "optional": false
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@playwright/test": "^1.40.0",
66
+ "@types/node": "^20.0.0",
67
+ "typescript": "^5.0.0"
68
+ }
69
+ }
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Post-install script to automatically create zest.config.ts in the project root
5
+ * This script runs after npm install and creates a default configuration file
6
+ * if it doesn't already exist.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ const configTemplate = `import { defineZestConfig } from '@zest-pw/test';
13
+
14
+ /**
15
+ * Zest Playwright Configuration
16
+ *
17
+ * Configure test reporting, screenshots, and Zephyr integration
18
+ */
19
+ export default defineZestConfig({
20
+ reporter: {
21
+ // Save test results to JSON file
22
+ saveJsonReport: true,
23
+ // Output directory for reports
24
+ outputDir: 'test-results',
25
+ // Print test results to console
26
+ printToConsole: true,
27
+ // Verbose output (includes all step details)
28
+ verbose: false,
29
+ },
30
+ screenshots: {
31
+ // Enable screenshot capture
32
+ enabled: true,
33
+ // Include screenshots in JSON report
34
+ includeInReport: true,
35
+ // Capture screenshots only on failure
36
+ onlyOnFailure: false,
37
+ // Save screenshots to disk as files
38
+ saveToDisk: false,
39
+ },
40
+ zephyr: {
41
+ // Enable Zephyr Scale integration
42
+ enabled: false,
43
+ // Update test results in Zephyr after test run
44
+ updateResults: false,
45
+ // API credentials (uses environment variables by default)
46
+ // apiUrl: process.env.ZEPHYR_API_URL,
47
+ // apiKey: process.env.ZEPHYR_API_KEY,
48
+ // testCycleKey: process.env.ZEPHYR_TEST_CYCLE_KEY,
49
+ },
50
+ });
51
+ `;
52
+
53
+ const configFileName = 'zest.config.ts';
54
+
55
+ // When postinstall runs, process.cwd() is the project root where npm install was executed
56
+ // This is the correct directory where we want to create zest.config.ts
57
+ const projectRoot = process.cwd();
58
+ const configPath = path.join(projectRoot, configFileName);
59
+
60
+ // Skip if we're in the zest-pw package development directory itself
61
+ // (when running npm install in the package repo)
62
+ const packageJsonPath = path.join(projectRoot, 'package.json');
63
+ if (fs.existsSync(packageJsonPath)) {
64
+ try {
65
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
66
+ if (packageJson.name === '@zest-pw/test') {
67
+ // We're in the package development directory, skip
68
+ process.exit(0);
69
+ }
70
+ } catch (e) {
71
+ // If we can't read package.json, continue anyway
72
+ }
73
+ }
74
+
75
+ // Перевіряємо, чи файл вже існує
76
+ if (fs.existsSync(configPath)) {
77
+ console.log(`[@zest-pw/test] ✓ ${configFileName} already exists, skipping...`);
78
+ process.exit(0);
79
+ }
80
+
81
+ // Створюємо файл конфігурації
82
+ try {
83
+ fs.writeFileSync(configPath, configTemplate, 'utf8');
84
+ console.log(`[@zest-pw/test] ✓ Created ${configFileName} in project root`);
85
+ console.log(`[@zest-pw/test] Location: ${configPath}`);
86
+ } catch (error) {
87
+ // Don't break the installation process, but show the error
88
+ console.error(`[@zest-pw/test] ⚠ Failed to create ${configFileName}:`, error.message);
89
+ console.error(`[@zest-pw/test] Target directory: ${projectRoot}`);
90
+ process.exit(0); // Exit with 0 to not break npm install
91
+ }
92
+