-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(rule-tester): allow to create empty tests #7467
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
feat(rule-tester): allow to create empty tests #7467
Conversation
Thanks for the PR, @azat-io! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
The code changes look nifty but let's discuss in a backing issue. The rule tester is an important part of the public API and I'm not sure we want to do this without talking it over first.
I would like to be able to skip valid or invalid scenarios in some tests. In some cases, such examples are simply not needed. Some simple example: import noLetRule from '../rule/no-let'
ruleTester.run(
`disallow to use let`,
rule,
{
valid: [],
invalid: [`let a = 1`],
},
) |
Issue #7481 |
@JoshuaKGoldberg Could you review this PR? This pull request is the last step to upgrade to version 6 before the big release in our ESLint plugin: azat-io/eslint-plugin-perfectionist#32 The same PR in ESLint also was merged: eslint/eslint#17475 |
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.
Changes look good, thanks for keeping on this!
Could you please add some unit tests for the new logic though? Conditionally skipping tests is a kind of behavior that's easy to trip up over time.
@JoshuaKGoldberg Hmm. Can you tell me the best way to do that? Since this problem occurs only when using RuleTester with Vitest. Because of this: https://github.com/vitest-dev/vitest/blob/main/packages/runner/src/run.ts#L331-L338 |
See the tests at the bottom of
They show running it('does not call describe with valid if no valid tests are provided', () => {
const ruleTester = new RuleTester();
ruleTester.run('my-rule', NOOP_RULE, {
valid: [],
invalid: [
{
code: 'invalid',
errors: [{ messageId: 'error' }],
},
],
});
expect(mockedDescribe.mock.calls) // ... |
@JoshuaKGoldberg Thanks. Done. |
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.
Awesome! I actually stumbled onto a want for this recently 😄 so it's very exciting to see it come in. Thanks as always @azat-io!
PR Checklist
Overview
In some cases I only need to test for valid or invalid scenarios.
For example, if I want to check that a rule for the ESLint plugin works with different code stylings. Or that a rule does not apply to a certain file extension.
Example:
This test is currently crashing with an error:
Error: No test found in suite invalid