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
New: Add name to RuleTester #15179
New: Add name to RuleTester #15179
Conversation
|
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!
What happens in older eslints’ RuleTesters when test cases have a name provided? Most eslint plugins cover multiple eslint versions, so new features aren’t useful in a reasonable time frame unless they’re backwards compatible. |
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!
@ljharb I think they will be ignored. I’m not sure it matters either way, as this only affects the rule developer who has control over the ESLint version used. |
@nzakas great! the rule developer has "control" in the sense that they could semver-major and drop all older eslint versions, but in practice the rule developer does not have control of this, because breaking changes cause churn and pain for their users. |
Marked as accepted since the issue is accepted. |
Top-level properties that are not RuleTesterParameters are passed through as eslint config options, so the test case will fail due to Error: ESLint configuration in rule-tester is invalid:
- Unexpected top-level property "name". |
@mdjermanovic thats what i was afraid of, that means that the eslint ecosystem can’t use this feature in RuleTester until eslint < 8 is no longer supported - given that i have plugins still supporting eslint 2, that will be a long time. Any thought to removing the “throw on unknown properties” behavior, since that’s what breaks forward compatibility? |
I'd prefer not in this case, as that would silently ignore typos in test cases, while it's relatively easy to extend RuleTester and remove unsupported properties. const { RuleTester } = require("eslint");
const supportsName = false; // ... check ESLint version
module.exports = class MyRuleTester extends RuleTester {
run(ruleName, rule, test) {
if (!supportsName) {
[...test.valid, ...test.invalid].forEach(testCase => {
if (typeof testCase === "object") {
delete testCase.name;
}
});
}
super.run(ruleName, rule, test);
}
} |
Agree. I don’t holding back progress for the sake of forward compatibility is a good approach. You can always just not use “name” at all in your tests and there will be no difference. |
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!
Thanks for contributing! |
Thx for the feature |
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 autofixing to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Implemented support for naming test cases, which can be useful when you're debugging some tests that have very similar code (especially when you're in the final cleanup stages and trying to update all those
column
&endColumn
numbers 😅), or when your test code is very looooooooong so you want to give it a name to make it easier on your terminal if it fails.If a
name
isn't provided or is an empty string, we fallback to the current behavior of usingcode
.Is there anything you'd like reviewers to focus on?
Closes #15090