Skip to content

Commit

Permalink
Tweak Jest default settings (#378)
Browse files Browse the repository at this point in the history
Disable timer mocking and enable verbose output.
  • Loading branch information
gaearon authored Aug 5, 2016
1 parent 6fb517a commit 8084a32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions config/jest/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Currently, Jest mocks setTimeout() and similar functions by default:
// https://facebook.github.io/jest/docs/timer-mocks.html
// We think this is confusing, so we disable this feature.
// If you see value in it, run `jest.useFakeTimers()` in individual tests.
beforeEach(() => {
jest.useRealTimers();

This comment has been minimized.

Copy link
@cpojer

cpojer Aug 8, 2016

Contributor

You don't need to do this in beforeEach. It should be enough to do this in this file and call it just once.

I'll make an option for this for Jest 15 so we can remove this.

This comment has been minimized.

Copy link
@gaearon

gaearon Aug 8, 2016

Author Contributor

I want useFakeTimers() in user code to have it scoping. When I put useRealTimers() outside this block, using useFakeTimers() inside an it leaked it to all other its. I want it to be completely local and “go back” after each test.

This comment has been minimized.

Copy link
@cpojer

cpojer Aug 8, 2016

Contributor

I see, that actually makes a lot of sense and it should probably be the default. I don't know how many tests at FB would fail if we change this, so would need to try (it is probably more than 300-500)

});
1 change: 1 addition & 0 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ prompt(
path.join('config', 'webpack.config.prod.js'),
path.join('config', 'jest', 'CSSStub.js'),
path.join('config', 'jest', 'FileStub.js'),
path.join('config', 'jest', 'environment.js'),
path.join('config', 'jest', 'transform.js'),
path.join('scripts', 'build.js'),
path.join('scripts', 'start.js'),
Expand Down
4 changes: 3 additions & 1 deletion scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module.exports = (resolve, rootDir) => {
setupFiles: [
resolve('config/polyfills.js')
],
testEnvironment: 'node'
setupTestFrameworkScriptFile: resolve('config/jest/environment.js'),

This comment has been minimized.

Copy link
@cpojer

cpojer Aug 8, 2016

Contributor

I think this should be in setupFiles.

We used to have setupTestFrameworkScriptFile and setupTestEnvironmentScriptFile for some reason. One runs before jasmine and setupTestFrameworkScriptFile runs after jasmine. I simplified it to setupFiles and made it an array and it is what most people will probably want to use but the other hook can still be useful. Maybe we should make the docs more clear.

testEnvironment: 'node',
verbose: true
};
if (rootDir) {
config.rootDir = rootDir;
Expand Down

0 comments on commit 8084a32

Please sign in to comment.