Skip to content

An *Actual* ".only" #48895

Closed
Closed
@machineghost

Description

@machineghost

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 :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions