Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable single thread mode for runner #5712

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
([#5670](https://github.com/facebook/jest/pull/5670))
* `[expect]` Add inverse matchers (`expect.not.arrayContaining`, etc.,
[#5517](https://github.com/facebook/jest/pull/5517))
* `[jest-cli]` Add `isSerial` property that runners can expose to specify that
they can not run in parallel
[#5706](https://github.com/facebook/jest/pull/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
executed in parallel your class should have the property `isSerial` to be set as
`true`.

### `setupFiles` [array]

Default: `[]`
Expand Down
56 changes: 56 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,20 @@ import TestScheduler from '../test_scheduler';
import SummaryReporter from '../reporters/summary_reporter';

jest.mock('../reporters/default_reporter');
const mockSerialRunner = {
isSerial: true,
runTests: jest.fn(),
};
jest.mock('jest-runner-serial', () => jest.fn(() => mockSerialRunner), {
virtual: true,
});

const mockParallelRunner = {
runTests: jest.fn(),
};
jest.mock('jest-runner-parallel', () => jest.fn(() => mockParallelRunner), {
virtual: true,
});

test('.addReporter() .removeReporter()', () => {
const scheduler = new TestScheduler({}, {});
Expand All @@ -21,3 +35,45 @@ test('.addReporter() .removeReporter()', () => {
scheduler.removeReporter(SummaryReporter);
expect(scheduler._dispatcher._reporters).not.toContain(reporter);
});

test('schedule tests run in parallel per default', async () => {
const scheduler = new TestScheduler({}, {});
const test = {
context: {
config: {
runner: 'jest-runner-parallel',
},
hasteFS: {
matchFiles: jest.fn(() => []),
},
},
path: './test/path.js',
};
const tests = [test, test];

await scheduler.scheduleTests(tests, {isInterrupted: jest.fn()});

expect(mockParallelRunner.runTests).toHaveBeenCalled();
expect(mockParallelRunner.runTests.mock.calls[0][5].serial).toBeFalsy();
});

test('schedule tests run in serial if the runner flags them', async () => {
const scheduler = new TestScheduler({}, {});
const test = {
context: {
config: {
runner: 'jest-runner-serial',
},
hasteFS: {
matchFiles: jest.fn(() => []),
},
},
path: './test/path.js',
};

const tests = [test, test];
await scheduler.scheduleTests(tests, {isInterrupted: jest.fn()});

expect(mockSerialRunner.runTests).toHaveBeenCalled();
expect(mockSerialRunner.runTests.mock.calls[0][5].serial).toBeTruthy();
});
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 || Boolean(testRunners[runner].isSerial),
},
);
}
Expand Down