Skip to content

Commit 62ed157

Browse files
authored
Merge pull request #6 from SimenB/in-band
feat: support serial execution
2 parents 9f71d95 + bd850ea commit 62ed157

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

lib/createJestRunner.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,76 @@ const createRunner = runPath => {
1313
this._globalConfig = globalConfig;
1414
}
1515

16-
// eslint-disable-next-line
1716
runTests(tests, watcher, onStart, onResult, onFailure, options) {
17+
return options.serial
18+
? this._createInBandTestRun(
19+
tests,
20+
watcher,
21+
onStart,
22+
onResult,
23+
onFailure,
24+
options,
25+
)
26+
: this._createParallelTestRun(
27+
tests,
28+
watcher,
29+
onStart,
30+
onResult,
31+
onFailure,
32+
options,
33+
);
34+
}
35+
36+
_createInBandTestRun(
37+
tests,
38+
watcher,
39+
onStart,
40+
onResult,
41+
onFailure,
42+
options,
43+
) {
44+
return tests.reduce(
45+
(promise, test) =>
46+
promise
47+
.then(() => {
48+
if (watcher.isInterrupted()) {
49+
throw new CancelRun();
50+
}
51+
52+
return onStart(test).then(() => {
53+
// eslint-disable-next-line import/no-dynamic-require, global-require
54+
const runner = require(runPath);
55+
const baseOptions = {
56+
config: test.context.config,
57+
globalConfig: this._globalConfig,
58+
testPath: test.path,
59+
rawModuleMap: watcher.isWatchMode()
60+
? test.context.moduleMap.getRawModuleMap()
61+
: null,
62+
options,
63+
};
64+
65+
if (typeof runner.default === 'function') {
66+
return runner.default(baseOptions);
67+
}
68+
69+
return runner(baseOptions);
70+
});
71+
})
72+
.then(result => onResult(test, result))
73+
.catch(err => onFailure(test, err)),
74+
Promise.resolve(),
75+
);
76+
}
77+
78+
_createParallelTestRun(
79+
tests,
80+
watcher,
81+
onStart,
82+
onResult,
83+
onFailure,
84+
options,
85+
) {
1886
const worker = new Worker(runPath, {
1987
exposedMethods: ['default'],
2088
numWorkers: this._globalConfig.maxWorkers,

0 commit comments

Comments
 (0)