File size: 773 Bytes
776286d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { baseNameOf } from '../base-name-of'
import { rootedPathOf } from '../rooted-path-of'
import { TEST_DIRECTORIES } from './test-directories'
import { TEST_FILENAME_PATTERNS } from './test-filename-patterns'

/**
 * Whether a repository-relative path is a test, spec, fixture or snapshot,
 * by the same rules the engine's own diff panel applies.
 *
 * @param path the file's path from the repository root, `/`-separated
 * @returns whether the diff pane counts it among the tests and generated files
 */
export function isTestFile(path: string) {
  const name = baseNameOf(path)
  const rooted = rootedPathOf(path)

  return (
    TEST_DIRECTORIES.some(directory => rooted.includes(directory)) ||
    TEST_FILENAME_PATTERNS.some(pattern => pattern.test(name))
  )
}