MCPcopy
hub / github.com/colbymchenry/codegraph / isTestFile

Function isTestFile

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

Source from the content-addressed store, hash-verified

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

Callers 4

findRelevantContextMethod · 0.90
scorePathRelevanceFunction · 0.70

Calls 1

matchesNonProductionDirFunction · 0.85

Tested by

no test coverage detected