slack-ctrf
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -107,3 +107,35 @@ #!/usr/bin/env node | ||
})) | ||
.command('ai <path>', 'Send ai failed test summary to Slack', (yargs) => { | ||
return yargs.positional('path', { | ||
describe: 'Path to the CTRF file', | ||
type: 'string', | ||
demandOption: true, | ||
}) | ||
.option('title', { | ||
alias: 't', | ||
type: 'string', | ||
description: 'Title of notification', | ||
default: "AI Summary", | ||
}); | ||
}, (argv) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const ctrfData = (0, ctrf_parser_1.parseCtrfFile)(argv.path); | ||
for (const test of ctrfData.results.tests) { | ||
if (test.status === "failed") { | ||
const message = (0, message_formatter_1.formatAiTestSummary)(test, ctrfData.results.environment, { title: argv.title }); | ||
if (message) { | ||
yield (0, slack_notify_1.sendSlackMessage)(message); | ||
console.log('AI test summary sent to Slack.'); | ||
} | ||
else { | ||
console.log('No AI summary detected. No message sent.'); | ||
} | ||
} | ||
} | ||
} | ||
catch (error) { | ||
console.error('Error:', error.message); | ||
} | ||
})) | ||
.help() | ||
.argv; |
@@ -1,2 +0,2 @@ | ||
import { CtrfReport } from '../types/ctrf'; | ||
import { CtrfEnvironment, CtrfReport, CtrfTest } from '../types/ctrf'; | ||
type Options = { | ||
@@ -8,2 +8,3 @@ title: string; | ||
export declare const formatFlakyTestsMessage: (ctrf: CtrfReport, options?: Options) => object | null; | ||
export declare const formatAiTestSummary: (test: CtrfTest, environment: CtrfEnvironment | undefined, options?: Options) => object | null; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatFlakyTestsMessage = exports.formatFailedTestsMessage = exports.formatResultsMessage = void 0; | ||
exports.formatAiTestSummary = exports.formatFlakyTestsMessage = exports.formatFailedTestsMessage = exports.formatResultsMessage = void 0; | ||
const formatResultsMessage = (ctrf, options) => { | ||
@@ -191,1 +191,86 @@ const { summary, environment } = ctrf.results; | ||
exports.formatFlakyTestsMessage = formatFlakyTestsMessage; | ||
const formatAiTestSummary = (test, environment, options) => { | ||
const { name, ai, status } = test; | ||
if (!ai || status === "passed") { | ||
return null; | ||
} | ||
let title = (options === null || options === void 0 ? void 0 : options.title) ? options === null || options === void 0 ? void 0 : options.title : `AI Test summary`; | ||
let missingEnvProperties = []; | ||
let buildInfo = "*Build:* No build information provided"; | ||
if (environment) { | ||
const { buildName, buildNumber, buildUrl } = environment; | ||
if (buildName && buildNumber) { | ||
const buildText = buildUrl ? `<${buildUrl}|${buildName} #${buildNumber}>` : `${buildName} #${buildNumber}`; | ||
buildInfo = `*Build:* ${buildText}`; | ||
} | ||
else if (buildName || buildNumber) { | ||
buildInfo = `*Build:* ${buildName || ''} ${buildNumber || ''}`; | ||
} | ||
if (!buildName) { | ||
missingEnvProperties.push('buildName'); | ||
} | ||
if (!buildNumber) { | ||
missingEnvProperties.push('buildNumber'); | ||
} | ||
if (!buildUrl) { | ||
missingEnvProperties.push('buildUrl'); | ||
} | ||
} | ||
else { | ||
missingEnvProperties = ['buildName', 'buildNumber', 'buildUrl']; | ||
} | ||
const color = '#FFD700'; | ||
const resultText = `*Status:* Test *failed* :x:`; | ||
const aiSummaryText = `*AI Summary:* ${ai}`; | ||
const blocks = [ | ||
{ | ||
type: "header", | ||
text: { | ||
type: "plain_text", | ||
text: `${title}\n${buildInfo}`, | ||
emoji: true | ||
} | ||
}, | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `*Test Name:* ${name}` | ||
} | ||
}, | ||
{ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `${resultText}\n${aiSummaryText}` | ||
} | ||
} | ||
]; | ||
if (missingEnvProperties.length > 0) { | ||
blocks.push({ | ||
type: "section", | ||
text: { | ||
type: "mrkdwn", | ||
text: `:warning: Missing environment properties: ${missingEnvProperties.join(', ')}. Add these to your test for a better experience.` | ||
} | ||
}); | ||
} | ||
blocks.push({ | ||
type: "context", | ||
elements: [ | ||
{ | ||
type: "mrkdwn", | ||
text: "<https://github.com/ctrf-io/slack-ctrf|a CTRF plugin>" | ||
} | ||
] | ||
}); | ||
return { | ||
attachments: [ | ||
{ | ||
color: color, | ||
blocks: blocks | ||
} | ||
] | ||
}; | ||
}; | ||
exports.formatAiTestSummary = formatAiTestSummary; |
{ | ||
"name": "slack-ctrf", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -49,2 +49,4 @@ # Slack Test Results Notification | ||
### Results | ||
To send the test results summary to Slack: | ||
@@ -58,2 +60,16 @@ | ||
### AI Summary | ||
To send AI failed test summary to Slack: | ||
```sh | ||
npx slack-ctrf ai /path/to/ctrf-report.json | ||
``` | ||
![AI view](assets/ai.png) | ||
See the [AI Test Reporter](https://github.com/ctrf-io/ai-test-reporter) to add AI summaries to your CTRF report | ||
### Flaky | ||
To send flaky test report to Slack: | ||
@@ -83,3 +99,3 @@ | ||
To can choose a custom title for your notification, use the `--title` option: | ||
You can choose a custom title for your notification, use the `--title` option: | ||
@@ -86,0 +102,0 @@ ```sh |
23705
489
141