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