From 62125844567766ef6534ebe08592b4cd68514d94 Mon Sep 17 00:00:00 2001 From: Dmitrii Abramov Date: Wed, 19 Jul 2017 17:20:07 -0700 Subject: [PATCH] fix watch mode --- .../src/__tests__/watch_filename_pattern_mode.test.js | 2 +- packages/jest-cli/src/cli/index.js | 7 +++++++ packages/jest-cli/src/lib/update_global_config.js | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/jest-cli/src/__tests__/watch_filename_pattern_mode.test.js b/packages/jest-cli/src/__tests__/watch_filename_pattern_mode.test.js index 3d56e40f97c3..561840dbba14 100644 --- a/packages/jest-cli/src/__tests__/watch_filename_pattern_mode.test.js +++ b/packages/jest-cli/src/__tests__/watch_filename_pattern_mode.test.js @@ -135,7 +135,7 @@ describe('Watch mode flows', () => { // globalConfig is updated with the current pattern expect(runJestMock.mock.calls[0][0].globalConfig).toEqual({ - onlyChanged: true, + onlyChanged: false, testNamePattern: '', testPathPattern: 'p.*3', watch: true, diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index 65ccc7dc6345..c91eef19f9e3 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -75,6 +75,13 @@ const runCLI = async ( (r: AggregatedResult) => (results = r), ); + if (argv.watch || argv.watchAll) { + // If in watch mode, return the promise that will never resolve. + // If the watch mode is interrupted, watch should handle the process + // shuttdown. + return new Promise(() => {}); + } + if (!results) { throw new Error( 'AggregatedResult must be present after test run is complete', diff --git a/packages/jest-cli/src/lib/update_global_config.js b/packages/jest-cli/src/lib/update_global_config.js index 85f52b5e75f2..9af007f0a738 100644 --- a/packages/jest-cli/src/lib/update_global_config.js +++ b/packages/jest-cli/src/lib/update_global_config.js @@ -50,7 +50,10 @@ module.exports = ( } newConfig.onlyChanged = false; - newConfig.onlyChanged = !newConfig.watchAll && !newConfig.testNamePattern; + newConfig.onlyChanged = + !newConfig.watchAll && + !newConfig.testNamePattern && + !newConfig.testPathPattern; if (options.noSCM) { newConfig.noSCM = true;