Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add job summary to the test suite runs #56742

Merged
merged 17 commits into from
Oct 12, 2023
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"update-google-fonts": "node ./scripts/update-google-fonts.js"
},
"devDependencies": {
"@actions/core": "1.10.1",
"@babel/core": "7.18.0",
"@babel/eslint-parser": "7.18.2",
"@babel/generator": "7.18.0",
Expand Down
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { spawn, exec: execOrig } = require('child_process')
const { createNextInstall } = require('./test/lib/create-next-install')
const glob = promisify(_glob)
const exec = promisify(execOrig)
const core = require('@actions/core')

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

// which types we have configured to run separate
const configuredTestTypes = Object.values(testFilters)
const errorsPerTests = new Map()

async function maybeLogSummary() {
if (process.env.CI && errorsPerTests.size > 0) {
const outputTemplate = `
${Array.from(errorsPerTests.entries())
.map(([test, output]) => {
return `
<details>
<summary>${test}</summary>

\`\`\`
${output}
\`\`\`

</details>
`
})
.join('\n')}`

await core.summary
.addHeading('Tests failures')
.addTable([
[
{
data: 'Test suite',
header: true,
},
],
...Array.from(errorsPerTests.entries()).map(([test]) => {
return [
`<a href="https://github.com/vercel/next.js/blob/canary/${test}">${test}</a>`,
]
}),
])
.addRaw(outputTemplate)
.write()
}
}

const cleanUpAndExit = async (code) => {
if (process.env.NEXT_TEST_STARTER) {
Expand All @@ -81,6 +121,9 @@ const cleanUpAndExit = async (code) => {
if (process.env.NEXT_TEST_TEMP_REPO) {
await fs.remove(process.env.NEXT_TEST_TEMP_REPO)
}
if (process.env.CI) {
await maybeLogSummary()
}
console.log(`exiting with code ${code}`)

setTimeout(() => {
Expand Down Expand Up @@ -472,11 +515,19 @@ ${ENDGROUP}`)
} else {
process.stdout.write(`${GROUP}❌ ${test.file} output\n`)
}

let output = ''
// limit out to last 64kb so that we don't
// run out of log room in CI
for (const { chunk } of outputChunks) {
process.stdout.write(chunk)
output += chunk.toString()
}

if (process.env.CI && !killed) {
errorsPerTests.set(test.file, output)
}

if (isExpanded) {
process.stdout.write(`end of ${test.file} output\n`)
} else {
Expand Down
Loading