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

An *Actual* ".only" #48895

Closed
machineghost opened this issue Jul 23, 2023 · 2 comments
Closed

An *Actual* ".only" #48895

machineghost opened this issue Jul 23, 2023 · 2 comments
Labels
feature request Issues that request new features to be added to Node.js. test_runner Issues and PRs related to the test runner subsystem.

Comments

@machineghost
Copy link

machineghost commented Jul 23, 2023

What is the problem this feature will solve?

Imagine you have a function with 50 tests. You add a console.log to debug just one of those tests, but of course you see console.log output 50x times, creating a giant signal-to-noise ratio problem.

.only solves this in other major testing frameworks. In most other test frameworks I can simply do:

test.only('my test', ...

That's it! I can now run my tests, the exact same way I did before, but now I just see the console.log from the one test I marked as "only".

That's not how it works in Node however. In Node I also have to add:

t.runOnly(true);

to the test's describe ... only that's not enough: I also have to add:

--test-only

to my test-running-command.

You'd think "ok, that's runOnly stuff is pointless boilerplate, but you just add it to every test file and you're fine, right?" Wrong. Because when I run the tests normally, that line causes an error:

TypeError [Error]: t.runOnly is not a function

In other words, to be able to just (occasionally) run a single test, I have to add this boilerplate to every test file:

try {
  t.runOnly(true);
} catch (err) {}

Then I have to switch which test command I use ... and I still have to mark the test as .only (as I would in another framework).

This is all a mess. There should be a way to just run one test out of 50 easily!

What is the feature you are proposing to solve the problem?

Make .only work the same as it does in other major test frameworks (ie. all you need is .only), or add a new feature (with a new name: ".justThis") which works similarly.

What alternatives have you considered?

Going back to Mocha or Jest :(

@machineghost machineghost added the feature request Issues that request new features to be added to Node.js. label Jul 23, 2023
@cjihrig
Copy link
Contributor

cjihrig commented Jul 23, 2023

Closing as a duplicate of #47945.

#47945 (comment) is still applicable though.

@cjihrig cjihrig closed this as completed Jul 23, 2023
@machineghost
Copy link
Author

:(

@MoLow MoLow added the test_runner Issues and PRs related to the test runner subsystem. label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants