Unverified Commit 6adedb5e authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[test] Add test suite name for Tests failures table (#89258)

parent cf07866e
...@@ -113,13 +113,14 @@ const mockTrace = () => ({ ...@@ -113,13 +113,14 @@ const mockTrace = () => ({
// which types we have configured to run separate // which types we have configured to run separate
const configuredTestTypes = Object.values(testFilters) const configuredTestTypes = Object.values(testFilters)
/** @type {Map<string, { output: string, failedCases: string[] }>} */
const errorsPerTests = new Map() const errorsPerTests = new Map()
async function maybeLogSummary() { async function maybeLogSummary() {
if (process.env.CI && errorsPerTests.size > 0) { if (process.env.CI && errorsPerTests.size > 0) {
const outputTemplate = ` const outputTemplate = `
${Array.from(errorsPerTests.entries()) ${Array.from(errorsPerTests.entries())
.map(([test, output]) => { .map(([test, { output }]) => {
return ` return `
<details> <details>
<summary>${test}</summary> <summary>${test}</summary>
...@@ -133,20 +134,27 @@ ${output} ...@@ -133,20 +134,27 @@ ${output}
}) })
.join('\n')}` .join('\n')}`
// Build table rows with one row per failed test case
const tableRows = []
for (const [test, { failedCases }] of errorsPerTests.entries()) {
const testLink = `<a href="https://github.com/vercel/next.js/blob/canary/${test}">${test}</a>`
if (failedCases.length === 0) {
tableRows.push(['Unknown', testLink])
} else {
for (const caseName of failedCases) {
tableRows.push([caseName, testLink])
}
}
}
await core.summary await core.summary
.addHeading('Tests failures') .addHeading('Tests failures')
.addTable([ .addTable([
[ [
{ { data: 'Test Name', header: true },
data: 'Test suite', { data: 'Test Path', header: true },
header: true,
},
], ],
...Array.from(errorsPerTests.entries()).map(([test]) => { ...tableRows,
return [
`<a href="https://github.com/vercel/next.js/blob/canary/${test}">${test}</a>`,
]
}),
]) ])
.addRaw(outputTemplate) .addRaw(outputTemplate)
.write() .write()
...@@ -608,7 +616,7 @@ ${ENDGROUP}`) ...@@ -608,7 +616,7 @@ ${ENDGROUP}`)
} }
if (process.env.CI) { if (process.env.CI) {
errorsPerTests.set(test.file, output) errorsPerTests.set(test.file, { output, failedCases: [] })
} }
if (isExpanded) { if (isExpanded) {
...@@ -704,6 +712,28 @@ ${ENDGROUP}`) ...@@ -704,6 +712,28 @@ ${ENDGROUP}`)
'utf8' 'utf8'
) )
const obj = JSON.parse(testsOutput) const obj = JSON.parse(testsOutput)
// Extract failed test case names from Jest JSON output
if (!passed && process.env.CI) {
const failedCases = []
for (const testResult of obj.testResults || []) {
for (const assertion of testResult.assertionResults || []) {
if (assertion.status === 'failed') {
const caseName = [
...(assertion.ancestorTitles || []),
assertion.title,
].join(' > ')
failedCases.push(caseName)
}
}
}
// Update errorsPerTests with failed case names
const existing = errorsPerTests.get(test.file)
if (existing) {
existing.failedCases = failedCases
}
}
obj.processEnv = { obj.processEnv = {
NEXT_TEST_MODE: process.env.NEXT_TEST_MODE, NEXT_TEST_MODE: process.env.NEXT_TEST_MODE,
HEADLESS: process.env.HEADLESS, HEADLESS: process.env.HEADLESS,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment