MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / isTestFile

Function isTestFile

src/search/query-utils.ts:290–329  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

288 * Check if a file path looks like a test file
289 */
290export function isTestFile(filePath: string): boolean {
291 const lower = filePath.toLowerCase();
292 const fileName = path.basename(filePath); // original case — needed for camelCase boundaries
293 const lowerName = fileName.toLowerCase();
294
295 // --- Filename patterns ---
296 if (
297 lowerName.startsWith('test_') || // python: test_foo.py
298 lowerName.startsWith('test.') ||
299 // separator-delimited: foo_test.go, foo.test.ts, foo-spec.rb, bar_spec.py
300 /[._-](test|tests|spec|specs)\.[a-z0-9]+$/.test(lowerName) ||
301 // CamelCase suffix (Java/Kotlin/Swift/C#/Scala): FooTest.kt, BarTests.swift,
302 // BazSpec.scala, QuxTestCase.java. Capital-led so "latest.kt"/"manifest.kt"
303 // (lowercase "test") are NOT matched.
304 /(?:Test|Tests|TestCase|Tester|Spec|Specs)\.[A-Za-z0-9]+$/.test(fileName)
305 ) {
306 return true;
307 }
308
309 // --- Directory patterns ---
310 if (
311 lower.includes('/tests/') || lower.includes('/test/') ||
312 lower.includes('/__tests__/') || lower.includes('/spec/') ||
313 lower.includes('/specs/') || lower.includes('/testlib/') ||
314 lower.includes('/testing/') ||
315 lower.startsWith('test/') || lower.startsWith('tests/') ||
316 lower.startsWith('spec/') || lower.startsWith('specs/') ||
317 // CamelCase test source-set dirs (Kotlin Multiplatform / Gradle / Xcode):
318 // jvmTest/, commonTest/, androidTest/, iosTest/, integrationTest/. Capital-led
319 // so "latest/" / "manifest/" are not matched.
320 /(?:^|\/)[A-Za-z0-9]*(?:Test|Tests|Spec)\//.test(filePath)
321 ) {
322 return true;
323 }
324
325 // Non-production directories: examples, samples, benchmarks, fixtures, demos.
326 // Check both mid-path (/integration/) and start-of-path (integration/) since
327 // file paths may be stored as relative paths without a leading slash.
328 return matchesNonProductionDir(lower);
329}
330
331/**
332 * Check if a path is in a non-production directory (integration, sample, example, etc.)

Callers 5

findRelevantContextMethod · 0.90
indirectTestNoteMethod · 0.90
scorePathRelevanceFunction · 0.70

Calls 1

matchesNonProductionDirFunction · 0.85

Tested by

no test coverage detected