From 189f6c627c8dad07e7fa74c753d20150af73fd37 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 3 Mar 2020 16:11:56 -0600 Subject: [PATCH 1/4] Update to output jest data for posting failed tests comment --- .github/workflows/build_test_deploy.yml | 1 + jest.config.js | 1 - run-tests.js | 38 +++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 6059e757d9cd970..8bc0e91b762b381 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -38,6 +38,7 @@ jobs: needs: build env: NEXT_TELEMETRY_DISABLED: 1 + NEXT_TEST_JOB: 1 HEADLESS: true strategy: fail-fast: false diff --git a/jest.config.js b/jest.config.js index 023dd083017caf2..68829f0230eaca6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,6 @@ module.exports = { testMatch: ['**/*.test.js'], verbose: true, - bail: true, rootDir: 'test', modulePaths: ['/lib'], globalSetup: '/jest-global-setup.js', diff --git a/run-tests.js b/run-tests.js index 2ed62b0fb1b5211..d8a9c0c427867fc 100644 --- a/run-tests.js +++ b/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') @@ -8,9 +9,11 @@ const { spawn, exec: execOrig } = require('child_process') const glob = promisify(_glob) const exec = promisify(execOrig) -const NUM_RETRIES = 2 -const DEFAULT_CONCURRENCY = 2 const timings = [] +const NUM_RETRIES = 0 +const DEFAULT_CONCURRENCY = 2 +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() From a6060fbbfb7e69c585059ed533885ce79b7e0362 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 3 Mar 2020 17:25:27 -0600 Subject: [PATCH 2/4] Add failing test --- test/integration/app-document/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/app-document/test/index.test.js b/test/integration/app-document/test/index.test.js index 2dcd847e954ea2c..15ecdcfeb20727d 100644 --- a/test/integration/app-document/test/index.test.js +++ b/test/integration/app-document/test/index.test.js @@ -38,7 +38,7 @@ describe('Document and App', () => { it('should not have any missing key warnings', async () => { await renderViaHTTP(context.appPort, '/') - expect(context.output).not.toMatch( + expect(context.output).toMatch( /Each child in a list should have a unique "key" prop/ ) }) From 31428e129479406a7be57bc0784dbdc7aa938f0c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 3 Mar 2020 17:28:08 -0600 Subject: [PATCH 3/4] Reset retries --- run-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.js b/run-tests.js index d8a9c0c427867fc..30baa05d1c4751a 100644 --- a/run-tests.js +++ b/run-tests.js @@ -10,7 +10,7 @@ const glob = promisify(_glob) const exec = promisify(execOrig) const timings = [] -const NUM_RETRIES = 0 +const NUM_RETRIES = 2 const DEFAULT_CONCURRENCY = 2 const RESULTS_EXT = `.results.json` const isTestJob = !!process.env.NEXT_TEST_JOB From 96424d5a67c3d6afb2b4843732de7755f44d3b88 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 3 Mar 2020 18:29:01 -0600 Subject: [PATCH 4/4] Revert change for testing --- test/integration/app-document/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/app-document/test/index.test.js b/test/integration/app-document/test/index.test.js index 15ecdcfeb20727d..2dcd847e954ea2c 100644 --- a/test/integration/app-document/test/index.test.js +++ b/test/integration/app-document/test/index.test.js @@ -38,7 +38,7 @@ describe('Document and App', () => { it('should not have any missing key warnings', async () => { await renderViaHTTP(context.appPort, '/') - expect(context.output).toMatch( + expect(context.output).not.toMatch( /Each child in a list should have a unique "key" prop/ ) })