Skip to content

Commit 85133dc

Browse files
MarcoDotIOclaude
andauthored
fix(web): PR diffs list a .logic.test.ts file beside the source it covers (#23129)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent ff9f636 commit 85133dc

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,24 @@ describe("orderDiffFiles", () => {
118118
"src/orphan.spec.ts",
119119
]);
120120
});
121+
122+
it("pairs a test with the source whose name carries its own dotted suffix", () => {
123+
expect(
124+
order([
125+
file("src/c.browser.test.tsx"),
126+
file("src/b.test.ts"),
127+
file("src/a.logic.test.ts"),
128+
file("src/c.tsx"),
129+
file("src/b.ts"),
130+
file("src/a.logic.ts"),
131+
]),
132+
).toEqual([
133+
"src/a.logic.ts",
134+
"src/b.ts",
135+
"src/c.tsx",
136+
"src/a.logic.test.ts",
137+
"src/b.test.ts",
138+
"src/c.browser.test.tsx",
139+
]);
140+
});
121141
});

‎apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,17 @@ function orderByImports(
117117
return ordered;
118118
}
119119

120-
function testedBaseName(path: string): string {
121-
return (path.split("/").at(-1) ?? "").replace(/\.(?:test|spec)\..*$/, "").replace(/\.[^.]+$/, "");
120+
// `a.logic.test.ts` covers `a.logic.ts` while `a.browser.test.ts` covers `a.ts`, so the longest
121+
// dotted prefix that names a source file wins.
122+
function testedSourcePosition(path: string, sourcePositions: ReadonlyMap<string, number>): number {
123+
let name = (path.split("/").at(-1) ?? "").replace(/\.(?:test|spec)\..*$/, "");
124+
while (true) {
125+
const position = sourcePositions.get(name);
126+
if (position !== undefined) return position;
127+
const dot = name.lastIndexOf(".");
128+
if (dot <= 0) return Number.MAX_SAFE_INTEGER;
129+
name = name.slice(0, dot);
130+
}
122131
}
123132

124133
export function orderDiffFiles(
@@ -159,9 +168,10 @@ export function orderDiffFiles(
159168
const orderedTests = [...byPath.keys()]
160169
.filter((path) => tiers.get(path) === "test")
161170
.sort((left, right) => {
162-
const leftPosition = sourcePositions.get(testedBaseName(left)) ?? Number.MAX_SAFE_INTEGER;
163-
const rightPosition = sourcePositions.get(testedBaseName(right)) ?? Number.MAX_SAFE_INTEGER;
164-
return leftPosition - rightPosition || left.localeCompare(right);
171+
return (
172+
testedSourcePosition(left, sourcePositions) -
173+
testedSourcePosition(right, sourcePositions) || left.localeCompare(right)
174+
);
165175
});
166176

167177
const orderedGenerated = [...byPath.keys()]

0 commit comments

Comments
 (0)