A file named test.js or spec.rb counts as a test: confidence no longer says tests not added when they were
3 files+12−20/3 viewed
| 159 | 159 | assert.ok(isTestFile("pkg/store_test.go")); | |
| 160 | 160 | assert.ok(!isTestFile("src/testing-utils.ts")); | |
| 161 | 161 | assert.ok(!isTestFile("src/contest.ts")); | |
| 162 | + | assert.ok(isTestFile("test.js")); | |
| 163 | + | assert.ok(isTestFile("lib/spec.rb")); | |
| 162 | 164 | }); | |
| 163 | 165 | ||
| 164 | 166 | const merged = (daysAgo: number, mergedBy: string | null, number = 1, authoredByAgent = true): Merged => ({ |
| 183 | 183 | ||
| 184 | 184 | /** Test files, by the names test runners look for. */ | |
| 185 | 185 | export function isTestFile(path: string): boolean { | |
| 186 | − | return /(^|\/)(__tests__|tests?|spec)\//i.test(path) || /[._-](test|spec)\.[a-z0-9]+$/i.test(path) || /_test\.(go|rs|py)$/i.test(path); | |
| 186 | + | return ( | |
| 187 | + | /(^|\/)(__tests__|tests?|spec)\//i.test(path) || | |
| 188 | + | /[._-](test|spec)\.[a-z0-9]+$/i.test(path) || | |
| 189 | + | /_test\.(go|rs|py)$/i.test(path) || | |
| 190 | + | // A file named for what it is: test.js, tests.py, spec.rb. | |
| 191 | + | /(^|\/)(tests?|specs?)\.[a-z0-9]+$/i.test(path) | |
| 192 | + | ); | |
| 187 | 193 | } | |
| 188 | 194 | ||
| 189 | 195 | const plural = (n: number, one: string, many = `${one}s`) => `${n.toLocaleString("en-US")} ${n === 1 ? one : many}`; |
| 123 | 123 | lower.split('/').any(|dir| matches!(dir, "test" | "tests" | "__tests__" | "spec" | "specs" | "testdata")) | |
| 124 | 124 | || [".test.", ".spec.", "_test.", "-test.", "_spec."].iter().any(|mark| file.contains(mark)) | |
| 125 | 125 | || file.starts_with("test_") | |
| 126 | + | // A file named for what it is: test.js, tests.py, spec.rb. | |
| 127 | + | || matches!(file.split('.').next(), Some("test" | "tests" | "spec" | "specs")) && file.contains('.') | |
| 126 | 128 | } | |
| 127 | 129 | ||
| 128 | 130 | /// Files that change nothing that runs: prose and pictures. | |
| 967 | 969 | ||
| 968 | 970 | #[test] | |
| 969 | 971 | fn tests_prose_and_sensitive_paths_are_told_apart() { | |
| 970 | − | for path in ["src/__tests__/a.ts", "tests/test_api.py", "pkg/api_test.go", "src/a.spec.tsx", "crates/x/tests/it.rs"] { | |
| 972 | + | for path in ["src/__tests__/a.ts", "tests/test_api.py", "pkg/api_test.go", "src/a.spec.tsx", "crates/x/tests/it.rs", "test.js", "lib/spec.rb"] { | |
| 971 | 973 | assert!(is_test(path), "{path}"); | |
| 972 | 974 | } | |
| 973 | 975 | for path in ["src/testing.ts", "src/contest.rs", "attest/a.rs"] { |