diff --git a/CHANGELOG.md b/CHANGELOG.md index 091499af1e48..fec27bc417ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ promises ([#5670](https://github.com/facebook/jest/pull/5670)) * `[expect]` Add isError to utils ([#5670](https://github.com/facebook/jest/pull/5670)) +* `[jest-cli]` Add `serial` property that runners can expose to specify that + they can not run in parallel (#5706) ### Fixes diff --git a/docs/Configuration.md b/docs/Configuration.md index dc70b54fd4f6..89ce3ba393ba 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -703,6 +703,10 @@ async runTests( ): Promise ``` +If you need to restrict your test-runner to only run in serial rather then being +exectued in paralell your class should have the static attribute `serial` to be +set as `true`. + ### `setupFiles` [array] Default: `[]` diff --git a/packages/jest-cli/src/__tests__/test_scheduler.test.js b/packages/jest-cli/src/__tests__/test_scheduler.test.js index 352e62a62771..b7bfec5877e8 100644 --- a/packages/jest-cli/src/__tests__/test_scheduler.test.js +++ b/packages/jest-cli/src/__tests__/test_scheduler.test.js @@ -12,6 +12,11 @@ import TestScheduler from '../test_scheduler'; import SummaryReporter from '../reporters/summary_reporter'; jest.mock('../reporters/default_reporter'); +const mockSerialRunner = { + serial: true, + runTests: jest.fn() +}; +jest.mock('jest-runner-serial', () => jest.fn(() => mockSerialRunner)); test('.addReporter() .removeReporter()', () => { const scheduler = new TestScheduler({}, {}); @@ -21,3 +26,23 @@ test('.addReporter() .removeReporter()', () => { scheduler.removeReporter(SummaryReporter); expect(scheduler._dispatcher._reporters).not.toContain(reporter); }); + +test('serial option in runner call runTests with serial', asnyc() => { + const scheduler = new TestScheduler({}, {}); + const tests = [{ + context: { + config: { + runner: 'jest-runner-serial' + }, + hasteFS: HasteFS, + moduleMap: ModuleMap, + resolver: HasteResolver, + }, + path: './test/path.js', + }] + await scheduler.scheduleTests(tests); + const jestRunnerSerial = require('jest-runner-serial'); + + expect(jestRunnerSerial).toHaveBeenCalled(); + mockSerialRunner.runTests.toHaveBeenCalled(); +}); diff --git a/packages/jest-cli/src/test_scheduler.js b/packages/jest-cli/src/test_scheduler.js index 2f7ec55002c0..1324762db1a1 100644 --- a/packages/jest-cli/src/test_scheduler.js +++ b/packages/jest-cli/src/test_scheduler.js @@ -192,7 +192,7 @@ export default class TestScheduler { onResult, onFailure, { - serial: runInBand, + serial: runInBand || testRunners[runner].serial, }, ); }