{"library":"slack-ctrf","title":"Slack Test Results Reporter","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install slack-ctrf"],"cli":{"name":"slack-ctrf","version":null}},"imports":["import { sendSlackReport } from 'slack-ctrf';","import { sendSlackMessage } from 'slack-ctrf';","import type { SlackReportOptions } from 'slack-ctrf';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { sendSlackReport } from 'slack-ctrf';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\n// Ensure environment variables are set for Slack authentication\n// For Webhook: export SLACK_WEBHOOK_URL='https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'\n// For OAuth: export SLACK_OAUTH_TOKEN='xoxb-YOUR_BOT_TOKEN' and export SLACK_CHANNEL_ID='C0123456789'\n\n// Create a dummy CTRF report file for demonstration\nconst dummyCtrfReportPath = path.join(process.cwd(), 'dummy-ctrf-report.json');\nconst dummyCtrfReport = {\n  id: 'report-123',\n  name: 'Example Test Run',\n  description: 'A sample test report generated for quickstart.',\n  summary: {\n    total: 5,\n    passed: 3,\n    failed: 1,\n    skipped: 1,\n    duration: 12345,\n  },\n  results: [\n    { name: 'Test A', status: 'passed', duration: 100 },\n    { name: 'Test B', status: 'failed', duration: 250, message: 'Assertion failed' },\n    { name: 'Test C', status: 'skipped', duration: 50 },\n    { name: 'Test D', status: 'passed', duration: 150 },\n    { name: 'Test E', status: 'passed', duration: 80 }\n  ],\n  build: { id: 'build-456', name: 'CI Build #456' }\n};\n\nfs.writeFileSync(dummyCtrfReportPath, JSON.stringify(dummyCtrfReport, null, 2));\n\nasync function main() {\n  try {\n    // Ensure one of these environment variables is set:\n    // SLACK_WEBHOOK_URL or (SLACK_OAUTH_TOKEN AND SLACK_CHANNEL_ID)\n    const webhookUrl = process.env.SLACK_WEBHOOK_URL ?? '';\n    const oauthToken = process.env.SLACK_OAUTH_TOKEN ?? '';\n    const channelId = process.env.SLACK_CHANNEL_ID ?? '';\n\n    if (!webhookUrl && (!oauthToken || !channelId)) {\n      console.error('Error: Either SLACK_WEBHOOK_URL or (SLACK_OAUTH_TOKEN and SLACK_CHANNEL_ID) must be set.');\n      process.exit(1);\n    }\n\n    console.log(`Sending Slack report for ${dummyCtrfReportPath}...`);\n\n    await sendSlackReport({\n      file: dummyCtrfReportPath, // Path to your CTRF report JSON\n      webhookUrl: webhookUrl,\n      oauthToken: oauthToken,\n      channelId: channelId,\n      title: 'Nightly Regression Test Results',\n      onFailOnly: false, // Send notification even if all tests pass\n      aiSummary: true, // Enable AI summary if configured\n    });\n    console.log('Slack report sent successfully.');\n  } catch (error) {\n    console.error('Failed to send Slack report:', error);\n    process.exit(1);\n  } finally {\n    // Clean up the dummy report file\n    fs.unlinkSync(dummyCtrfReportPath);\n  }\n}\n\nmain();\n","lang":"typescript","description":"Demonstrates how to programmatically send a Slack notification with test results from a CTRF report using environment variables for authentication.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}