/// import { expect } from "e2e"; import { run } from "./shell.ts"; import { runPromise, test, WEB } from "./t3.ts"; const importer = `diff --git a/src/a.ts b/src/a.ts index 1111111..2222222 100644 --- a/src/a.ts +++ b/src/a.ts @@ -1 +1,2 @@ +import { b } from "~/z/b.logic"; export const a = 1; `; const dependency = `diff --git a/z/b.logic.ts b/z/b.logic.ts index 4444444..5555555 100644 --- a/z/b.logic.ts +++ b/z/b.logic.ts @@ -1 +1 @@ -export const b = 1; +export const b = 2; `; const unrelated = (path: string) => `diff --git a/${path} b/${path} new file mode 100644 index 0000000..3333333 --- /dev/null +++ b/${path} @@ -0,0 +1 @@ +export const unrelated = 1; `; const cases = [ {label: "two-files", patch: importer + dependency, expected: ["z/b.logic.ts", "src/a.ts"]}, {label: "three-files", patch: unrelated("other/b.ts") + importer + dependency, expected: ["other/b.ts", "z/b.logic.ts", "src/a.ts"]}, {label: "non-dotted-control", patch: importer.replace('b } from "~/z/b.logic"', 'c } from "~/z/c"') + unrelated("z/c.ts").replace("unrelated", "c"), expected: ["z/c.ts", "src/a.ts"]}, {label: "dotted-alias-with-unrelated-b", patch: importer + unrelated("y/b.ts") + dependency, expected: ["y/b.ts", "z/b.logic.ts", "src/a.ts"]}, {label: "false-match-isolated", patch: importer.replace("~/z/b.logic", "~/a/b.logic") + unrelated("y/b.ts") + dependency.replaceAll("z/b.logic.ts", "a/b.logic.ts"), expected: ["a/b.logic.ts", "src/a.ts", "y/b.ts"]}, ]; test("PR Code orders a dotted alias dependency ahead of its importer, without matching b.ts", WEB, async ({ t3, app, screen, browser }) => { const project = await t3.project("Dotted module ordering", { "src/a.ts": "export const a = 1;\n", "z/b.logic.ts": "export const b = 1;\n", "a/b.logic.ts": "export const b = 1;\n", "other/b.ts": "export const other = 1;\n", "tsconfig.json": '{"compilerOptions":{"paths":{"~/*":["./*"]}}}\n', }); await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project })); const thread = await t3.thread({project, title: "Dotted alias import", messages: ["first"]}); // Only the diff payload is synthetic. The app, server, PR metadata and Code view are real. let patch = cases[0].patch; await browser.route("**/api/pull-requests/diff", async route => { await route.fulfill({json: {patch, truncated: false, nextCursor: null}}); }); await t3.open(thread); const actual: string[][] = []; for (const sample of cases) { patch = sample.patch; await app.open("/pull-requests?repository=pingdotgg%2Ft3code&number=32364&selectedHost=github.com&q=32364"); await screen.getByRole("button", "Code", {exact: true}).tap(); await screen.getByRole("button", "Maximize panel", {exact: true}).tap(); await screen.getByRole("button", "Expand all files", {exact: true}).tap(); await browser.locator("diffs-container").first().waitFor({state: "visible"}); await app.screenshot(sample.label); actual.push(await browser.evaluate(() => Array.from(document.querySelectorAll("diffs-container")).flatMap(host => Array.from(host.shadowRoot?.querySelectorAll("[data-title]") ?? [], el => el.textContent?.trim() ?? "")).filter(name => ["src/a.ts","y/b.ts","other/b.ts","z/c.ts","z/b.logic.ts","a/b.logic.ts"].includes(name)))); } expect(actual).toEqual(cases.map(sample => sample.expected)); });