Add support for globalSetup and globalTeardown in projects#6865
Add support for globalSetup and globalTeardown in projects#6865SimenB merged 15 commits intojestjs:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6865 +/- ##
==========================================
+ Coverage 66.98% 67.02% +0.04%
==========================================
Files 250 251 +1
Lines 10365 10369 +4
Branches 4 3 -1
==========================================
+ Hits 6943 6950 +7
+ Misses 3421 3418 -3
Partials 1 1
Continue to review full report at Codecov.
|
|
I like this! Would the docs need an update? |
|
@SimenB @thymikee Thanks, I'm not sure what would be the best wording, here are two options: *After globalSetup section
|
14c5c52 to
1a1412d
Compare
|
@SimenB Let me know what you think regarding the documentation options. Other than that, is there anything in the PR that needs a fix? |
|
Sorry about the late response! I think those doc changes makes sense, yeah |
|
Thanks @SimenB, I've updated the documentation. |
Codecov Report
@@ Coverage Diff @@
## master #6865 +/- ##
==========================================
+ Coverage 66.61% 66.66% +0.04%
==========================================
Files 253 254 +1
Lines 10626 10630 +4
Branches 4 4
==========================================
+ Hits 7079 7086 +7
+ Misses 3546 3543 -3
Partials 1 1
Continue to review full report at Codecov.
|
|
I think this makes sense, and is also how I think most global options should be handled. I think if you think of Jest as a generic runner, rather than just a test runner, this change makes sense. @cpojer thoughts? |
|
works for me. |
b431eb1 to
bcbc602
Compare
|
If inly changelog is different, could somebody with the right access kindly merge the changes? |
thymikee
left a comment
There was a problem hiding this comment.
Left some nits to address, but looks good over all
| '/examples/', | ||
| '/e2e/.*/__tests__', | ||
| '/e2e/global-setup', | ||
| '/e2e/global-teardown', |
There was a problem hiding this comment.
not sure why this is needed?
There was a problem hiding this comment.
Those directories are fixtures to the tests that in __tests__ directory. The test files inside should be run from /e2e/__tests__/global_setup.test.js and /e2e/__tests__/global_teardown.test.js.
| await Promise.all( | ||
| Array.from(globalModulePaths).map(async modulePath => { | ||
| if (!modulePath) { | ||
| return null; |
There was a problem hiding this comment.
any scenario where this could happen?
There was a problem hiding this comment.
I think I did it because globalSetup/globalTeardown are nullables and can also be an empty string.
I did not write any specific test for this use case, but Jest's tests would not pass without this condition.
Co-Authored-By: ranyitz <ranyitz@users.noreply.github.com>
Co-Authored-By: ranyitz <ranyitz@users.noreply.github.com>
|
@thymikee Thanks for the review! |
jestjs/jest#6865 updating deprecated property remove tsconfig.jest.json ignore d.ts files form coverage This reverts commit 7875345cadaee70b4f2cb2c2d5d3d8554fe0354f.
* upgrading jest to support global setup on multi-projects; jestjs/jest#6865 updating deprecated property remove tsconfig.jest.json ignore d.ts files form coverage * fix e2e root dir path
|
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. |
Summary
This PR solves #5441 and adds support for
globalSetupandglobalTeardownfunctions in projects.Motivation
There are multiple usaged for
projects. Some use them for multiple packages in a monorepo and some for running multiple environments/runners.Today,
globalSetup/globalTeadownare working only inglobalConfig.In most cases it would be nice if Jest would know how to run only the relevant setup for the specific tests that we choose to run.
For example, bootstrap puppeteer only if we are in the
e2eproject, or if we choose to run an e2e file at the moment (which needs setup). It would be also nice to not bootstrap puppeteer if we only run component tests.