report failed tests to slack

This commit is contained in:
A.J. Kaptijn 2024-03-14 17:32:48 +01:00
parent dd70238216
commit 7cb3970161
4 changed files with 39 additions and 6 deletions

21
dist/index.js generated vendored
View file

@ -382,6 +382,21 @@ class TestReporter {
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>` 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); yield webhook.send(req);
} }
@ -1650,8 +1665,8 @@ function getSuitesReport(tr, runIndex, options) {
const tsTime = (0, markdown_utils_1.formatTime)(s.time); const tsTime = (0, markdown_utils_1.formatTime)(s.time);
const tsName = s.name.startsWith(name) ? s.name.slice(name.length + 1) : s.name; 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 skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed');
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link; s.link = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link;
const tsNameLink = skipLink ? tsName : (0, markdown_utils_1.link)(tsName, tsAddr); 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 passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : ''; const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : '';
const skipped = s.skipped > 0 ? `${s.skipped}${markdown_utils_1.Icon.skip}` : ''; 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 sections = [];
const tsName = ts.name; const tsName = ts.name;
const tsSlug = makeSuiteSlug(runIndex, suiteIndex); const tsSlug = makeSuiteSlug(runIndex, suiteIndex);
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`; const tsNameLink = `<a id="${tsSlug.id}" href="${ts.link}">${tsName}</a>`;
const icon = getResultIcon(ts.result); const icon = getResultIcon(ts.result);
sections.push(`### ${icon}\xa0${tsNameLink}`); sections.push(`### ${icon}\xa0${tsNameLink}`);
sections.push('```'); sections.push('```');

View file

@ -328,6 +328,22 @@ class TestReporter {
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>` 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) await webhook.send(req)

View file

@ -199,8 +199,8 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
const tsTime = formatTime(s.time) const tsTime = formatTime(s.time)
const tsName = s.name.startsWith(name) ? s.name.slice(name.length + 1) : s.name 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 skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link s.link = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr) const tsNameLink = skipLink ? tsName : link(tsName, s.link)
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : '' const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : '' const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
const skipped = s.skipped > 0 ? `${s.skipped}${Icon.skip}` : '' 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 tsName = ts.name
const tsSlug = makeSuiteSlug(runIndex, suiteIndex) const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>` const tsNameLink = `<a id="${tsSlug.id}" href="${ts.link}">${tsName}</a>`
const icon = getResultIcon(ts.result) const icon = getResultIcon(ts.result)
sections.push(`### ${icon}\xa0${tsNameLink}`) sections.push(`### ${icon}\xa0${tsNameLink}`)

View file

@ -82,6 +82,8 @@ export class TestSuiteResult {
private totalTime?: number private totalTime?: number
) {} ) {}
link?: string
get tests(): number { get tests(): number {
return this.groups.reduce((sum, g) => sum + g.tests.length, 0) return this.groups.reduce((sum, g) => sum + g.tests.length, 0)
} }