New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

slack-ctrf

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slack-ctrf - npm Package Compare versions

Comparing version 0.0.17 to 0.0.18

dist/slack-reporter.d.ts

196

dist/cli.js

@@ -19,5 +19,30 @@ #!/usr/bin/env node

const ctrf_parser_1 = require("./ctrf-parser");
const message_formatter_1 = require("./message-formatter");
const slack_notify_1 = require("./slack-notify");
const common_1 = require("./utils/common");
const slack_reporter_1 = require("./slack-reporter");
const sharedOptions = {
title: {
alias: 't',
type: 'string',
description: 'Title of notification',
},
prefix: {
alias: 'p',
type: 'string',
description: 'Custom text to add as a prefix to the message',
default: '',
},
suffix: {
alias: 's',
type: 'string',
description: 'Custom text to add as a suffix to the message',
default: '',
},
};
const consolidatedOption = {
consolidated: {
alias: 'c',
type: 'boolean',
description: 'Consolidate all failure summaries into a single message',
default: false,
},
};
const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))

@@ -37,30 +62,7 @@ .command('results <path>', 'Send test results summary to Slack', (yargs) => {

})
.option('title', {
alias: 't',
type: 'string',
description: 'Title of notification',
default: "Test Results",
})
.option('prefix', {
alias: 'p',
type: 'string',
description: 'Custom text to add as a prefix to the message',
default: '',
})
.option('suffix', {
alias: 's',
type: 'string',
description: 'Custom text to add as a suffix to the message',
default: '',
});
.options(sharedOptions);
}, (argv) => __awaiter(void 0, void 0, void 0, function* () {
try {
const ctrfData = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
if (argv.onFailOnly && ctrfData.results.summary.failed === 0) {
console.log('No failed tests. Message not sent.');
return;
}
const message = (0, message_formatter_1.formatResultsMessage)(ctrfData, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
yield (0, slack_notify_1.sendSlackMessage)(message);
console.log('Results message sent to Slack.');
const report = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
yield (0, slack_reporter_1.sendTestResultsToSlack)(report, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
}

@@ -77,53 +79,8 @@ catch (error) {

})
.option('title', {
alias: 't',
type: 'string',
description: 'Title of notification',
default: ":x: Failed Test",
})
.option('prefix', {
alias: 'p',
type: 'string',
description: 'Custom text to add as a prefix to the message',
default: '',
})
.option('suffix', {
alias: 's',
type: 'string',
description: 'Custom text to add as a suffix to the message',
default: '',
})
.option('consolidated', {
alias: 'c',
type: 'boolean',
description: 'Consolidate all failure summaries into a single message',
default: false,
});
.options(sharedOptions)
.option(consolidatedOption);
}, (argv) => __awaiter(void 0, void 0, void 0, function* () {
try {
const ctrfData = (0, common_1.stripAnsiFromErrors)((0, ctrf_parser_1.parseCtrfFile)(argv.path));
if (argv.consolidated) {
const message = (0, message_formatter_1.formatConsolidatedFailedTestSummary)(ctrfData.results.tests, ctrfData.results.environment, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
if (message) {
yield (0, slack_notify_1.sendSlackMessage)(message);
console.log('Failed test summary sent to Slack.');
}
else {
console.log('No failed test summary detected. No message sent.');
}
}
else {
for (const test of ctrfData.results.tests) {
if (test.status === "failed") {
const message = (0, message_formatter_1.formatFailedTestSummary)(test, ctrfData.results.environment, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
if (message) {
yield (0, slack_notify_1.sendSlackMessage)(message);
console.log('Failed test summary sent to Slack.');
}
else {
console.log('No failed test summary detected. No message sent');
}
}
}
}
const report = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
yield (0, slack_reporter_1.sendFailedResultsToSlack)(report, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix, consolidated: argv.consolidated });
}

@@ -140,31 +97,7 @@ catch (error) {

})
.option('title', {
alias: 't',
type: 'string',
description: 'Title of notification',
default: "Flaky Tests",
})
.option('prefix', {
alias: 'p',
type: 'string',
description: 'Custom text to add as a prefix to the message',
default: '',
})
.option('suffix', {
alias: 's',
type: 'string',
description: 'Custom text to add as a suffix to the message',
default: '',
});
.options(sharedOptions);
}, (argv) => __awaiter(void 0, void 0, void 0, function* () {
try {
const ctrfData = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
const message = (0, message_formatter_1.formatFlakyTestsMessage)(ctrfData, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
if (message) {
yield (0, slack_notify_1.sendSlackMessage)(message);
console.log('Flaky tests message sent to Slack.');
}
else {
console.log('No flaky tests detected. No message sent.');
}
const report = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
yield (0, slack_reporter_1.sendFlakyResultsToSlack)(report, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
}

@@ -181,53 +114,8 @@ catch (error) {

})
.option('title', {
alias: 't',
type: 'string',
description: 'Title of notification',
default: "AI Summary",
})
.option('prefix', {
alias: 'p',
type: 'string',
description: 'Custom text to add as a prefix to the message',
default: '',
})
.option('suffix', {
alias: 's',
type: 'string',
description: 'Custom text to add as a suffix to the message',
default: '',
})
.option('consolidated', {
alias: 'c',
type: 'boolean',
description: 'Consolidate all failure summaries into a single message',
default: false,
});
.options(sharedOptions)
.option(consolidatedOption);
}, (argv) => __awaiter(void 0, void 0, void 0, function* () {
try {
const ctrfData = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
if (argv.consolidated) {
const message = (0, message_formatter_1.formatConsolidatedAiTestSummary)(ctrfData.results.tests, ctrfData.results.environment, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix });
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.');
}
}
else {
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, prefix: argv.prefix, suffix: argv.suffix });
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');
}
}
}
}
const report = (0, ctrf_parser_1.parseCtrfFile)(argv.path);
yield (0, slack_reporter_1.sendAISummaryToSlack)(report, { title: argv.title, prefix: argv.prefix, suffix: argv.suffix, consolidated: argv.consolidated });
}

@@ -234,0 +122,0 @@ catch (error) {

@@ -8,7 +8,9 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
const common_1 = require("./utils/common");
const parseCtrfFile = (filePath) => {
const fileContent = fs_1.default.readFileSync(filePath, 'utf-8');
const result = JSON.parse(fileContent);
let result = JSON.parse(fileContent);
result = (0, common_1.stripAnsiFromErrors)(result);
return result;
};
exports.parseCtrfFile = parseCtrfFile;

@@ -1,3 +0,2 @@

import { sendSlackMessage } from './slack-notify';
import { formatResultsMessage, formatFlakyTestsMessage, formatAiTestSummary, formatConsolidatedAiTestSummary, formatFailedTestSummary, formatConsolidatedFailedTestSummary } from './message-formatter';
export { sendSlackMessage, formatResultsMessage, formatFlakyTestsMessage, formatAiTestSummary, formatConsolidatedAiTestSummary, formatFailedTestSummary, formatConsolidatedFailedTestSummary, };
import { sendTestResultsToSlack, sendFailedResultsToSlack, sendFlakyResultsToSlack, sendAISummaryToSlack } from './slack-reporter';
export { sendTestResultsToSlack, sendFailedResultsToSlack, sendFlakyResultsToSlack, sendAISummaryToSlack };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatConsolidatedFailedTestSummary = exports.formatFailedTestSummary = exports.formatConsolidatedAiTestSummary = exports.formatAiTestSummary = exports.formatFlakyTestsMessage = exports.formatResultsMessage = exports.sendSlackMessage = void 0;
const slack_notify_1 = require("./slack-notify");
Object.defineProperty(exports, "sendSlackMessage", { enumerable: true, get: function () { return slack_notify_1.sendSlackMessage; } });
const message_formatter_1 = require("./message-formatter");
Object.defineProperty(exports, "formatResultsMessage", { enumerable: true, get: function () { return message_formatter_1.formatResultsMessage; } });
Object.defineProperty(exports, "formatFlakyTestsMessage", { enumerable: true, get: function () { return message_formatter_1.formatFlakyTestsMessage; } });
Object.defineProperty(exports, "formatAiTestSummary", { enumerable: true, get: function () { return message_formatter_1.formatAiTestSummary; } });
Object.defineProperty(exports, "formatConsolidatedAiTestSummary", { enumerable: true, get: function () { return message_formatter_1.formatConsolidatedAiTestSummary; } });
Object.defineProperty(exports, "formatFailedTestSummary", { enumerable: true, get: function () { return message_formatter_1.formatFailedTestSummary; } });
Object.defineProperty(exports, "formatConsolidatedFailedTestSummary", { enumerable: true, get: function () { return message_formatter_1.formatConsolidatedFailedTestSummary; } });
exports.sendAISummaryToSlack = exports.sendFlakyResultsToSlack = exports.sendFailedResultsToSlack = exports.sendTestResultsToSlack = void 0;
const slack_reporter_1 = require("./slack-reporter");
Object.defineProperty(exports, "sendTestResultsToSlack", { enumerable: true, get: function () { return slack_reporter_1.sendTestResultsToSlack; } });
Object.defineProperty(exports, "sendFailedResultsToSlack", { enumerable: true, get: function () { return slack_reporter_1.sendFailedResultsToSlack; } });
Object.defineProperty(exports, "sendFlakyResultsToSlack", { enumerable: true, get: function () { return slack_reporter_1.sendFlakyResultsToSlack; } });
Object.defineProperty(exports, "sendAISummaryToSlack", { enumerable: true, get: function () { return slack_reporter_1.sendAISummaryToSlack; } });
import { CtrfEnvironment, CtrfReport, CtrfTest } from '../types/ctrf';
type Options = {
title: string;
prefix?: string;
suffix?: string;
};
import { Options } from '../types/reporter';
export declare const formatResultsMessage: (ctrf: CtrfReport, options?: Options) => object;

@@ -13,2 +9,1 @@ export declare const formatFlakyTestsMessage: (ctrf: CtrfReport, options?: Options) => object | null;

export declare const formatFailedTestSummary: (test: CtrfTest, environment: CtrfEnvironment | undefined, options?: Options) => object | null;
export {};

@@ -102,3 +102,3 @@ "use strict";

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -207,3 +207,3 @@ ]

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -320,3 +320,3 @@ ]

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -447,3 +447,3 @@ ]

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -578,3 +578,3 @@ ]

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -694,3 +694,3 @@ ]

type: "mrkdwn",
text: "<https://github.com/ctrf-io/slack-ctrf|Slack CTRF Test Reporter>"
text: "<https://github.com/ctrf-io/slack-ctrf|Slack Test Reporter> by <https://ctrf.io|CTRF :green_heart:>"
}

@@ -697,0 +697,0 @@ ]

{
"name": "slack-ctrf",
"version": "0.0.17",
"version": "0.0.18",
"description": "Send Slack notifications with test results from popular testing frameworks",

@@ -29,2 +29,2 @@ "main": "dist/index.js",

}
}
}

@@ -162,2 +162,23 @@ # Slack Test Results Notification

## Programmatic Usage
You can use the package programmatically to send notifications to Slack. To install the package, run:
```sh
npm install slack-ctrf
```
The package exports the following functions:
- `sendTestResultsToSlack`
- `sendFlakyResultsToSlack`
- `sendFailedResultsToSlack`
- `sendAISummaryToSlack`
```ts
import { sendTestResultsToSlack } from 'slack-ctrf';
sendTestResultsToSlack(report);
```
## What is CTRF?

@@ -164,0 +185,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc