Skip to content

Commit 5b22819

Browse files
authored
feat: add mutex to in band runner (#7)
* feat: add mutex to in band runner * Update CHANGELOG.md
1 parent a0fa00c commit 5b22819

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## master
22

3+
### Fixes
4+
* Use a mutex when running in band as well ([#7](https://github.com/rogeliog/create-jest-runner/pull/7))
5+
36
## 0.3.0
47

58
### Fixes
@@ -20,4 +23,4 @@
2023

2124
## 0.1.0
2225

23-
* Initial Release
26+
* Initial Release

lib/createJestRunner.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,39 @@ const createRunner = runPath => {
4242
onFailure,
4343
options,
4444
) {
45+
const mutex = throat(1);
4546
return tests.reduce(
4647
(promise, test) =>
47-
promise
48-
.then(() => {
49-
if (watcher.isInterrupted()) {
50-
throw new CancelRun();
51-
}
52-
53-
return onStart(test).then(() => {
54-
// eslint-disable-next-line import/no-dynamic-require, global-require
55-
const runner = require(runPath);
56-
const baseOptions = {
57-
config: test.context.config,
58-
globalConfig: this._globalConfig,
59-
testPath: test.path,
60-
rawModuleMap: watcher.isWatchMode()
61-
? test.context.moduleMap.getRawModuleMap()
62-
: null,
63-
options,
64-
};
65-
66-
if (typeof runner.default === 'function') {
67-
return runner.default(baseOptions);
48+
mutex(() =>
49+
promise
50+
.then(() => {
51+
if (watcher.isInterrupted()) {
52+
throw new CancelRun();
6853
}
6954

70-
return runner(baseOptions);
71-
});
72-
})
73-
.then(result => onResult(test, result))
74-
.catch(err => onFailure(test, err)),
55+
return onStart(test).then(() => {
56+
// eslint-disable-next-line import/no-dynamic-require, global-require
57+
const runner = require(runPath);
58+
const baseOptions = {
59+
config: test.context.config,
60+
globalConfig: this._globalConfig,
61+
testPath: test.path,
62+
rawModuleMap: watcher.isWatchMode()
63+
? test.context.moduleMap.getRawModuleMap()
64+
: null,
65+
options,
66+
};
67+
68+
if (typeof runner.default === 'function') {
69+
return runner.default(baseOptions);
70+
}
71+
72+
return runner(baseOptions);
73+
});
74+
})
75+
.then(result => onResult(test, result))
76+
.catch(err => onFailure(test, err)),
77+
),
7578
Promise.resolve(),
7679
);
7780
}

0 commit comments

Comments
 (0)