Skip to content

Commit 62ab0e3

Browse files
authored
ci: add job summary to the test suite runs (#56742)
This PR adds Github Actions summaries to the test suite that runs in the CI so that you can easily visualise which tests failed + what the relevant log was instead of parsing the logs yourself. Example here https://github.com/vercel/next.js/actions/runs/6495658699 ![CleanShot 2023-10-12 at 14 57 32@2x](https://github.com/vercel/next.js/assets/11064311/7d65496b-6e28-460a-8bef-3f2e91266d00)
1 parent b6cce9c commit 62ab0e3

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"update-google-fonts": "node ./scripts/update-google-fonts.js"
5959
},
6060
"devDependencies": {
61+
"@actions/core": "1.10.1",
6162
"@babel/core": "7.18.0",
6263
"@babel/eslint-parser": "7.18.2",
6364
"@babel/generator": "7.18.0",

pnpm-lock.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run-tests.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { spawn, exec: execOrig } = require('child_process')
1111
const { createNextInstall } = require('./test/lib/create-next-install')
1212
const glob = promisify(_glob)
1313
const exec = promisify(execOrig)
14+
const core = require('@actions/core')
1415

1516
function escapeRegexp(str) {
1617
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
@@ -73,6 +74,45 @@ const mockTrace = () => ({
7374

7475
// which types we have configured to run separate
7576
const configuredTestTypes = Object.values(testFilters)
77+
const errorsPerTests = new Map()
78+
79+
async function maybeLogSummary() {
80+
if (process.env.CI && errorsPerTests.size > 0) {
81+
const outputTemplate = `
82+
${Array.from(errorsPerTests.entries())
83+
.map(([test, output]) => {
84+
return `
85+
<details>
86+
<summary>${test}</summary>
87+
88+
\`\`\`
89+
${output}
90+
\`\`\`
91+
92+
</details>
93+
`
94+
})
95+
.join('\n')}`
96+
97+
await core.summary
98+
.addHeading('Tests failures')
99+
.addTable([
100+
[
101+
{
102+
data: 'Test suite',
103+
header: true,
104+
},
105+
],
106+
...Array.from(errorsPerTests.entries()).map(([test]) => {
107+
return [
108+
`<a href="https://github.com/vercel/next.js/blob/canary/${test}">${test}</a>`,
109+
]
110+
}),
111+
])
112+
.addRaw(outputTemplate)
113+
.write()
114+
}
115+
}
76116

77117
const cleanUpAndExit = async (code) => {
78118
if (process.env.NEXT_TEST_STARTER) {
@@ -81,6 +121,9 @@ const cleanUpAndExit = async (code) => {
81121
if (process.env.NEXT_TEST_TEMP_REPO) {
82122
await fs.remove(process.env.NEXT_TEST_TEMP_REPO)
83123
}
124+
if (process.env.CI) {
125+
await maybeLogSummary()
126+
}
84127
console.log(`exiting with code ${code}`)
85128

86129
setTimeout(() => {
@@ -472,11 +515,19 @@ ${ENDGROUP}`)
472515
} else {
473516
process.stdout.write(`${GROUP}${test.file} output\n`)
474517
}
518+
519+
let output = ''
475520
// limit out to last 64kb so that we don't
476521
// run out of log room in CI
477522
for (const { chunk } of outputChunks) {
478523
process.stdout.write(chunk)
524+
output += chunk.toString()
479525
}
526+
527+
if (process.env.CI && !killed) {
528+
errorsPerTests.set(test.file, output)
529+
}
530+
480531
if (isExpanded) {
481532
process.stdout.write(`end of ${test.file} output\n`)
482533
} else {

0 commit comments

Comments
 (0)