Skip to content
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

📎 Implement lint/noExclusiveTests - eslint-plugin-jest/no-focused-tests, eslint-plugin-mocha/no-exclusive-tests, eslint-plugin-no-only-tests #597

Closed
Conaclos opened this issue Oct 25, 2023 · 8 comments · Fixed by #1999
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@Conaclos
Copy link
Member

Conaclos commented Oct 25, 2023

Description

Implement no-focused-tests / no-exclusive-tests / no-only-test.

I think we could restrict the rule to test.only, describe.only and it.only.

Want to contribute? Lets you know you are interested! We will assign you to the issue to prevent several people to work on the same issue. Don't worry, we can unassign you later if you are no longer interested in the issue! Read our contributing guide and analyzer contributing guide.

This was proposed by @emab.

@Conaclos Conaclos added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 25, 2023
@ematipico
Copy link
Member

ematipico commented Oct 25, 2023

I think we could restrict the rule to test.only, describe.only and it.only.

This choice is debatable, so we should really understand the rule's criteria. The original rule is made for mocha only, so should we do the same? What about other testing libraries?

For example, tape: https://www.npmjs.com/package/tape#testonlyname-opts-cb, where a user can import tape like const t = require("tape"), so it would t.only.

@ematipico ematipico added the S-Needs discussion Status: needs a discussion to understand criteria label Oct 25, 2023
@Conaclos Conaclos changed the title 📎 Implement lint/noExclusiveTests - eslint-plugin-mocha/no-exclusive-tests 📎 Implement lint/noExclusiveTests - eslint-plugin-jest/no-focused-tests, eslint-plugin-mocha/no-exclusive-tests Oct 25, 2023
@Conaclos
Copy link
Member Author

Conaclos commented Oct 25, 2023

We can ship a first version which supports the most common usages. describe, test, and it are widely used by test frameworks (AVA, Jasmine, Jest, Mocha, Tape, ...).

I am not fond of tracking potential renaming of these functions because this implies maintaining a list of supported frameworks.

However, some rules could be dedicated to a test framework. Since most of test frameworks rely on implicit globals 🤮, we should add a way to declare the use of a framework in the configuration or a way to detect it (e.g. via package.json dev dependencies).

@ematipico
Copy link
Member

Sounds like a good plan!

@ematipico ematipico removed the S-Needs discussion Status: needs a discussion to understand criteria label Oct 26, 2023
@emab
Copy link
Contributor

emab commented Oct 30, 2023

Maybe could be a configuration option, but having a comment above a skipped test explaining why it was skipped can be extremely useful. Is this something we could consider?

@Conaclos
Copy link
Member Author

Maybe could be a configuration option, but having a comment above a skipped test explaining why it was skipped can be extremely useful. Is this something we could consider?

You can already use an ignore comment with the reason. This should fulfill your request?

@emab
Copy link
Contributor

emab commented Oct 30, 2023

I think this rule will allow you to use .skip, and doesn't force you to explain why you are skipping?

E.g. this rule will stop this:

describe.only("test", () => {});

But you can add a comment here:

// biome-ignore lint/suspicious/noExclusiveTests: I really want to run this test only!
describe.only("test", () => {});

But we will still be allowing this:

describe.skip("test", () => {});

I'm wondering if a config option requires a comment above a skipped test (not a .only test), for example:

describe.skip("test", () => {}); // lint failure - skipped test requires a comment

// TODO: Skipping until EXAMPLE-123 is completed
describe.skip("test", () => {});

@Conaclos
Copy link
Member Author

Conaclos commented Oct 30, 2023

I think this rule will allow you to use .skip, and doesn't force you to explain why you are skipping?

Oh yes, sorry I misread your request. I think this would be better served by a dedicated rule noSkippedTests. What do you think?

@Conaclos Conaclos changed the title 📎 Implement lint/noExclusiveTests - eslint-plugin-jest/no-focused-tests, eslint-plugin-mocha/no-exclusive-tests 📎 Implement lint/noExclusiveTests - eslint-plugin-jest/no-focused-tests, eslint-plugin-mocha/no-exclusive-tests, eslint-plugin-no-only-tests Dec 12, 2023
@chansuke
Copy link
Member

chansuke commented Jan 1, 2024

I'd like to work on this issue 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
4 participants