donobu 2.29.1 → 2.30.1

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 (35) hide show
  1. package/dist/assets/generated/version +1 -1
  2. package/dist/cli/install-donobu-plugin.d.ts +6 -0
  3. package/dist/cli/install-donobu-plugin.d.ts.map +1 -0
  4. package/dist/cli/install-donobu-plugin.js +125 -0
  5. package/dist/cli/install-donobu-plugin.js.map +1 -0
  6. package/dist/cli/playwright-json-to-markdown.d.ts +43 -0
  7. package/dist/cli/playwright-json-to-markdown.d.ts.map +1 -0
  8. package/dist/cli/playwright-json-to-markdown.js +239 -0
  9. package/dist/cli/playwright-json-to-markdown.js.map +1 -0
  10. package/dist/cli/playwright-json-to-slack-json.d.ts +3 -0
  11. package/dist/cli/playwright-json-to-slack-json.d.ts.map +1 -0
  12. package/dist/cli/playwright-json-to-slack-json.js +207 -0
  13. package/dist/cli/playwright-json-to-slack-json.js.map +1 -0
  14. package/dist/esm/assets/generated/version +1 -1
  15. package/dist/esm/cli/install-donobu-plugin.d.ts +6 -0
  16. package/dist/esm/cli/install-donobu-plugin.d.ts.map +1 -0
  17. package/dist/esm/cli/install-donobu-plugin.js +125 -0
  18. package/dist/esm/cli/install-donobu-plugin.js.map +1 -0
  19. package/dist/esm/cli/playwright-json-to-markdown.d.ts +43 -0
  20. package/dist/esm/cli/playwright-json-to-markdown.d.ts.map +1 -0
  21. package/dist/esm/cli/playwright-json-to-markdown.js +239 -0
  22. package/dist/esm/cli/playwright-json-to-markdown.js.map +1 -0
  23. package/dist/esm/cli/playwright-json-to-slack-json.d.ts +3 -0
  24. package/dist/esm/cli/playwright-json-to-slack-json.d.ts.map +1 -0
  25. package/dist/esm/cli/playwright-json-to-slack-json.js +207 -0
  26. package/dist/esm/cli/playwright-json-to-slack-json.js.map +1 -0
  27. package/dist/esm/managers/PluginLoader.js +3 -15
  28. package/dist/esm/managers/PluginLoader.js.map +1 -1
  29. package/dist/managers/PluginLoader.js +3 -15
  30. package/dist/managers/PluginLoader.js.map +1 -1
  31. package/package.json +4 -3
  32. package/dist/assets/playwright-json-to-markdown.js +0 -257
  33. package/dist/assets/playwright-json-to-slack-json.js +0 -171
  34. package/dist/esm/assets/playwright-json-to-markdown.js +0 -257
  35. package/dist/esm/assets/playwright-json-to-slack-json.js +0 -171
@@ -1 +1 @@
1
- 1289
1
+ 1293
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ export declare function getPluginName(): Promise<string>;
3
+ export declare function buildPlugin(): Promise<void>;
4
+ export declare function installPlugin(): Promise<void>;
5
+ export declare function main(): Promise<void>;
6
+ //# sourceMappingURL=install-donobu-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-donobu-plugin.d.ts","sourceRoot":"","sources":["../../src/cli/install-donobu-plugin.ts"],"names":[],"mappings":";AA2CA,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAgCrD;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAGjD;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAsBnD;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAoB1C"}
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getPluginName = getPluginName;
5
+ exports.buildPlugin = buildPlugin;
6
+ exports.installPlugin = installPlugin;
7
+ exports.main = main;
8
+ /**
9
+ * @fileoverview Donobu Plugin Installation CLI
10
+ *
11
+ * A command-line utility for building and installing Donobu plugins into the local Donobu Studio environment.
12
+ * This script automates the process of compiling a plugin and copying it to the appropriate plugins directory
13
+ * where Donobu Studio can discover and load it.
14
+ *
15
+ * @usage
16
+ * Run this command from within a Donobu plugin directory (must contain package.json and src/ directory):
17
+ *
18
+ * ```bash
19
+ * npm exec install-donobu-plugin
20
+ * ```
21
+ *
22
+ * @process
23
+ * 1. Validates that the current directory is a valid plugin directory.
24
+ * 2. Determines the plugin name from package.json, git repository, or username.
25
+ * 3. Runs `npm run build` to compile the plugin.
26
+ * 4. Copies the built plugin to the Donobu plugin directory (OS-variant).
27
+ * 5. Provides instructions to restart Donobu Studio to see the new tools.
28
+ *
29
+ * @requirements
30
+ * - Must be run from a directory containing package.json.
31
+ * - Must be run from a directory containing src/ directory.
32
+ * - The project must have a working `npm run build` script.
33
+ * - Write permissions to the Donobu Studio plugins directory.
34
+ *
35
+ * @output
36
+ * - Plugin compiled and installed to Donobu Studio plugins directory.
37
+ * - Console output with installation progress and final location.
38
+ */
39
+ const child_process_1 = require("child_process");
40
+ const util_1 = require("util");
41
+ const promises_1 = require("fs/promises");
42
+ const path_1 = require("path");
43
+ const fs_1 = require("fs");
44
+ const Logger_1 = require("../utils/Logger");
45
+ const MiscUtils_1 = require("../utils/MiscUtils");
46
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
47
+ async function getPluginName() {
48
+ try {
49
+ // First, try to read the plugin name from package.json
50
+ const packageJsonContent = await (0, promises_1.readFile)('package.json', 'utf8');
51
+ const packageJson = JSON.parse(packageJsonContent);
52
+ if (packageJson.name) {
53
+ Logger_1.appLogger.info(`Using plugin name from package.json: ${packageJson.name}`);
54
+ return packageJson.name;
55
+ }
56
+ }
57
+ catch (error) {
58
+ Logger_1.appLogger.warn('Could not read package.json name, falling back to git/user detection', error);
59
+ }
60
+ // Fallback to a heuristic
61
+ try {
62
+ const { stdout } = await execAsync('git rev-parse --show-toplevel');
63
+ const repoPath = stdout.trim();
64
+ const gitBasedName = `${(0, path_1.basename)(repoPath).replace(/\.git$/, '')}-custom-tools`;
65
+ Logger_1.appLogger.info(`Using git-based plugin name: ${gitBasedName}`);
66
+ return gitBasedName;
67
+ }
68
+ catch {
69
+ const user = process.env.USER || 'unknown-user';
70
+ const userBasedName = `${user}-custom-tools`;
71
+ Logger_1.appLogger.info(`Using user-based plugin name: ${userBasedName}`);
72
+ return userBasedName;
73
+ }
74
+ }
75
+ async function buildPlugin() {
76
+ Logger_1.appLogger.info('Building plugin...');
77
+ await execAsync('npm run build');
78
+ }
79
+ async function installPlugin() {
80
+ const pluginName = await getPluginName();
81
+ const pluginsDir = (0, path_1.join)(MiscUtils_1.MiscUtils.baseWorkingDirectory(), 'plugins');
82
+ const thisPluginDir = (0, path_1.join)(pluginsDir, pluginName);
83
+ Logger_1.appLogger.info(`Installing plugin: ${pluginName}`);
84
+ // Create plugins directory
85
+ await (0, promises_1.mkdir)(pluginsDir, { recursive: true });
86
+ // Remove old plugin if exists
87
+ try {
88
+ await (0, promises_1.rm)(thisPluginDir, { recursive: true, force: true });
89
+ }
90
+ catch {
91
+ // Ignore if directory doesn't exist
92
+ }
93
+ // Copy built plugin
94
+ await (0, promises_1.cp)('dist', thisPluginDir, { recursive: true });
95
+ Logger_1.appLogger.info(`Plugin installed successfully to: ${thisPluginDir}`);
96
+ Logger_1.appLogger.info('Restart Donobu to see the new tools.');
97
+ }
98
+ async function main() {
99
+ try {
100
+ // Check if we're in a plugin directory
101
+ try {
102
+ await (0, promises_1.access)('package.json', fs_1.constants.F_OK);
103
+ await (0, promises_1.access)('src', fs_1.constants.F_OK);
104
+ }
105
+ catch {
106
+ Logger_1.appLogger.error('Error: This command must be run from a Donobu plugin directory');
107
+ Logger_1.appLogger.error('Make sure you have package.json and src/ directory');
108
+ process.exit(1);
109
+ }
110
+ await buildPlugin();
111
+ await installPlugin();
112
+ }
113
+ catch (error) {
114
+ Logger_1.appLogger.error('Installation failed:', error);
115
+ process.exit(1);
116
+ }
117
+ }
118
+ // If this file is being run directly
119
+ if (require.main === module) {
120
+ main().catch((error) => {
121
+ console.error('Unhandled error:', error);
122
+ process.exit(1);
123
+ });
124
+ }
125
+ //# sourceMappingURL=install-donobu-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-donobu-plugin.js","sourceRoot":"","sources":["../../src/cli/install-donobu-plugin.ts"],"names":[],"mappings":";;;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AC,cAAc,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;YAC7C,MAAM,IAAA,iBAAM,EAAC,KAAK,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,kBAAS,CAAC,KAAK,CACb,gEAAgE,CACjE,CAAC;YACF,kBAAS,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,WAAW,EAAE,CAAC;QACpB,MAAM,aAAa,EAAE,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAS,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,qCAAqC;AACrC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Playwright JSON Report to Markdown Converter
4
+ *
5
+ * A command-line utility that converts Playwright JSON test reports into human-readable Markdown format.
6
+ * This tool is designed to be used in CI/CD pipelines to generate formatted test reports for GitHub
7
+ * Actions summaries, pull request comments, or documentation.
8
+ *
9
+ * @usage
10
+ * Read from file:
11
+ * ```bash
12
+ * npm exec playwright-json-to-markdown report.json
13
+ * ```
14
+ *
15
+ * Read from stdin (useful in pipelines):
16
+ * ```bash
17
+ * cat test-results/results.json | npx playwright-json-to-markdown
18
+ * npm exec playwright test --reporter=json | npx playwright-json-to-markdown
19
+ * ```
20
+ *
21
+ * @input
22
+ * Expects a Playwright JSON report with the following structure:
23
+ * - config: Test configuration including projects.
24
+ * - suites: Array of test suites containing specs and tests.
25
+ * - stats: Summary statistics (duration, expected, unexpected, flaky, skipped).
26
+ *
27
+ * @output
28
+ * Generates a Markdown report containing:
29
+ * - 📊 Summary table with test counts and duration.
30
+ * - Overall pass/fail status with appropriate emoji.
31
+ * - 📋 Detailed results organized by file and test suite.
32
+ * - ❌ Error details and locations for failed tests.
33
+ * - 🚀 List of configured projects.
34
+ *
35
+ * @features
36
+ * - Emoji indicators for test status (✅ passed, ❌ failed).
37
+ * - Human-readable duration formatting (ms, s, m s).
38
+ * - Hierarchical organization (file → spec → test).
39
+ * - Error message and location details for failures.
40
+ * - Summary statistics in tabular format.
41
+ */
42
+ export {};
43
+ //# sourceMappingURL=playwright-json-to-markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-json-to-markdown.d.ts","sourceRoot":"","sources":["../../src/cli/playwright-json-to-markdown.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG"}
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * @fileoverview Playwright JSON Report to Markdown Converter
5
+ *
6
+ * A command-line utility that converts Playwright JSON test reports into human-readable Markdown format.
7
+ * This tool is designed to be used in CI/CD pipelines to generate formatted test reports for GitHub
8
+ * Actions summaries, pull request comments, or documentation.
9
+ *
10
+ * @usage
11
+ * Read from file:
12
+ * ```bash
13
+ * npm exec playwright-json-to-markdown report.json
14
+ * ```
15
+ *
16
+ * Read from stdin (useful in pipelines):
17
+ * ```bash
18
+ * cat test-results/results.json | npx playwright-json-to-markdown
19
+ * npm exec playwright test --reporter=json | npx playwright-json-to-markdown
20
+ * ```
21
+ *
22
+ * @input
23
+ * Expects a Playwright JSON report with the following structure:
24
+ * - config: Test configuration including projects.
25
+ * - suites: Array of test suites containing specs and tests.
26
+ * - stats: Summary statistics (duration, expected, unexpected, flaky, skipped).
27
+ *
28
+ * @output
29
+ * Generates a Markdown report containing:
30
+ * - 📊 Summary table with test counts and duration.
31
+ * - Overall pass/fail status with appropriate emoji.
32
+ * - 📋 Detailed results organized by file and test suite.
33
+ * - ❌ Error details and locations for failed tests.
34
+ * - 🚀 List of configured projects.
35
+ *
36
+ * @features
37
+ * - Emoji indicators for test status (✅ passed, ❌ failed).
38
+ * - Human-readable duration formatting (ms, s, m s).
39
+ * - Hierarchical organization (file → spec → test).
40
+ * - Error message and location details for failures.
41
+ * - Summary statistics in tabular format.
42
+ */
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ const fs_1 = require("fs");
45
+ function stripAnsiCodes(str) {
46
+ return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
47
+ }
48
+ // Function to format duration in a readable way
49
+ function formatDuration(ms) {
50
+ if (ms < 1000) {
51
+ return `${ms}ms`;
52
+ }
53
+ const seconds = Math.floor(ms / 1000);
54
+ if (seconds < 60) {
55
+ return `${seconds}s`;
56
+ }
57
+ const minutes = Math.floor(seconds / 60);
58
+ const remainingSeconds = seconds % 60;
59
+ return `${minutes}m ${remainingSeconds}s`;
60
+ }
61
+ // Read the JSON data from file or stdin
62
+ function readInput() {
63
+ const args = process.argv.slice(2);
64
+ if (args.length > 0) {
65
+ return JSON.parse((0, fs_1.readFileSync)(args[0], 'utf8'));
66
+ }
67
+ else {
68
+ return JSON.parse((0, fs_1.readFileSync)(0, 'utf8')); // Read from stdin
69
+ }
70
+ }
71
+ // Process JSON and create markdown
72
+ function generateMarkdown(jsonData) {
73
+ const { suites } = jsonData;
74
+ // Create report header
75
+ let markdown = `# Playwright Test Report\n\n`;
76
+ // Tests by file
77
+ markdown += `## Summary\n\n`;
78
+ // Create file summary table with status counts
79
+ markdown += `| File | Passed | Self-Healed | Failed | Timed Out | Skipped | Interrupted | Duration |\n`;
80
+ markdown += `| - | - | - | - | - | - | - | - |\n`;
81
+ // Track totals for summary row
82
+ let totalPassed = 0;
83
+ let totalFailed = 0;
84
+ let totalTimedOut = 0;
85
+ let totalSkipped = 0;
86
+ let totalInterrupted = 0;
87
+ let totalSelfHealed = 0;
88
+ let totalDuration = 0;
89
+ suites.forEach((suite) => {
90
+ // Count tests by status for this file
91
+ let passed = 0;
92
+ let failed = 0;
93
+ let timedOut = 0;
94
+ let skipped = 0;
95
+ let interrupted = 0;
96
+ let selfHealed = 0;
97
+ const fileDuration = suite.specs.reduce((total, spec) => total +
98
+ spec.tests.reduce((testTotal, test) => {
99
+ const result = test.results && test.results.at(-1);
100
+ const isSelfHealed = test.annotations &&
101
+ test.annotations.some((a) => a.type === 'self-healed');
102
+ if (test.status === 'skipped' ||
103
+ (!result && test.status === undefined)) {
104
+ skipped++;
105
+ }
106
+ else if (result) {
107
+ if (isSelfHealed) {
108
+ selfHealed++;
109
+ }
110
+ else {
111
+ switch (result.status) {
112
+ case 'passed':
113
+ passed++;
114
+ break;
115
+ case 'failed':
116
+ failed++;
117
+ break;
118
+ case 'timedOut':
119
+ timedOut++;
120
+ break;
121
+ case 'skipped':
122
+ skipped++;
123
+ break;
124
+ case 'interrupted':
125
+ interrupted++;
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ return testTotal + (result?.duration || 0);
131
+ }, 0), 0);
132
+ // Add to totals
133
+ totalPassed += passed;
134
+ totalFailed += failed;
135
+ totalTimedOut += timedOut;
136
+ totalSkipped += skipped;
137
+ totalInterrupted += interrupted;
138
+ totalSelfHealed += selfHealed;
139
+ totalDuration += fileDuration;
140
+ markdown += `| ${suite.file} | ${passed ? passed + ' ✅' : ''} | ${selfHealed ? selfHealed + ' ❤️‍🩹' : ''} | ${failed ? failed + ' ❌' : ''} | ${timedOut ? timedOut + ' ⏰' : ''} | ${skipped ? skipped + ' ⏭️' : ''} | ${interrupted ? interrupted + ' ⚡' : ''} | ${formatDuration(fileDuration)} |\n`;
141
+ });
142
+ // Add totals row
143
+ markdown += `| **TOTAL** | **${totalPassed + ' ✅'}** | **${totalSelfHealed + ' ❤️‍🩹'}** | **${totalFailed + ' ❌'}** | **${totalTimedOut + ' ⏰'}** | **${totalSkipped + ' ⏭️'}** | **${totalInterrupted + ' ⚡'}** | **${formatDuration(totalDuration)}** |\n`;
144
+ markdown += `\n`;
145
+ // Generate test details sections
146
+ suites.forEach((suite) => {
147
+ const fileName = suite.file;
148
+ markdown += `## ${fileName}\n\n`;
149
+ suite.specs.forEach((spec) => {
150
+ markdown += `### ${spec.title}\n\n`;
151
+ spec.tests.forEach((test) => {
152
+ const result = test.results && test.results.at(-1);
153
+ if (test.status === 'skipped' || !result || test.status === undefined) {
154
+ markdown += `**Status**: ⏭️ Skipped \n`;
155
+ markdown += `**Duration**: N/A \n`;
156
+ // Get objective from annotations if available
157
+ let objective = 'No objective provided';
158
+ if (test.annotations) {
159
+ const objectiveAnnotation = test.annotations.find((a) => a.type === 'objective');
160
+ if (objectiveAnnotation) {
161
+ objective =
162
+ objectiveAnnotation.description || 'No objective provided';
163
+ }
164
+ }
165
+ // Escape any existing triple backticks in the objective
166
+ objective = objective.replace(/```/g, '\\`\\`\\`');
167
+ markdown += `**Objective**:\n\`\`\`\n${objective}\n\`\`\`\n`;
168
+ markdown += `---\n\n`;
169
+ return;
170
+ }
171
+ const isSelfHealed = test.annotations &&
172
+ test.annotations.some((a) => a.type === 'self-healed');
173
+ // Determine status based on result status and self-healing annotation
174
+ let status;
175
+ if (result.status === 'passed') {
176
+ status = '✅ Passed';
177
+ }
178
+ else if (isSelfHealed) {
179
+ status = '❌ Failed (❤️‍🩹 Self-Healed)';
180
+ }
181
+ else if (result.status === 'failed') {
182
+ status = '❌ Failed';
183
+ }
184
+ else if (result.status === 'timedOut') {
185
+ status = '⏰ Timed Out';
186
+ }
187
+ else if (result.status === 'skipped') {
188
+ status = '⏭️ Skipped';
189
+ }
190
+ else if (result.status === 'interrupted') {
191
+ status = '⚡ Interrupted';
192
+ }
193
+ else {
194
+ status = `⚠️ ${result.status || 'Unknown'}`;
195
+ }
196
+ const duration = formatDuration(result.duration || 0);
197
+ // Get objective from annotations if available
198
+ let objective = 'No objective provided';
199
+ if (test.annotations) {
200
+ const objectiveAnnotation = test.annotations.find((a) => a.type === 'objective');
201
+ if (objectiveAnnotation) {
202
+ objective =
203
+ objectiveAnnotation.description || 'No objective provided';
204
+ }
205
+ }
206
+ // Escape any existing triple backticks in the objective by replacing ``` with \`\`\`
207
+ objective = objective.replace(/```/g, '\\`\\`\\`');
208
+ markdown += `**Status**: ${status} \n`;
209
+ markdown += `**Duration**: ${duration} \n`;
210
+ markdown += `**Objective**:\n\`\`\`\n${objective}\n\`\`\`\n`;
211
+ // Add error details if test failed
212
+ if (result.status === 'failed' && result.error) {
213
+ markdown += `\n<details>\n<summary>⚠️ Error Details</summary>\n\n`;
214
+ markdown += `\`\`\`\n${result.error.message || 'No error message available'}\n\`\`\`\n\n`;
215
+ // Include code snippet if available
216
+ if (result.error.snippet) {
217
+ markdown += `**Code Snippet**:\n\`\`\`\n${stripAnsiCodes(result.error.snippet)}\n\`\`\`\n\n`;
218
+ }
219
+ markdown += `</details>\n\n`;
220
+ }
221
+ markdown += `---\n\n`;
222
+ });
223
+ });
224
+ });
225
+ // Add timestamp footer
226
+ markdown += `_Report generated on ${new Date().toLocaleString()} by Donobu_\n`;
227
+ return markdown;
228
+ }
229
+ // Main execution
230
+ try {
231
+ const jsonData = readInput();
232
+ const markdown = generateMarkdown(jsonData);
233
+ console.log(markdown);
234
+ }
235
+ catch (error) {
236
+ console.error('Error processing JSON: ', error.message);
237
+ process.exit(1);
238
+ }
239
+ //# sourceMappingURL=playwright-json-to-markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-json-to-markdown.js","sourceRoot":"","sources":["../../src/cli/playwright-json-to-markdown.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,uBAAuB;IACvB,QAAQ,IAAI,wBAAwB,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IAE/E,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,iBAAiB;AACjB,IAAI,CAAC;IACH,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAG,KAAa,CAAC,OAAO,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=playwright-json-to-slack-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-json-to-slack-json.d.ts","sourceRoot":"","sources":["../../src/cli/playwright-json-to-slack-json.ts"],"names":[],"mappings":""}
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * @fileoverview Playwright JSON Report to Slack Message Converter
6
+ *
7
+ * A command-line utility that converts Playwright JSON test reports into Slack-compatible JSON messages
8
+ * using Slack's Block Kit format. This tool is designed for CI/CD pipelines to send automated test
9
+ * notifications to Slack channels with rich formatting and actionable information.
10
+ *
11
+ * @usage
12
+ * Basic usage (read from file):
13
+ * ```bash
14
+ * npm exec playwright-json-to-slack-json report.json
15
+ * ```
16
+ *
17
+ * With report URL link:
18
+ * ```bash
19
+ * npm exec playwright-json-to-slack-json --report-url "https://example.com/report" report.json
20
+ * ```
21
+ *
22
+ * Read from stdin (useful in pipelines):
23
+ * ```bash
24
+ * cat test-results/results.json | npx playwright-json-to-slack-json --report-url "$REPORT_URL"
25
+ * npm exec playwright test --reporter=json | npx playwright-json-to-slack-json
26
+ * ```
27
+ *
28
+ * @parameters
29
+ * - `--report-url <url>`: Optional URL to link to the full test report.
30
+ * - `<report.json>`: Path to Playwright JSON report file (if not reading from stdin).
31
+ *
32
+ * @input
33
+ * Expects a Playwright JSON report with the following structure:
34
+ * - config: Test configuration including projects.
35
+ * - suites: Array of test suites containing specs and tests.
36
+ * - stats: Summary statistics (duration, expected, unexpected, flaky, skipped).
37
+ *
38
+ * @output
39
+ * Generates a Slack Block Kit JSON message containing:
40
+ * - Header with overall test status (✅ passed or ❌ failed).
41
+ * - Summary section with test counts and duration.
42
+ * - Failed test details (limited to first 10 failures).
43
+ * - Optional link to full report if --report-url provided.
44
+ * - Rich formatting with emojis and structured layout.
45
+ *
46
+ * @features
47
+ * - Slack Block Kit formatted messages for rich display.
48
+ * - Color-coded status indicators (green for pass, red for fail).
49
+ * - Condensed failed test listing (shows first 10, indicates if more).
50
+ * - Human-readable duration formatting.
51
+ * - Optional external report linking.
52
+ * - Proper emoji usage for visual clarity.
53
+ *
54
+ * @integration
55
+ * Use with Slack Incoming Webhooks:
56
+ * ```bash
57
+ * # Generate Slack payload and send to webhook
58
+ * SLACK_PAYLOAD=$(npm exec playwright-json-to-slack-json --report-url "$REPORT_URL" < results.json)
59
+ * curl -X POST -H 'Content-type: application/json' --data "$SLACK_PAYLOAD" "$SLACK_WEBHOOK_URL"
60
+ * ```
61
+ */
62
+ const fs_1 = require("fs");
63
+ // Read the JSON data from file or stdin
64
+ function readInput() {
65
+ const args = process.argv.slice(2);
66
+ // Parse arguments to extract report URL and input file
67
+ let reportUrl = null;
68
+ let inputFile = null;
69
+ for (let i = 0; i < args.length; i++) {
70
+ if (args[i] === '--report-url' && i + 1 < args.length) {
71
+ reportUrl = args[i + 1];
72
+ i++; // Skip the URL value
73
+ }
74
+ else if (!args[i].startsWith('--')) {
75
+ inputFile = args[i];
76
+ }
77
+ }
78
+ let jsonData;
79
+ if (inputFile) {
80
+ jsonData = JSON.parse((0, fs_1.readFileSync)(inputFile, 'utf8'));
81
+ }
82
+ else {
83
+ jsonData = JSON.parse((0, fs_1.readFileSync)(0, 'utf8')); // Read from stdin
84
+ }
85
+ return { jsonData, reportUrl };
86
+ }
87
+ // Process JSON and create simplified Slack blocks
88
+ function generateSlackBlocks(jsonData, reportUrl) {
89
+ const { suites } = jsonData;
90
+ const blocks = [];
91
+ // Header block
92
+ blocks.push({
93
+ type: 'header',
94
+ text: {
95
+ type: 'plain_text',
96
+ text: '🎭 Playwright Test Summary',
97
+ },
98
+ });
99
+ // Track totals
100
+ let totalPassed = 0;
101
+ let totalFailed = 0;
102
+ let totalTimedOut = 0;
103
+ let totalSkipped = 0;
104
+ let totalInterrupted = 0;
105
+ let totalSelfHealed = 0;
106
+ // Process each suite to get totals
107
+ suites.forEach((suite) => {
108
+ suite.specs.forEach((spec) => {
109
+ spec.tests.forEach((test) => {
110
+ const result = test.results && test.results.at(-1);
111
+ const isSelfHealed = test.annotations &&
112
+ test.annotations.some((a) => a.type === 'self-healed');
113
+ if (test.status === 'skipped' ||
114
+ (!result && test.status === undefined)) {
115
+ totalSkipped++;
116
+ }
117
+ else if (result) {
118
+ if (isSelfHealed) {
119
+ totalSelfHealed++;
120
+ }
121
+ else {
122
+ switch (result.status) {
123
+ case 'passed':
124
+ totalPassed++;
125
+ break;
126
+ case 'failed':
127
+ totalFailed++;
128
+ break;
129
+ case 'timedOut':
130
+ totalTimedOut++;
131
+ break;
132
+ case 'skipped':
133
+ totalSkipped++;
134
+ break;
135
+ case 'interrupted':
136
+ totalInterrupted++;
137
+ break;
138
+ }
139
+ }
140
+ }
141
+ });
142
+ });
143
+ });
144
+ // Create status summary table
145
+ const statusRows = [
146
+ { name: 'Passed', emoji: '✅', count: totalPassed },
147
+ { name: 'Self-Healed', emoji: '❤️‍🩹', count: totalSelfHealed },
148
+ { name: 'Failed', emoji: '❌', count: totalFailed },
149
+ { name: 'Timed Out', emoji: '⏰', count: totalTimedOut },
150
+ { name: 'Skipped', emoji: '⏭️', count: totalSkipped },
151
+ { name: 'Interrupted', emoji: '⚡', count: totalInterrupted },
152
+ ];
153
+ // Add each status row as a section with two fields
154
+ statusRows.forEach((row) => {
155
+ blocks.push({
156
+ type: 'section',
157
+ fields: [
158
+ {
159
+ type: 'mrkdwn',
160
+ text: `${row.emoji} ${row.name}`,
161
+ },
162
+ {
163
+ type: 'mrkdwn',
164
+ text: `${row.count}`,
165
+ },
166
+ ],
167
+ });
168
+ });
169
+ // Add report URL link if provided
170
+ if (reportUrl) {
171
+ blocks.push({
172
+ type: 'divider',
173
+ });
174
+ blocks.push({
175
+ type: 'section',
176
+ text: {
177
+ type: 'mrkdwn',
178
+ text: `📊 <${reportUrl}|View Full Report>`,
179
+ },
180
+ });
181
+ }
182
+ // Add timestamp footer
183
+ blocks.push({
184
+ type: 'divider',
185
+ });
186
+ blocks.push({
187
+ type: 'context',
188
+ elements: [
189
+ {
190
+ type: 'mrkdwn',
191
+ text: `Report generated on ${new Date().toLocaleString()} by Donobu`,
192
+ },
193
+ ],
194
+ });
195
+ return { blocks };
196
+ }
197
+ // Main execution
198
+ try {
199
+ const { jsonData, reportUrl } = readInput();
200
+ const slackBlocks = generateSlackBlocks(jsonData, reportUrl);
201
+ console.log(JSON.stringify(slackBlocks, null, 2));
202
+ }
203
+ catch (error) {
204
+ console.error('Error processing JSON:', error.message);
205
+ process.exit(1);
206
+ }
207
+ //# sourceMappingURL=playwright-json-to-slack-json.js.map