From 6109bda52d5c73bdb6d1d9780c1b2a558f75b5ff Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 20 Oct 2026 19:04:26 -0700 Subject: [PATCH] test(nextjs): Warm the module graph before the tunnel route tests The first test in `getFinalConfigObjectUtils.test.ts` paid for the cold transform of the module and its dependency tree. On a slow CI runner this took more than the 5 second test timeout. Vitest does not stop a timed-out test, so its late `console.log` went into the next test's spy, and two tests failed. A `beforeAll` hook now imports the module once. `vi.resetModules()` clears the module registry but keeps the transform cache, so later imports are fast. The slow work runs in the hook, which has its own timeout and cannot leak into a test. A longer test timeout would also pass, but a slow first test could still break the next one. Fixes #25591 Fixes JS-3977 Co-Authored-By: Claude Opus 5.5 (1M context) --- .../withSentryConfig/getFinalConfigObjectUtils.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/test/config/withSentryConfig/getFinalConfigObjectUtils.test.ts b/packages/nextjs/test/config/withSentryConfig/getFinalConfigObjectUtils.test.ts index cfda40eaa28f..dde7fbf85066 100644 --- a/packages/nextjs/test/config/withSentryConfig/getFinalConfigObjectUtils.test.ts +++ b/packages/nextjs/test/config/withSentryConfig/getFinalConfigObjectUtils.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import type { NextConfigObject } from '../../../src/config/types'; import { makeProject, removeProjects } from './projectFixture'; @@ -9,6 +9,14 @@ afterEach(() => { }); describe('maybeSetUpTunnelRouteRewriteRules', () => { + beforeAll(async () => { + // The first import transforms the whole dependency tree, which can + // take longer than the test timeout on a slow CI runner. A timed-out + // test keeps running and logs into the next test's spies. Imports + // after `vi.resetModules()` reuse these transforms. + await import('../../../src/config/withSentryConfig/getFinalConfigObjectUtils'); + }); + beforeEach(() => { vi.restoreAllMocks(); // A fresh module per test, because the function logs each message only once.