The best way to control Claude Code, Codex and more from any computer or phone
test(web): cover file classification through diff ordering (#10304)
Julius Marminge committed
Sep 5, 2026 at 22:30 UTC
f93aafcc2c166128070b32259e827f15bc2a1d82
2 files changed
+25
-28
apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts
+24
-27
@@ -1,7 +1,7 @@
1
import type { FileDiffMetadata } from "@pierre/diffs";
2
import { describe, expect, it } from "vite-plus/test";
3
4
-import { diffFileTier, orderDiffFiles } from "./pullRequestFileOrder.logic";
4
+import { orderDiffFiles } from "./pullRequestFileOrder.logic";
5
6
/** Only the path and the patch's own lines matter here; the viewer fills the rest in. */
7
function file(name: string, additionLines: ReadonlyArray<string> = []): FileDiffMetadata {
@@ -12,34 +12,31 @@ function order(files: ReadonlyArray<FileDiffMetadata>): Array<string> {
12
return orderDiffFiles(files).map((entry) => entry.name);
13
}
14
15
-describe("diffFileTier", () => {
16
- it("puts lockfiles, snapshots and build output last", () => {
17
- expect(diffFileTier("pnpm-lock.yaml")).toBe("generated");
18
- expect(diffFileTier("apps/web/package-lock.json")).toBe("generated");
19
- expect(diffFileTier("src/__snapshots__/app.ts")).toBe("generated");
20
- expect(diffFileTier("src/app.test.ts.snap")).toBe("generated");
21
- expect(diffFileTier("src/api.generated.ts")).toBe("generated");
22
- expect(diffFileTier("public/app.min.js")).toBe("generated");
23
- expect(diffFileTier("dist/app.js")).toBe("generated");
24
- expect(diffFileTier("packages/core/vendor/lib.js")).toBe("generated");
25
- });
26
-
27
- it("recognises a test by its name or by the directory holding it", () => {
28
- expect(diffFileTier("src/app.test.ts")).toBe("test");
29
- expect(diffFileTier("src/app.spec.tsx")).toBe("test");
30
- expect(diffFileTier("src/__tests__/app.ts")).toBe("test");
31
- expect(diffFileTier("test/app.ts")).toBe("test");
32
- expect(diffFileTier("tests/helpers/app.ts")).toBe("test");
33
- });
34
-
35
- it("treats everything else as source, including files merely named like a directory", () => {
36
- expect(diffFileTier("src/app.ts")).toBe("source");
37
- expect(diffFileTier("src/testing.ts")).toBe("source");
38
- expect(diffFileTier("src/dist.ts")).toBe("source");
15
+describe("orderDiffFiles", () => {
16
+ it("places source before tests and generated files across path conventions", () => {
17
+ const source = ["src/app.ts", "src/dist.ts", "src/testing.ts"];
18
+ const tests = [
19
+ "src/__tests__/app.ts",
20
+ "src/app.spec.tsx",
21
+ "src/app.test.ts",
22
+ "test/app.ts",
23
+ "tests/helpers/app.ts",
24
+ ];
25
+ const generated = [
26
+ "apps/web/package-lock.json",
27
+ "dist/app.js",
28
+ "packages/core/vendor/lib.js",
29
+ "pnpm-lock.yaml",
30
+ "public/app.min.js",
31
+ "src/__snapshots__/app.ts",
32
+ "src/api.generated.ts",
33
+ "src/app.test.ts.snap",
34
+ ];
35
+ expect(
36
+ order([...generated, ...tests, ...source].toReversed().map((path) => file(path))),
37
+ ).toEqual([...source, ...tests, ...generated]);
38
});
40
-});
39
42
-describe("orderDiffFiles", () => {
40
it("answers an empty diff with an empty order", () => {
41
expect(order([])).toEqual([]);
42
});
apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts
+1
-1
@@ -31,7 +31,7 @@ const GENERATED_DIRECTORIES = new Set([
31
const TEST_DIRECTORIES = new Set(["__tests__", "tests", "test"]);
32
const MODULE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
33
34
-export function diffFileTier(path: string): DiffFileTier {
34
+function diffFileTier(path: string): DiffFileTier {
35
const segments = path.split("/");
36
const name = segments.at(-1) ?? "";
37
if (