From dcb25a40ef3a6acb85dd46fe1cac587600a4e376 Mon Sep 17 00:00:00 2001 From: donkeyote Date: Mon, 6 Apr 2026 15:31:33 +0100 Subject: [PATCH] fix: ensure test files are ignored when type checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move test file exclusion filter to run before the TypeScript program is created, rather than filtering diagnostics after the emit. Previously, test and mock files (__tests__, __mocks__, *.spec.*, *.test.*) were still compiled as part of the program — their errors were just suppressed. Now they are excluded from rootNames upfront, so they are never type-checked at all. --- .../next/src/lib/typescript/runTypeCheck.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/next/src/lib/typescript/runTypeCheck.ts b/packages/next/src/lib/typescript/runTypeCheck.ts index e786c7d263e60b..6fe3742b8222a5 100644 --- a/packages/next/src/lib/typescript/runTypeCheck.ts +++ b/packages/next/src/lib/typescript/runTypeCheck.ts @@ -106,6 +106,18 @@ export async function runTypeCheck( }) } + const ignoreRegex = [ + // matches **/__(tests|mocks)__/** + /[\\/]__(?:tests|mocks)__[\\/]/, + // matches **/*.(spec|test).* + /(?<=[\\/.])(?:spec|test)\.[^\\/]+$/, + ] + const regexIgnoredFile = new RegExp( + ignoreRegex.map((r) => r.source).join('|') + ) + + fileNames = fileNames.filter((fileName) => !regexIgnoredFile.test(fileName)) + if (fileNames.length < 1) { return { hasWarnings: false, @@ -150,20 +162,9 @@ export async function runTypeCheck( const result = program.emit() - const ignoreRegex = [ - // matches **/__(tests|mocks)__/** - /[\\/]__(?:tests|mocks)__[\\/]/, - // matches **/*.(spec|test).* - /(?<=[\\/.])(?:spec|test)\.[^\\/]+$/, - ] - const regexIgnoredFile = new RegExp( - ignoreRegex.map((r) => r.source).join('|') - ) - const allDiagnostics = typescript .getPreEmitDiagnostics(program as import('typescript').Program) .concat(result.diagnostics) - .filter((d) => !(d.file && regexIgnoredFile.test(d.file.fileName))) const firstError = allDiagnostics.find(