spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / classify / is-test-file / is-test-file.ts
21 lines · 773 BRaw
1import { baseNameOf } from '../base-name-of'
2import { rootedPathOf } from '../rooted-path-of'
3import { TEST_DIRECTORIES } from './test-directories'
4import { TEST_FILENAME_PATTERNS } from './test-filename-patterns'
5
6/**
7 * Whether a repository-relative path is a test, spec, fixture or snapshot,
8 * by the same rules the engine's own diff panel applies.
9 *
10 * @param path the file's path from the repository root, `/`-separated
11 * @returns whether the diff pane counts it among the tests and generated files
12 */
13export function isTestFile(path: string) {
14 const name = baseNameOf(path)
15 const rooted = rootedPathOf(path)
16
17 return (
18 TEST_DIRECTORIES.some(directory => rooted.includes(directory)) ||
19 TEST_FILENAME_PATTERNS.some(pattern => pattern.test(name))
20 )
21}