New defaults for Jest. #1511

Merged
merged 1 commit into from Aug 30, 2016

Conversation

Projects
None yet
4 participants
@cpojer
Contributor

cpojer commented Aug 30, 2016

For Jest 15 we are going to ship with a ton of new defaults that should make the experience of using Jest better. With this, I also removed a bunch of outdated documentation from the website – however I feel like we should completely rewrite the documentation on the website and replace it with better, useful, step-by-step guides (cc @lacker).

This diff:

  • Disables automocking by default.
  • Uses real timers by default. Adds a timers: 'fake' | 'real' config option for global control.
  • Doesn't implicitly reset the module registry after every test. Adds jest.resetModules and a resetModules config option for better control.
  • Includes .test.js and .spec.js in the default testRegex.
  • Completely removes some deprecated configuration options and makes Jest throw with helpful error messages so that it will be easy for people to upgrade.
  • Adds a warning when jest.unmock is used to either enable automocking or remove the unmock calls. Similarly Jest now logs a warning if automocking isn't used but unmockedModulePathPatterns is specified.
  • Updates the docs to reflect the new defaults and removes some outdated pages.
  • Fixes two minor reporter bugs: the verbose reporter now prints the test header before any test results and top level test or it calls don't print a > right after the * bullet. (* works instead of * > works). I know this should have gone into separate diffs, but you know, sue me.
  • Removes obsolete testEnvData config option.

At Facebook we will continue to use automocking and fake timers for the foreseeable future and both features will continue to be part of Jest long term. Especially the auto mocking feature at this point is easy to maintain and the explicit auto-mocking using jest.mock is incredibly valuable. However, it makes a lot of sense for libraries and beginners to start with sane defaults. Automocking is valuable for big organizations that do not have a unit testing culture. I will elaborate this in the release blog post but wanted to give a few hints in here.

TODO: I'll add a few tests for the new errors tomorrow :)

cc @gaearon

@ghost ghost added the CLA Signed ✔️ label Aug 30, 2016

@suchipi

This comment has been minimized.

Show comment
Hide comment
@suchipi

suchipi Aug 30, 2016

Contributor

Excited for this release! Looking forward to new docs, too. I just picked up jest for a new personal project (via create-react-app#master) and it wasn't clear to me if I was supposed to require at top-level or within test cases (or in beforeEach), how jest.doMock will affect future test runs, whether a mock will persist outside the describe it was defined in, etc. I think a page giving a high-level overview of when jest will mock modules and how that works would help with that a ton.

Contributor

suchipi commented Aug 30, 2016

Excited for this release! Looking forward to new docs, too. I just picked up jest for a new personal project (via create-react-app#master) and it wasn't clear to me if I was supposed to require at top-level or within test cases (or in beforeEach), how jest.doMock will affect future test runs, whether a mock will persist outside the describe it was defined in, etc. I think a page giving a high-level overview of when jest will mock modules and how that works would help with that a ton.

@probablyup

This comment has been minimized.

Show comment
Hide comment
@probablyup

probablyup Aug 30, 2016

Contributor

This is really great stuff @cpojer :) completely gets rid of the few config changes I had in package.json ;)

Contributor

probablyup commented Aug 30, 2016

This is really great stuff @cpojer :) completely gets rid of the few config changes I had in package.json ;)

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Aug 30, 2016

Current coverage is 63.09% (diff: 47.27%)

Merging #1511 into master will increase coverage by 0.24%

@@             master      #1511   diff @@
==========================================
  Files            97         97          
  Lines          3647       3647          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           2292       2301     +9   
+ Misses         1355       1346     -9   
  Partials          0          0          

Powered by Codecov. Last update 84516ce...9faefb3

codecov-io commented Aug 30, 2016

Current coverage is 63.09% (diff: 47.27%)

Merging #1511 into master will increase coverage by 0.24%

@@             master      #1511   diff @@
==========================================
  Files            97         97          
  Lines          3647       3647          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           2292       2301     +9   
+ Misses         1355       1346     -9   
  Partials          0          0          

Powered by Codecov. Last update 84516ce...9faefb3

@cpojer

This comment has been minimized.

Show comment
Hide comment
@cpojer

cpojer Aug 30, 2016

Contributor

Alright, should be good to go. Updated some older tests and added new ones.

Contributor

cpojer commented Aug 30, 2016

Alright, should be good to go. Updated some older tests and added new ones.

@cpojer cpojer merged commit 3bbf32a into facebook:master Aug 30, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment