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

Function isTestPath

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

Source from the content-addressed store, hash-verified

309 * that contains them is telling the reader something untrue.
310 */
311export function isTestPath(filePath: string): boolean {
312 const lower = filePath.toLowerCase();
313 const fileName = path.basename(filePath); // original case — needed for camelCase boundaries
314 const lowerName = fileName.toLowerCase();
315
316 // --- Filename patterns ---
317 if (
318 lowerName.startsWith('test_') || // python: test_foo.py
319 lowerName.startsWith('test.') ||
320 // separator-delimited: foo_test.go, foo.test.ts, foo-spec.rb, bar_spec.py
321 /[._-](test|tests|spec|specs)\.[a-z0-9]+$/.test(lowerName) ||
322 // CamelCase suffix (Java/Kotlin/Swift/C#/Scala): FooTest.kt, BarTests.swift,
323 // BazSpec.scala, QuxTestCase.java. Capital-led so "latest.kt"/"manifest.kt"
324 // (lowercase "test") are NOT matched.
325 /(?:Test|Tests|TestCase|Tester|Spec|Specs)\.[A-Za-z0-9]+$/.test(fileName)
326 ) {
327 return true;
328 }
329
330 // --- Directory patterns ---
331 if (
332 lower.includes('/tests/') || lower.includes('/test/') ||
333 lower.includes('/__tests__/') || lower.includes('/spec/') ||
334 lower.includes('/specs/') || lower.includes('/testlib/') ||
335 lower.includes('/testing/') || lower.includes('/e2e/') ||
336 lower.startsWith('test/') || lower.startsWith('tests/') ||
337 lower.startsWith('spec/') || lower.startsWith('specs/') ||
338 lower.startsWith('e2e/') ||
339 // CamelCase test source-set dirs (Kotlin Multiplatform / Gradle / Xcode):
340 // jvmTest/, commonTest/, androidTest/, iosTest/, integrationTest/. Capital-led
341 // so "latest/" / "manifest/" are not matched.
342 /(?:^|\/)[A-Za-z0-9]*(?:Test|Tests|Spec)\//.test(filePath) ||
343 // Test-support modules and doubles by directory name: Gradle's
344 // `core/data-test/`, `core/datastore-test/`, `:testing`; Go's `testdata/`;
345 // `testutil(s)/`, `test-utils/`, `fakes/`, `mocks/`, `__mocks__/`.
346 /(?:^|\/)(?:[\w.]+[-_]test(?:s|ing)?|testdata|testutils?|test[-_]utils?|fakes?|mocks?|__mocks__|stubs)\//.test(lower)
347 ) {
348 return true;
349 }
350
351 return false;
352}
353
354/**
355 * Check if a path is in a non-production directory (integration, sample, example, etc.)

Callers 15

angularComponentsFunction · 0.90
isPythonTestFileFunction · 0.90
isTestSuitePathFunction · 0.90
luaAliasExprFunction · 0.90
isVisibleAcrossFilesFunction · 0.90
matchMethodCallFunction · 0.90
matchCppMacroNamespacedFunction · 0.90
hasTestRequestPatternFunction · 0.90
isRequestHelperFunction · 0.90
testRequestEdgesFunction · 0.90
crossTierEdgesFunction · 0.90
svelteKitLinkEdgesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected