Skip to content

🚀 Feature: Support .only in parallel mode #5450

@sam-super

Description

@sam-super

Feature Request Checklist

Overview

I think support .only in parallel mode would be a big win for developer experience when using mocha.

It makes total sense as to why it's not currently supported:

in parallel mode, Mocha does not load all files and suites into memory before running tests

I have checked for an existing issue (i expected to find one, so apologies if i missed it):
https://github.com/mochajs/mocha/issues?q=parallel%20only%20in%3Atitle

Suggested Solution

If we can support it, I'm thinking that something like a preloadTestFiles: true config option could enable this. Having test files loaded in the main/parent thread would allow us to filter the test files that don't have .only tests in them (assuming at least 1 .only is found). This method would make the new functionality opt-in and avoid unexpected side effects from loading each test file in the main thread.

If someone could indicate if there is any appetite for this change then i'm willing to give creating a PR for it a go (although as a disclaimer it might be too much of a fundamental change, given my limited experience working in the mocha codebase).

Alternatives

as currently suggested in the docs users can add --grep <testname> instead of .only or --parallel=false but this make the process quite clunky and un-intuitive (esp for people used to using jest).

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: in triagea maintainer should (re-)triage (review) this issuetype: featureenhancement proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions