From 411846a016869eb807f1e322cc0f82fa5fbe9803 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 5 Apr 2024 21:33:19 +0200 Subject: [PATCH] Always throw error when build fails during test (#64116) ## What? When creating the Next.js instance fails for whatever reason (most commonly `next build` failing) it currently exits the process, this causes Jest to not report these tests as failed. The change in this PR ensures that anytime creating the instance fails it throws an error that is caught by Jest and then causes Jest to report the tests as failed. The reporting of tests is relevant as our monitoring tools (i.e. DataDog / Turbopack test manifest) rely on correct reporting of all failing tests. Closes NEXT-3016 --- .github/workflows/test_e2e_deploy.yml | 2 +- test/lib/e2e-utils.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test_e2e_deploy.yml b/.github/workflows/test_e2e_deploy.yml index 8871dacfe0c97..feb37aec4c4b4 100644 --- a/.github/workflows/test_e2e_deploy.yml +++ b/.github/workflows/test_e2e_deploy.yml @@ -51,7 +51,7 @@ jobs: - run: node scripts/run-e2e-test-project-reset.mjs name: Reset test project - - run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.35.1-jammy /bin/bash -c "cd /work && NODE_VERSION=${{ env.NODE_LTS_VERSION }} ./scripts/setup-node.sh && corepack enable > /dev/null && NEXT_JUNIT_TEST_REPORT=true DATADOG_API_KEY=${DATADOG_API_KEY} DD_ENV=ci VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_CONTINUE_ON_ERROR=1 xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2 -c 1 >> /proc/1/fd/1" + - run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.35.1-jammy /bin/bash -c "cd /work && NODE_VERSION=${{ env.NODE_LTS_VERSION }} ./scripts/setup-node.sh && corepack enable > /dev/null && NEXT_JUNIT_TEST_REPORT=true DATADOG_API_KEY=${DATADOG_API_KEY} DD_ENV=ci VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2 -c 1 >> /proc/1/fd/1" name: Run test/e2e (deploy) - name: Upload test report diff --git a/test/lib/e2e-utils.ts b/test/lib/e2e-utils.ts index 7da67a75bd6c1..d87e94f79c77a 100644 --- a/test/lib/e2e-utils.ts +++ b/test/lib/e2e-utils.ts @@ -213,16 +213,12 @@ export async function createNext( } catch (err) { require('console').error('Failed to create next instance', err) try { - nextInstance.destroy() + await nextInstance?.destroy() } catch (_) {} - if (process.env.NEXT_TEST_CONTINUE_ON_ERROR) { - // Other test should continue to create new instance if NEXT_TEST_CONTINUE_ON_ERROR explicitly specified. - nextInstance = undefined - throw err - } else { - process.exit(1) - } + nextInstance = undefined + // Throw instead of process exit to ensure that Jest reports the tests as failed. + throw err } finally { flushAllTraces() }