Skip to content

Commit

Permalink
Always use workers when using the watch mode (#6647)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjesun authored Jul 6, 2018
1 parent d16d420 commit 664681a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## master

### Fixes

- `[jest-runner]` Force parallel runs for watch mode, to avoid TTY freeze ([#6647](https://github.com/facebook/jest/pull/6647))

## 23.3.0

### Features
Expand Down
26 changes: 18 additions & 8 deletions packages/jest-cli/src/test_scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import TestRunner from 'jest-runner';
import TestWatcher from './test_watcher';
import VerboseReporter from './reporters/verbose_reporter';

const SLOW_TEST_TIME = 3000;
const SLOW_TEST_TIME = 1000;

// The default jest-runner is required because it is the default test runner
// and required implicitly through the `runner` ProjectConfig option.
Expand Down Expand Up @@ -85,15 +85,25 @@ export default class TestScheduler {
getEstimatedTime(timings, this._globalConfig.maxWorkers) / 1000,
);

// Run in band if we only have one test or one worker available.
// If we are confident from previous runs that the tests will finish quickly
// we also run in band to reduce the overhead of spawning workers.
const runInBand =
// Run in band if we only have one test or one worker available, unless we
// are using the watch mode, in which case the TTY has to be responsive and
// we cannot schedule anything in the main thread. Same logic applies to
// watchAll.
//
// If we are confident from previous runs that the tests will finish
// quickly we also run in band to reduce the overhead of spawning workers.
const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);

const runInBandWatch = tests.length <= 1 && areFastTests;
const runInBandNonWatch =
this._globalConfig.maxWorkers <= 1 ||
tests.length <= 1 ||
(tests.length <= 20 &&
timings.length > 0 &&
timings.every(timing => timing < SLOW_TEST_TIME));
(tests.length <= 20 && timings.length > 0 && areFastTests);

const runInBand =
this._globalConfig.watch || this._globalConfig.watchAll
? runInBandWatch
: runInBandNonWatch;

const onResult = async (test: Test, testResult: TestResult) => {
if (watcher.isInterrupted()) {
Expand Down

0 comments on commit 664681a

Please sign in to comment.