| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | import type { FileDiffMetadata } from "@pierre/diffs"; | 1 | import type { FileDiffMetadata } from "@pierre/diffs"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; | 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | | 3 | |
| 4 | import { diffFileTier, orderDiffFiles } from "./pullRequestFileOrder.logic"; | 4 | import { orderDiffFiles } from "./pullRequestFileOrder.logic"; |
| 5 | | 5 | |
| 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. */ |
| 7 | function file(name: string, additionLines: ReadonlyArray<string> = []): FileDiffMetadata { | 7 | function 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 | } |
| 14 | | 14 | |
| 15 | describe("diffFileTier", () => { | 15 | describe("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 = [ |
| 26 | | 26 | "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", |
| 34 | | 34 | ]; |
| 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 | }); | | |
| 41 | | 39 | |
| 42 | describe("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 | }); |