test(hooks): dedupe unsupported npm spec assertion

This commit is contained in:
Peter Steinberger
2026-02-21 23:23:24 +00:00
parent d325c01503
commit 9ec440d1f4

View File

@@ -60,6 +60,17 @@ function writeArchiveFixture(params: { fileName: string; contents: Buffer }) {
};
}
async function expectUnsupportedNpmSpec(
install: (spec: string) => Promise<{ ok: boolean; error?: string }>,
) {
const result = await install("github:evil/evil");
expect(result.ok).toBe(false);
if (result.ok) {
return;
}
expect(result.error).toContain("unsupported npm spec");
}
describe("installHooksFromArchive", () => {
it.each([
{
@@ -365,12 +376,7 @@ describe("installHooksFromNpmSpec", () => {
});
it("rejects non-registry npm specs", async () => {
const result = await installHooksFromNpmSpec({ spec: "github:evil/evil" });
expect(result.ok).toBe(false);
if (result.ok) {
return;
}
expect(result.error).toContain("unsupported npm spec");
await expectUnsupportedNpmSpec((spec) => installHooksFromNpmSpec({ spec }));
});
it("aborts when integrity drift callback rejects the fetched artifact", async () => {