Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions lib/Hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ class Hook {
} else if (Array.isArray(item.before)) {
before = new Set(item.before);
}
if (before) {
for (const name of before) {
if (!this.taps.some((tap) => tap.name === name)) {
before.delete(name);
}
}
}
let stage = 0;
if (typeof item.stage === "number") {
stage = item.stage;
Expand Down
44 changes: 44 additions & 0 deletions lib/__tests__/Hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,48 @@ describe("Hook", () => {
new Error("Missing name for tap")
);
});

it("should ignore invalid before values", () => {
const hook = new SyncHook();

const calls = [];

hook.tap("A", () => calls.push("A"));

hook.tap(
{
name: "B",
before: "C"
},
() => calls.push("B")
);

hook.tap(
{
name: "C",
before: [" "]
},
() => calls.push("C")
);

hook.tap(
{
name: "D",
before: {}
},
() => calls.push("D")
);

hook.tap(
{
name: "E",
before: null
},
() => calls.push("E")
);

calls.length = 0;
hook.call();
expect(calls).toEqual(["A", "B", "C", "D", "E"]);
});
});