Skip to content

Commit fb6615a

Browse files
committed
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.
1 parent 2764ddb commit fb6615a

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/repterm/src/runner/loader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export async function discoverTests(
8888
return testFiles;
8989
}
9090

91+
/** Directories that should never be traversed when discovering tests. */
92+
const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', '.next', '.turbo']);
93+
9194
/**
9295
* Recursively find test files matching pattern
9396
*/
@@ -106,6 +109,7 @@ async function findTestFiles(
106109
const stats = await stat(fullPath);
107110

108111
if (stats.isDirectory() && recursive) {
112+
if (IGNORED_DIRS.has(entry)) continue;
109113
const nestedFiles = await findTestFiles(fullPath, pattern, recursive);
110114
files.push(...nestedFiles);
111115
} else if (stats.isFile() && pattern.test(entry)) {
@@ -197,7 +201,9 @@ async function analyzeDirectory(
197201
const stats = await stat(fullPath);
198202

199203
if (stats.isDirectory()) {
200-
subdirs.push(fullPath);
204+
if (!IGNORED_DIRS.has(entry)) {
205+
subdirs.push(fullPath);
206+
}
201207
} else if (stats.isFile() && pattern.test(entry)) {
202208
if (isSetupFile(entry)) {
203209
setupFile = fullPath;

0 commit comments

Comments
 (0)