Skip to content

Commit

Permalink
Enable single thread mode for runner
Browse files Browse the repository at this point in the history
Some runners for tools that can not be run in parallel need a way
to specify that they should not be executed in parallel. This commits
adds this functionality.

Closes jestjs#5706
  • Loading branch information
DanielMSchmidt committed Mar 4, 2018
1 parent f7171b9 commit dfe9545
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@ async runTests(
): Promise<void>
```

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: `[]`
Expand Down
25 changes: 25 additions & 0 deletions packages/jest-cli/src/__tests__/test_scheduler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}, {});
Expand All @@ -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();
});
2 changes: 1 addition & 1 deletion packages/jest-cli/src/test_scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class TestScheduler {
onResult,
onFailure,
{
serial: runInBand,
serial: runInBand || testRunners[runner].serial,
},
);
}
Expand Down

0 comments on commit dfe9545

Please sign in to comment.