Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/tests/responsible-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
fileName: string | null,
opts: { functionName?: string | null; typeName?: string | null } = {},
): CallSite {
return {
getFileName: () => fileName,
getFunctionName: () =>
"functionName" in opts ? (opts.functionName ?? null) : "fn",
getTypeName: () => opts.typeName ?? null,
} as unknown as CallSite;

Check warning on line 19 in src/tests/responsible-module.test.ts

View workflow job for this annotation

GitHub Actions / checks

anti-slop(no-chained-type-assertions)

src/tests/responsible-module.test.ts:14:10: This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.
}

describe("findResponsibleFile", () => {
Expand All @@ -43,28 +43,28 @@

it("returns the first non-implementor match even when an implementor appears earlier", () => {
const entries: ModuleFolderEntry[] = [
{ id: "cms", dir: "/project/cms", isImplementor: true },
{ id: "playground", dir: "/project/cms/playground" },
{ id: "dms", dir: "/project/dms", isImplementor: true },
{ id: "playground", dir: "/project/dms/playground" },
];
const trace = [
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/cms/playground/dist/table-view/drawer/page.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("/project/dms/playground/dist/table-view/drawer/page.js"),
];

expect(findResponsibleFile(trace, entries).module).to.equal("playground");
});

it("falls back to the first implementor match when no consumer frame matches", () => {
const entries: ModuleFolderEntry[] = [
{ id: "cms", dir: "/project/cms", isImplementor: true },
{ id: "dms", dir: "/project/dms", isImplementor: true },
];
const trace = [
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/cms/dist/implementations/cms/hooks.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("/project/dms/dist/implementations/dms/hooks.js"),
];

expect(findResponsibleFile(trace, entries).module).to.equal("cms");
expect(findResponsibleFile(trace, entries).module).to.equal("dms");
});

it("returns undefined when no frame matches any module", () => {
Expand All @@ -76,11 +76,11 @@

it("picks the longest matching folder on a single frame", () => {
const entries: ModuleFolderEntry[] = [
{ id: "cms", dir: "/project/cms", isImplementor: true },
{ id: "playground", dir: "/project/cms/playground" },
{ id: "dms", dir: "/project/dms", isImplementor: true },
{ id: "playground", dir: "/project/dms/playground" },
];
const trace = [
frame("/project/cms/playground/dist/table-view/drawer/page.js"),
frame("/project/dms/playground/dist/table-view/drawer/page.js"),
];

expect(findResponsibleFile(trace, entries).module).to.equal("playground");
Expand All @@ -90,14 +90,14 @@
const entries: ModuleFolderEntry[] = [
{ id: "local", dir: "/home/user/app" },
{
id: "cms",
dir: "/home/user/app/.antelope/cache/@antelopejs-private/cms",
id: "dms",
dir: "/home/user/app/.antelope/cache/@antelopejs-private/dms",
isImplementor: true,
},
];
const trace = [
frame(
"/home/user/app/.antelope/cache/@antelopejs-private/cms/dist/interfaces/cms/page.js",
"/home/user/app/.antelope/cache/@antelopejs-private/dms/dist/interfaces/dms/page.js",
),
frame("/home/user/app/dist/pages/skins.js"),
];
Expand All @@ -107,31 +107,31 @@

it("walks past unregistered intermediate frames between implementor and consumer", () => {
const entries: ModuleFolderEntry[] = [
{ id: "cms", dir: "/project/cms", isImplementor: true },
{ id: "playground", dir: "/project/cms/playground" },
{ id: "dms", dir: "/project/dms", isImplementor: true },
{ id: "playground", dir: "/project/dms/playground" },
];
const trace = [
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("/third-party/anon.js", { functionName: null, typeName: "Proxy" }),
frame("/project/cms/playground/dist/page.js"),
frame("/project/dms/playground/dist/page.js"),
];

expect(findResponsibleFile(trace, entries).module).to.equal("playground");
});

it("stops at the module-loader boundary so top-level side effects are attributed to the loading module, not the requirer", () => {
const entries: ModuleFolderEntry[] = [
{ id: "cms", dir: "/project/cms", isImplementor: true },
{ id: "playground", dir: "/project/cms/playground" },
{ id: "dms", dir: "/project/dms", isImplementor: true },
{ id: "playground", dir: "/project/dms/playground" },
];
const trace = [
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/cms/dist/interfaces/cms/page.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("/project/dms/dist/interfaces/dms/page.js"),
frame("node:internal/modules/cjs/loader"),
frame("node:internal/modules/helpers"),
frame("/project/cms/playground/dist/table-view/category.js"),
frame("/project/dms/playground/dist/table-view/category.js"),
];

expect(findResponsibleFile(trace, entries).module).to.equal("cms");
expect(findResponsibleFile(trace, entries).module).to.equal("dms");
});
});
Loading