Skip to content

Commit

Permalink
Update to output jest data for posting failed tests comment (#10814)
Browse files Browse the repository at this point in the history
* Update to output jest data for posting failed tests comment

* Add failing test

* Reset retries

* Revert change for testing
  • Loading branch information
ijjk committed Mar 4, 2020
1 parent 4ef1cd4 commit 8390a47
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -38,6 +38,7 @@ jobs:
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
NEXT_TEST_JOB: 1
HEADLESS: true
strategy:
fail-fast: false
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
@@ -1,7 +1,6 @@
module.exports = {
testMatch: ['**/*.test.js'],
verbose: true,
bail: true,
rootDir: 'test',
modulePaths: ['<rootDir>/lib'],
globalSetup: '<rootDir>/jest-global-setup.js',
Expand Down
36 changes: 32 additions & 4 deletions run-tests.js
@@ -1,5 +1,6 @@
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')
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8390a47

Please sign in to comment.