From fb6615a49b71fcf7225f6895ca5457092d3084c8 Mon Sep 17 00:00:00 2001 From: cnbailian <594647004@qq.com> Date: Fri, 6 Mar 2026 11:56:40 +0800 Subject: [PATCH] fix: skip node_modules and other ignored directories in test discovery Repterm's test loader was recursively scanning into node_modules and loading test files from dependencies (like bun-pty), causing fatal errors when describe() was used in contexts where it's not supported. This fix skips common non-test directories (node_modules, .git, dist, .next, .turbo) during recursive test discovery. Fixes the 'Cannot use describe outside of the test runner' error when running repterm with --record flag. --- bun.lock | 4 ++-- packages/repterm/src/runner/loader.ts | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bun.lock b/bun.lock index 94af960..aab054c 100644 --- a/bun.lock +++ b/bun.lock @@ -45,14 +45,14 @@ }, "packages/plugin-api": { "name": "repterm-api", - "version": "0.1.3", + "version": "0.1.4", "devDependencies": { "typescript": "^5.3.0", }, }, "packages/plugin-kubectl": { "name": "@nexusgpu/repterm-plugin-kubectl", - "version": "0.1.3", + "version": "0.1.4", "dependencies": { "repterm-api": "workspace:*", }, diff --git a/packages/repterm/src/runner/loader.ts b/packages/repterm/src/runner/loader.ts index facadb5..33751cd 100644 --- a/packages/repterm/src/runner/loader.ts +++ b/packages/repterm/src/runner/loader.ts @@ -88,6 +88,9 @@ export async function discoverTests( return testFiles; } +/** Directories that should never be traversed when discovering tests. */ +const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', '.next', '.turbo']); + /** * Recursively find test files matching pattern */ @@ -106,6 +109,7 @@ async function findTestFiles( const stats = await stat(fullPath); if (stats.isDirectory() && recursive) { + if (IGNORED_DIRS.has(entry)) continue; const nestedFiles = await findTestFiles(fullPath, pattern, recursive); files.push(...nestedFiles); } else if (stats.isFile() && pattern.test(entry)) { @@ -197,7 +201,9 @@ async function analyzeDirectory( const stats = await stat(fullPath); if (stats.isDirectory()) { - subdirs.push(fullPath); + if (!IGNORED_DIRS.has(entry)) { + subdirs.push(fullPath); + } } else if (stats.isFile() && pattern.test(entry)) { if (isSetupFile(entry)) { setupFile = fullPath;