New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: rule tester ignore irrelevant test case properties #18235
fix: rule tester ignore irrelevant test case properties #18235
Conversation
Hi @DMartens!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
✅ Deploy Preview for docs-eslint canceled.
|
Hi @DMartens!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a question about the tests, otherwise LGTM! 👍
lib/rule-tester/rule-tester.js
Outdated
const normalizedItem = typeof item === "string" ? { code: item } : item; | ||
const serializedTestCase = stringify(normalizedItem, { replacer: (key, value) => (!duplicationIgnoredParameters.has(key) ? value : void 0) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only exclude top-level test case properties. Otherwise, if the rule has options with these names, test cases like the following would be mistakenly detected as duplicates:
{
code: "var foo;",
options: [{ name: "bar" }]
},
{
code: "var foo;",
options: [{ name: "baz" }]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I resolved this via checking whether the current context object this
is the root test case object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! Would like another review before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for contributing!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain: Rule Tester
What changes did you make? (Give an overview)
Fixes #18173.
Ignore the properties
name
,errors
andoutput
as they are irrelevant when checking for duplicate test cases by using the replacer argument of the JSON stringifier.Unfortunately the custom JSON stringifier does not support the array form of the
JSON.stringify
replacer.Also normalized valid string test cases to the object form, as otherwise the following would not be detected:
Is there anything you'd like reviewers to focus on?
Some additional duplicate test cases of core rules were flagged and I tried to resolve the errors the best I could.
For example some test cases checked only the location and later other properties were tested.
Rather than merging the test cases, I opted to change the identifier names to keep the intent of the test cases.