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

Add support for globalSetup and globalTeardown in projects #6865

Merged
merged 15 commits into from Dec 25, 2018

Conversation

ranyitz
Copy link
Contributor

@ranyitz ranyitz commented Aug 19, 2018

Summary

This PR solves #5441 and adds support for globalSetup and globalTeardown functions 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/globalTeadown are working only in globalConfig.

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 e2e project, 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.

global-setup-teardown-projects

@ranyitz ranyitz changed the title add globalSetup and globalTeardown for projects Add support for globalSetup and globalTeardown in projects Aug 19, 2018
@codecov-io
Copy link

codecov-io commented Aug 19, 2018

Codecov Report

Merging #6865 into master will increase coverage by 0.04%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-config/src/index.js 37.73% <ø> (ø) ⬆️
packages/jest-cli/src/runJest.js 77.21% <100%> (+7.1%) ⬆️
packages/jest-cli/src/runGlobalHook.js 58.33% <58.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e72341...1a1412d. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Aug 23, 2018

I like this! Would the docs need an update?

@ranyitz
Copy link
Contributor Author

ranyitz commented Aug 24, 2018

@SimenB @thymikee Thanks, I'm not sure what would be the best wording, here are two options:

*After globalSetup section


...

If you are using the projects option and have multiple globalSetup modules, Jest will find the ones that relevant to the current run and will trigger only them before all test suites.


...

A globalSetup module configured in a project will be triggered only when you run at list one test from this project.

@ranyitz ranyitz force-pushed the global-setup-and-teardown-for-projects branch from 14c5c52 to 1a1412d Compare August 29, 2018 23:07
@ranyitz
Copy link
Contributor Author

ranyitz commented Sep 6, 2018

@SimenB Let me know what you think regarding the documentation options. Other than that, is there anything in the PR that needs a fix?

@SimenB
Copy link
Member

SimenB commented Sep 15, 2018

Sorry about the late response! I think those doc changes makes sense, yeah

@ranyitz
Copy link
Contributor Author

ranyitz commented Sep 15, 2018

Thanks @SimenB, I've updated the documentation.

docs/Configuration.md Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Sep 19, 2018

Codecov Report

Merging #6865 into master will increase coverage by 0.04%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/jest-config/src/index.js 37.73% <ø> (ø) ⬆️
packages/jest-cli/src/runJest.js 77.21% <100%> (+7.1%) ⬆️
packages/jest-cli/src/runGlobalHook.js 58.33% <58.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 477f461...bcbc602. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Sep 21, 2018

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?

@cpojer
Copy link
Member

cpojer commented Sep 25, 2018

works for me.

@ranyitz ranyitz force-pushed the global-setup-and-teardown-for-projects branch from b431eb1 to bcbc602 Compare October 7, 2018 23:10
@SimenB SimenB added this to the Jest 24 milestone Oct 16, 2018
@amarchen
Copy link

If inly changelog is different, could somebody with the right access kindly merge the changes?

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Left some nits to address, but looks good over all

@@ -32,6 +32,8 @@ module.exports = {
'/node_modules/',
'/examples/',
'/e2e/.*/__tests__',
'/e2e/global-setup',
'/e2e/global-teardown',
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

e2e/global-teardown/project-2/teardown.test.js Outdated Show resolved Hide resolved
packages/jest-cli/src/runGlobalHook.js Show resolved Hide resolved
packages/jest-cli/src/runGlobalHook.js Outdated Show resolved Hide resolved
await Promise.all(
Array.from(globalModulePaths).map(async modulePath => {
if (!modulePath) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

any scenario where this could happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I did it because globalSetup/globalTeardown are nullables and can also be an empty string.

https://github.com/facebook/jest/blob/c1d3de5e315d4dc01acfe33abd7de4fe7d4591ea/types/Config.js#L120-L121

I did not write any specific test for this use case, but Jest's tests would not pass without this condition.

thymikee and others added 3 commits December 19, 2018 00:33
Co-Authored-By: ranyitz <ranyitz@users.noreply.github.com>
Co-Authored-By: ranyitz <ranyitz@users.noreply.github.com>
@ranyitz
Copy link
Contributor Author

ranyitz commented Dec 18, 2018

@thymikee Thanks for the review!

@SimenB SimenB merged commit 698c33c into jestjs:master Dec 25, 2018
@ranyitz ranyitz deleted the global-setup-and-teardown-for-projects branch December 25, 2018 17:00
devaradhanm added a commit to microsoft/accessibility-insights-web that referenced this pull request Feb 5, 2019
jestjs/jest#6865

updating deprecated property

remove tsconfig.jest.json

ignore d.ts files form coverage

This reverts commit 7875345cadaee70b4f2cb2c2d5d3d8554fe0354f.
devaradhanm added a commit to microsoft/accessibility-insights-web that referenced this pull request Feb 6, 2019
* 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
captain-yossarian pushed a commit to captain-yossarian/jest that referenced this pull request Jul 18, 2019
@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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants