Skip to content

Commit

Permalink
fix: only ignore top-level test case properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DMartens committed Mar 28, 2024
1 parent e62558d commit 56d7198
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rule-tester/rule-tester.js
Expand Up @@ -873,7 +873,13 @@ class RuleTester {
}

const normalizedItem = typeof item === "string" ? { code: item } : item;
const serializedTestCase = stringify(normalizedItem, { replacer: (key, value) => (!duplicationIgnoredParameters.has(key) ? value : void 0) });
const serializedTestCase = stringify(normalizedItem, {
replacer(key, value) {

// "this" is the currently stringified object --> only ignore top-level properties
return (normalizedItem !== this || !duplicationIgnoredParameters.has(key)) ? value : void 0;
}
});

assert(
!seenTestCases.has(serializedTestCase),
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -3195,6 +3195,18 @@ describe("RuleTester", () => {
}, "detected duplicate test case");
});

it("does not ignore top level test case properties nested in other test case properties", () => {
ruleTester.run("foo", {
meta: { schema: [{ type: "object" }] },
create() {
return {};
}
}, {
valid: [{ options: [{ name: "foo" }], name: "foo", code: "same" }, { options: [{ name: "bar" }], name: "bar", code: "same" }],
invalid: []
});
});

it("does not throw an error for defining the same test case in different run calls", () => {
const rule = {
meta: {},
Expand Down

0 comments on commit 56d7198

Please sign in to comment.