From 8084a326f0ecaa2d1848a42ae1306767b39533ab Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 5 Aug 2016 18:39:50 +0100 Subject: [PATCH] Tweak Jest default settings (#378) Disable timer mocking and enable verbose output. --- config/jest/environment.js | 7 +++++++ scripts/eject.js | 1 + scripts/utils/createJestConfig.js | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 config/jest/environment.js diff --git a/config/jest/environment.js b/config/jest/environment.js new file mode 100644 index 00000000000..e7c1df906c6 --- /dev/null +++ b/config/jest/environment.js @@ -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(); +}); diff --git a/scripts/eject.js b/scripts/eject.js index 82202d6eed9..55661d19285 100644 --- a/scripts/eject.js +++ b/scripts/eject.js @@ -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'), diff --git a/scripts/utils/createJestConfig.js b/scripts/utils/createJestConfig.js index 282705f0dd3..d4ee867f473 100644 --- a/scripts/utils/createJestConfig.js +++ b/scripts/utils/createJestConfig.js @@ -19,7 +19,9 @@ module.exports = (resolve, rootDir) => { setupFiles: [ resolve('config/polyfills.js') ], - testEnvironment: 'node' + setupTestFrameworkScriptFile: resolve('config/jest/environment.js'), + testEnvironment: 'node', + verbose: true }; if (rootDir) { config.rootDir = rootDir;