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

fix(jest-circus): improve test.concurrent #12748

Merged
merged 2 commits into from
Apr 26, 2022

Conversation

dmitri-gb
Copy link
Contributor

@dmitri-gb dmitri-gb commented Apr 26, 2022

Summary

This change is a minor rewrite of the implementation of test.concurrent in jest-circus. It moves the test function invocation to a later point in time, so that it would be possible to apply proper test filtering (focused tests, testNamePattern, describe.skip). Previously such filtering was not applied to concurrent tests and they were always invoked.

Additionally, concurrent tests are now invoked after the global (top-level) beforeAll hooks. Previously this was not the case.

Finally, beforeEach and afterEach hooks are no longer invoked for concurrent tests at all. Previously both hooks were invoked after (or during) the test.

Test plan

Some existing tests for concurrent have been modified to verify the changes described above.

An illustrative example:

beforeAll(() => {
  console.log('running beforeAll');
});

it.concurrent('test A', async () => {
  console.log('message from test A');
});

it.concurrent('test B', async () => {
  console.log('message from test B');
});
jest -t "test B"

Before:

  console.log
    message from test A

      at Object.log [as fn] (main.test.js:8:11)

  console.log                                                                                                                                                                                                                                         
    message from test B                                                                                                                                                                                                                               

      at Object.log [as fn] (main.test.js:12:11)

  console.log
    running beforeAll

      at Object.log (main.test.js:4:11)

 PASS  ./main.test.js
  √ test B                                                                                                                                                                                                                                            
  ○ skipped test A

After:

  console.log
    running beforeAll

      at Object.log (main.test.js:4:11)

  console.log                                                                                                                                                                                                                                         
    message from test B                                                                                                                                                                                                                               

      at Object.log [as fn] (main.test.js:12:11)

 PASS  ./main.test.js
  √ test B (1 ms)
  ○ skipped test A

Fixes #4281
Fixes #10790
Fixes #11248
Fixes #12068
Fixes #12588

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, wow, this is fantastic!

could you fix the linting errors and add a changelog entry?

@dmitri-gb
Copy link
Contributor Author

@SimenB done!

@SimenB
Copy link
Member

SimenB commented Apr 26, 2022

Thanks!

@SimenB SimenB merged commit d9f6aaf into jestjs:main Apr 26, 2022
@SimenB
Copy link
Member

SimenB commented Apr 26, 2022

F3n67u pushed a commit to F3n67u/jest that referenced this pull request May 2, 2022
@github-actions
Copy link

This pull request 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.