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

[Bug]: test.concurrent does not respect testNamePattern #12588

Closed
rix0rrr opened this issue Mar 18, 2022 · 5 comments · Fixed by #12748
Closed

[Bug]: test.concurrent does not respect testNamePattern #12588

rix0rrr opened this issue Mar 18, 2022 · 5 comments · Fixed by #12748

Comments

@rix0rrr
Copy link

rix0rrr commented Mar 18, 2022

Version

27.5.1

Steps to reproduce

Code:

// example.test.js
test.concurrent('one', async () => {
    console.log('running test one');
});

test.concurrent('two', async () => {
    console.log('running test two');
});

Commands:

$ npm init -y
$ npm install jest
$ npx jest -t one

Expected behavior

I expect to see only:

running test one

Actual behavior

I see both console.logs printed, while the test report pretends it only ran one test:

  console.log
    running test one

      at bla.test.js:2:13

  console.log
    running test two

      at bla.test.js:6:13

 PASS  ./bla.test.js
  ✓ one (1 ms)
  ○ skipped two

Test Suites: 1 passed, 1 total
Tests:       1 skipped, 1 passed, 2 total
Snapshots:   0 total
Time:        0.292 s, estimated 1 s
Ran all test suites with tests matching "one".

Additional context

No response

Environment

System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 16.4.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.18.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^27.5.1 => 27.5.1
rix0rrr added a commit to aws/aws-cdk that referenced this issue Mar 18, 2022
Turns out that Jest's `test.concurrent()` does not play well when
running `jest -t TESTNAME`: jest will actually start all tests,
not just the one you were trying to run.

Reported here: jestjs/jest#12588

We used to have something to opt-out of concurrent running: we
have to flip that around, and opt in to concurrent running only
for the canary and pipeline tests, where we *know* for a fact
we're not filtering.
rix0rrr added a commit to aws/aws-cdk that referenced this issue Mar 18, 2022
Turns out that Jest's `test.concurrent()` does not play well when
running `jest -t TESTNAME`: jest will actually start all tests,
not just the one you were trying to run.

Reported here: jestjs/jest#12588

We used to have something to opt-out of concurrent running: we
have to flip that around, and opt in to concurrent running only
for the canary and pipeline tests, where we *know* for a fact
we're not filtering.
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Mar 21, 2022
Turns out that Jest's `test.concurrent()` does not play well when
running `jest -t TESTNAME`: jest will actually start all tests,
not just the one you were trying to run.

Reported here: jestjs/jest#12588

We used to have something to opt-out of concurrent running: we
have to flip that around, and opt in to concurrent running only
for the canary and pipeline tests, where we *know* for a fact
we're not filtering.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@F3n67u
Copy link
Contributor

F3n67u commented Mar 29, 2022

I think the problem is:
the test.concurrent executes the test code immediately, when we start the test, the promise will already be in the process of execution, so testNamePattern cannot stop test.concurrent from running. this details is digged from the jest source code comment.

https://github.com/facebook/jest/blob/f496a93a6dfe5dc1f87745afda455d065630369e/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L79-L96

This problem has a long history. It was introduced by #6267. and test.concurrent is still an experimental feature now.

test.concurrent is considered experimental - see here for details on missing features and other issues

I don't have any experience with test.concurrent, so I don't know how to fix that.

@rix0rrr
Copy link
Author

rix0rrr commented Mar 29, 2022

I saw the note it was "experimental". The note could have said "selecting specific tests to run is impossible with test.concurrent(), either using .only or using --testNamePattern (-t)".

It looks like this was done to avoid having to make changes to the runner itself. The runner remains sequential.

@F3n67u
Copy link
Contributor

F3n67u commented Mar 31, 2022

I saw the note it was "experimental". The note could have said "selecting specific tests to run is impossible with test.concurrent(), either using .only or using --testNamePattern (-t)".

@rix0rrr would you mind making a pr to suggest those changes to jest doc?

@F3n67u
Copy link
Contributor

F3n67u commented Mar 31, 2022

@SimenB please add Area:concurrent tag to this issue. so that our users could follow through with the doc of test.concurrent.

test.concurrent is considered experimental - see here for details on missing features and other issues
from https://jestjs.io/docs/api#testconcurrentname-fn-timeout

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants