authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 22:30:47-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 22:30:47-07:00
logf93aafcc2c166128070b32259e827f15bc2a1d82
treeb4bd028ba824d0e5db3dbbaf7a11a65b03c98880
parentb4040d9bf38d57cce715c9e602de8de4b0f4a523
signature Signed by PGP key B5690EEEBB952194

test(web): cover file classification through diff ordering (#10304)


2 files changed, 25 insertions(+), 28 deletions(-)

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