|
| 1 | +import Slack from '@slack/bolt' |
| 2 | +import dotenv from 'dotenv' |
| 3 | +import fs from 'fs' |
| 4 | + |
| 5 | +dotenv.config() |
| 6 | + |
| 7 | +const mochawesomeJsonOutput = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf-8') |
| 8 | +const mochawesomeReport = JSON.parse(mochawesomeJsonOutput) |
| 9 | + |
| 10 | +const totalSuites = mochawesomeReport.stats.suites |
| 11 | +const totalTests = mochawesomeReport.stats.tests |
| 12 | +const passedTests = mochawesomeReport.stats.passes |
| 13 | +const failedTests = mochawesomeReport.stats.failures |
| 14 | +const pendingTests = mochawesomeReport.stats.pending |
| 15 | +const durationInSeconds = mochawesomeReport.stats.duration / 1000 |
| 16 | + |
| 17 | +console.log(`Total Suites: ${totalSuites}`) |
| 18 | +console.log(`Total Tests: ${totalTests}`) |
| 19 | +console.log(`Passed Tests: ${passedTests}`) |
| 20 | +console.log(`Failed Tests: ${failedTests}`) |
| 21 | +console.log(`Pending Tests: ${pendingTests}`) |
| 22 | +console.log(`Total Duration: ${durationInSeconds.toFixed(2)} seconds`) |
| 23 | + |
| 24 | +const slackMessage = ` |
| 25 | +*Test Summary* |
| 26 | +Total Suites: ${totalSuites} |
| 27 | +Total Tests: ${totalTests} |
| 28 | +Passed Tests: ${passedTests} |
| 29 | +Failed Tests: ${failedTests} |
| 30 | +Pending Tests: ${pendingTests} |
| 31 | +Total Duration: ${durationInSeconds.toFixed(2)} seconds |
| 32 | +` |
| 33 | + |
| 34 | +const app = new Slack.App({ |
| 35 | + token: process.env.SLACK_BOT_TOKEN, |
| 36 | + signingSecret: process.env.SLACK_SIGNING_SECRET |
| 37 | +}) |
| 38 | + |
| 39 | +async function publishMessage (text) { |
| 40 | + await app.client.chat.postMessage({ |
| 41 | + token: process.env.SLACK_BOT_TOKEN, |
| 42 | + channel: process.env.SLACK_CHANNEL, |
| 43 | + text: text |
| 44 | + }) |
| 45 | +} |
| 46 | + |
| 47 | +publishMessage(slackMessage) |
0 commit comments