Registry / communication / slack-ctrf

slack-ctrf

JSON →
library0.0.31jsnpmunverified

slack-ctrf is an open-source, community-driven JavaScript/TypeScript library designed to send comprehensive test results to Slack channels. It supports the Common Test Report Format (CTRF) to ensure compatibility across various testing frameworks. The package, currently at version 0.0.31, is under active development, as indicated by frequent, small releases adding new features like AI summaries, custom titles, and glob patterns for report processing. Key differentiators include its deep integration with the CTRF ecosystem, support for detailed reports including failed and flaky test analyses, AI-generated summaries, and flexible templating for custom Slack messages. It aims to streamline CI/CD pipelines by providing conditional notifications, such as sending alerts only when tests fail, and supports both Slack Incoming Webhooks and OAuth Tokens for authentication.

npm install slack-ctrf
INSTALL
IMPORT
SIG · SLACK-CTRF
S
slack-ctrf
communicationjavascriptv0.0.31
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sendSlackReport
import { sendSlackReport } from 'slack-ctrf';
const sendSlackReport = require('slack-ctrf');
This is the primary function for sending CTRF-based test reports. The package is ESM-first with TypeScript types.
sendSlackMessage
import { sendSlackMessage } from 'slack-ctrf';
import sendSlackMessage from 'slack-ctrf';
A lower-level utility for sending generic Slack messages, often used for custom templates or simpler notifications.
SlackReportOptions
import type { SlackReportOptions } from 'slack-ctrf';
Import the type definition for configuring `sendSlackReport`. Always use `import type` for type-only imports to prevent bundling issues.

Demonstrates how to programmatically send a Slack notification with test results from a CTRF report using environment variables for authentication.

import { sendSlackReport } from 'slack-ctrf'; import * as fs from 'fs'; import * as path from 'path'; // Ensure environment variables are set for Slack authentication // For Webhook: export SLACK_WEBHOOK_URL='https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' // For OAuth: export SLACK_OAUTH_TOKEN='xoxb-YOUR_BOT_TOKEN' and export SLACK_CHANNEL_ID='C0123456789' // Create a dummy CTRF report file for demonstration const dummyCtrfReportPath = path.join(process.cwd(), 'dummy-ctrf-report.json'); const dummyCtrfReport = { id: 'report-123', name: 'Example Test Run', description: 'A sample test report generated for quickstart.', summary: { total: 5, passed: 3, failed: 1, skipped: 1, duration: 12345, }, results: [ { name: 'Test A', status: 'passed', duration: 100 }, { name: 'Test B', status: 'failed', duration: 250, message: 'Assertion failed' }, { name: 'Test C', status: 'skipped', duration: 50 }, { name: 'Test D', status: 'passed', duration: 150 }, { name: 'Test E', status: 'passed', duration: 80 } ], build: { id: 'build-456', name: 'CI Build #456' } }; fs.writeFileSync(dummyCtrfReportPath, JSON.stringify(dummyCtrfReport, null, 2)); async function main() { try { // Ensure one of these environment variables is set: // SLACK_WEBHOOK_URL or (SLACK_OAUTH_TOKEN AND SLACK_CHANNEL_ID) const webhookUrl = process.env.SLACK_WEBHOOK_URL ?? ''; const oauthToken = process.env.SLACK_OAUTH_TOKEN ?? ''; const channelId = process.env.SLACK_CHANNEL_ID ?? ''; if (!webhookUrl && (!oauthToken || !channelId)) { console.error('Error: Either SLACK_WEBHOOK_URL or (SLACK_OAUTH_TOKEN and SLACK_CHANNEL_ID) must be set.'); process.exit(1); } console.log(`Sending Slack report for ${dummyCtrfReportPath}...`); await sendSlackReport({ file: dummyCtrfReportPath, // Path to your CTRF report JSON webhookUrl: webhookUrl, oauthToken: oauthToken, channelId: channelId, title: 'Nightly Regression Test Results', onFailOnly: false, // Send notification even if all tests pass aiSummary: true, // Enable AI summary if configured }); console.log('Slack report sent successfully.'); } catch (error) { console.error('Failed to send Slack report:', error); process.exit(1); } finally { // Clean up the dummy report file fs.unlinkSync(dummyCtrfReportPath); } } main();
slack-ctrf --version
Debug
Known issues
breakingThe package is in a pre-1.0 state (v0.0.31), meaning APIs and internal structures may change without adhering to semantic versioning for breaking changes. Developers should expect more frequent updates that might introduce breaking changes.
fix
Always pin to a specific patch version (e.g., `~0.0.31` or exact `0.0.31`) and review release notes for each update. Consider using `npm ci` for consistent builds.
affects: <1.0.0
gotchaNode.js version requirement is strict. The package explicitly requires Node.js version `>=20.19.0`. Using older versions may lead to runtime errors or unexpected behavior.
fix
Ensure your Node.js environment is updated to at least version 20.19.0. Use `nvm` or your preferred Node.js version manager to switch versions.
affects: <=0.0.31
gotchaSensitive Slack credentials (Webhook URLs, OAuth Tokens, Channel IDs) should be handled as secrets and never hardcoded into source control. Exposure can lead to unauthorized access to your Slack workspace.
fix
Always use environment variables (`process.env.SLACK_WEBHOOK_URL`), secret management systems in CI/CD, or secure configuration files. Avoid committing secrets directly to repositories.
affects: >=0.0.1
deprecatedSlack API updates deprecating classic apps and certain API methods (e.g., `files.upload`) might impact custom message templates that rely on older patterns. Ensure your Slack app configuration and message payloads adhere to the latest Slack API guidelines.
fix
Regularly consult the Slack API Changelog and developer documentation for updates. When building custom messages, prioritize Block Kit for future compatibility.
affects: >=0.0.1
Errors
Common errors & fixes
Error: SLACK_WEBHOOK_URL environment variable is not set.
The required Slack webhook URL or OAuth credentials were not provided, either as environment variables or via CLI options.
fix
Set the `SLACK_WEBHOOK_URL` environment variable, or if using OAuth, set both `SLACK_OAUTH_TOKEN` and `SLACK_CHANNEL_ID` before running the command or script. Alternatively, pass them via CLI flags like `--webhook-url`.
Error: ENOENT: no such file or directory, 'path/to/your/report.json'
The specified CTRF report file path does not exist or is inaccessible.
fix
Verify that the path to your CTRF report (`--file` option or programmatic `file` property) is correct and the file exists. Ensure the process has read permissions for the file.
Error: Missing Slack 'chat:write' scope for OAuth token.
When using an OAuth token, the associated Slack app bot user lacks the necessary 'chat:write' permission to post messages to channels.
fix
Go to your Slack App settings, navigate to 'OAuth & Permissions', and ensure the 'chat:write' scope is added to your bot token. Reinstall the app to your workspace if scopes were changed.
TypeError: Cannot read properties of undefined (reading 'summary')
The provided CTRF report JSON file is either empty, malformed, or does not conform to the expected CTRF schema, leading to failed data parsing.
fix
Validate your CTRF report using `ctrf` package's validation utilities (e.g., `validateStrict` from `ctrf`). Ensure the report contains the required `summary` and `results` fields.
Upgrade
Version history
0.0.31latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources