From 7cb3970161ae4f44119db279d8673e5971e4662a Mon Sep 17 00:00:00 2001 From: "A.J. Kaptijn" Date: Thu, 14 Mar 2024 17:32:48 +0100 Subject: [PATCH] report failed tests to slack --- dist/index.js | 21 ++++++++++++++++++--- src/main.ts | 16 ++++++++++++++++ src/report/get-report.ts | 6 +++--- src/test-results.ts | 2 ++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index d1ddb8d..f7fb7cb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -382,6 +382,21 @@ class TestReporter { text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>` } }); + if (failed <= 10) { + tr.failedSuites.map((suite) => { + suite.failedGroups.map((group) => { + group.failedTests.map((test) => { + req.blocks.push({ + type: 'section', + text: { + type: 'mrkdwn', + text: `:red_circle: <${suite.link}|${test.name}>` + } + }); + }); + }); + }); + } }); yield webhook.send(req); } @@ -1650,8 +1665,8 @@ function getSuitesReport(tr, runIndex, options) { const tsTime = (0, markdown_utils_1.formatTime)(s.time); const tsName = s.name.startsWith(name) ? s.name.slice(name.length + 1) : s.name; const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed'); - const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link; - const tsNameLink = skipLink ? tsName : (0, markdown_utils_1.link)(tsName, tsAddr); + s.link = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link; + const tsNameLink = skipLink ? tsName : (0, markdown_utils_1.link)(tsName, s.link); const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : ''; const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : ''; const skipped = s.skipped > 0 ? `${s.skipped}${markdown_utils_1.Icon.skip}` : ''; @@ -1679,7 +1694,7 @@ function getTestsReport(ts, runIndex, suiteIndex, options) { const sections = []; const tsName = ts.name; const tsSlug = makeSuiteSlug(runIndex, suiteIndex); - const tsNameLink = `${tsName}`; + const tsNameLink = `${tsName}`; const icon = getResultIcon(ts.result); sections.push(`### ${icon}\xa0${tsNameLink}`); sections.push('```'); diff --git a/src/main.ts b/src/main.ts index a393660..0e4d1c5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -328,6 +328,22 @@ class TestReporter { text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>` } }) + + if (failed <= 10) { + tr.failedSuites.map(suite => { + suite.failedGroups.map(group => { + group.failedTests.map(test => { + req.blocks.push({ + type: 'section', + text: { + type: 'mrkdwn', + text: `:red_circle: <${suite.link}|${test.name}>` + } + }) + }) + }) + }) + } }) await webhook.send(req) diff --git a/src/report/get-report.ts b/src/report/get-report.ts index b18a66e..a8a29ea 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -199,8 +199,8 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt const tsTime = formatTime(s.time) const tsName = s.name.startsWith(name) ? s.name.slice(name.length + 1) : s.name const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed') - const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link - const tsNameLink = skipLink ? tsName : link(tsName, tsAddr) + s.link = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link + const tsNameLink = skipLink ? tsName : link(tsName, s.link) const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : '' const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : '' const skipped = s.skipped > 0 ? `${s.skipped}${Icon.skip}` : '' @@ -234,7 +234,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe const tsName = ts.name const tsSlug = makeSuiteSlug(runIndex, suiteIndex) - const tsNameLink = `${tsName}` + const tsNameLink = `${tsName}` const icon = getResultIcon(ts.result) sections.push(`### ${icon}\xa0${tsNameLink}`) diff --git a/src/test-results.ts b/src/test-results.ts index 72b6e1c..ec8800f 100644 --- a/src/test-results.ts +++ b/src/test-results.ts @@ -82,6 +82,8 @@ export class TestSuiteResult { private totalTime?: number ) {} + link?: string + get tests(): number { return this.groups.reduce((sum, g) => sum + g.tests.length, 0) }