Merge pull request #692 from kaoru0822-kitauji/fix/reference-test-stems

fix(reference): classify test suffixes before extensions
This commit is contained in:
Kaoru0822
2026-10-06 00:07:24 -07:00
committed by GitHub
3 changed files with 167 additions and 1 deletions
+2 -1
View File
@@ -285,7 +285,8 @@ const filenameIsTest = (filename: string): boolean => {
if (lower.includes(".test.") || lower.includes(".spec.")) return true;
if (lower.startsWith("test_") || lower.startsWith("spec_")) return true;
if (lower.endsWith("_test") || lower.endsWith("_spec")) return true;
return false;
const stem = basenameParts(lower).base;
return stem.endsWith("_test") || stem.endsWith("_spec");
};
const filenameIsGenerated = (filename: string): boolean => {
@@ -0,0 +1,60 @@
import { describe, expect, it } from "vitest";
import {
classifyReferenceSourcePath,
detectReferenceSourceLanguage,
} from "./referenceSourceClassification.js";
describe("reference source test filenames", () => {
it.each([
["main_test.go", ["source", "test"], "Go"],
["main_test.py", ["source", "test"], "Python"],
["parser_spec.rs", ["source", "test"], "Rust"],
["widget_spec.cpp", ["source", "test"], "C++"],
["Widget_TeSt.TS", ["source", "test"], "TypeScript"],
["Widget_SpEc.PY", ["source", "test"], "Python"],
["widget.v2_test.py", ["source", "test"], "Python"],
[".widget_spec.js", ["source", "test"], "JavaScript"],
["widget_test.fixture", ["test"], null],
["settings_spec.json", ["config", "test"], "JSON"],
["notes_test.md", ["documentation", "test"], "Markdown"],
["widget_test.map", ["generated", "test"], null],
["dist/widget_spec.js", ["generated", "source", "test"], "JavaScript"],
["vendor/widget_test.go", ["source", "test", "vendor"], "Go"],
])("recognizes the final basename suffix in %s", (path, tags, language) => {
expect(classifyReferenceSourcePath(path)).toEqual(tags);
expect(detectReferenceSourceLanguage(path)).toBe(language);
});
it.each([
["test_main.py", ["source", "test"]],
["SPEC_main.rs", ["source", "test"]],
["main.test.js", ["source", "test"]],
["main.SPEC.ts", ["source", "test"]],
["main_test", ["test"]],
["main_SPEC", ["test"]],
["main.py_test", ["test"]],
["main.rs_spec", ["test"]],
["tests/main.go", ["source", "test"]],
])("preserves existing test classification for %s", (path, tags) => {
expect(classifyReferenceSourcePath(path)).toEqual(tags);
});
it.each([
["main.go", ["source"]],
["main.py", ["source"]],
["main_test_helper.go", ["source"]],
["main_tests.go", ["source"]],
["main_testing.py", ["source"]],
["main_tester.py", ["source"]],
["main_spec_helper.rs", ["source"]],
["main_specs.rs", ["source"]],
["main_specimen.rs", ["source"]],
["main_test.py.bak", ["unknown"]],
["main_spec.ts.bak", ["unknown"]],
["main_test_helpers", ["unknown"]],
["main_spec_helpers", ["unknown"]],
])("does not infer a test from a near-name in %s", (path, tags) => {
expect(classifyReferenceSourcePath(path)).toEqual(tags);
});
});