未验证 提交 8390a474 编写于 作者: J JJ Kasper 提交者: GitHub

Update to output jest data for posting failed tests comment (#10814)

* Update to output jest data for posting failed tests comment

* Add failing test

* Reset retries

* Revert change for testing
上级 4ef1cd4e
......@@ -38,6 +38,7 @@ jobs:
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
HEADLESS: true
strategy:
fail-fast: false
......
module.exports = {
testMatch: ['**/*.test.js'],
verbose: true,
bail: true,
rootDir: 'test',
modulePaths: ['<rootDir>/lib'],
globalSetup: '<rootDir>/jest-global-setup.js',
......
const path = require('path')
const _glob = require('glob')
const fs = require('fs').promises
const fetch = require('node-fetch')
const { promisify } = require('util')
const { Sema } = require('async-sema')
......@@ -8,9 +9,11 @@ const { spawn, exec: execOrig } = require('child_process')
const glob = promisify(_glob)
const exec = promisify(execOrig)
const timings = []
const NUM_RETRIES = 2
const DEFAULT_CONCURRENCY = 2
const timings = []
const RESULTS_EXT = `.results.json`
const isTestJob = !!process.env.NEXT_TEST_JOB
const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
;(async () => {
......@@ -117,15 +120,24 @@ const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
const start = new Date().getTime()
const child = spawn(
'node',
[jestPath, '--runInBand', '--forceExit', '--verbose', test],
[
jestPath,
'--runInBand',
'--forceExit',
'--verbose',
...(isTestJob
? ['--json', `--outputFile=${test}${RESULTS_EXT}`]
: []),
test,
],
{
stdio: 'inherit',
env: {
...process.env,
...(usePolling
? {
// Events can be finicky in CI. This switches to a more reliable
// polling method.
// Events can be finicky in CI. This switches to a more
// reliable polling method.
CHOKIDAR_USEPOLLING: 'true',
CHOKIDAR_INTERVAL: 500,
}
......@@ -169,6 +181,22 @@ const TIMINGS_API = `https://next-timings.jjsweb.site/api/timings`
if (!passed) {
console.error(`${test} failed to pass within ${NUM_RETRIES} retries`)
children.forEach(child => child.kill())
if (isTestJob) {
try {
const testsOutput = await fs.readFile(
`${test}${RESULTS_EXT}`,
'utf8'
)
console.log(
`--test output start--`,
testsOutput,
`--test output end--`
)
} catch (err) {
console.log(`Failed to load test output`, err)
}
}
process.exit(1)
}
sema.release()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册