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

feat: add mutex to in band runner #7

Merged
merged 2 commits into from
Apr 27, 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## master

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

## 0.3.0

### Fixes
Expand All @@ -20,4 +23,4 @@

## 0.1.0

* Initial Release
* Initial Release
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea what's up, I edited in the GitHub UI. probably added a trailing newline

Copy link

@keplersj keplersj Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it does trailing newlines by default.

55 changes: 29 additions & 26 deletions lib/createJestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,39 @@ const createRunner = runPath => {
onFailure,
options,
) {
const mutex = throat(1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return tests.reduce(
(promise, test) =>
promise
.then(() => {
if (watcher.isInterrupted()) {
throw new CancelRun();
}

return onStart(test).then(() => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const runner = require(runPath);
const baseOptions = {
config: test.context.config,
globalConfig: this._globalConfig,
testPath: test.path,
rawModuleMap: watcher.isWatchMode()
? test.context.moduleMap.getRawModuleMap()
: null,
options,
};

if (typeof runner.default === 'function') {
return runner.default(baseOptions);
mutex(() =>
promise
.then(() => {
if (watcher.isInterrupted()) {
throw new CancelRun();
}

return runner(baseOptions);
});
})
.then(result => onResult(test, result))
.catch(err => onFailure(test, err)),
return onStart(test).then(() => {
// eslint-disable-next-line import/no-dynamic-require, global-require
const runner = require(runPath);
const baseOptions = {
config: test.context.config,
globalConfig: this._globalConfig,
testPath: test.path,
rawModuleMap: watcher.isWatchMode()
? test.context.moduleMap.getRawModuleMap()
: null,
options,
};

if (typeof runner.default === 'function') {
return runner.default(baseOptions);
}

return runner(baseOptions);
});
})
.then(result => onResult(test, result))
.catch(err => onFailure(test, err)),
),
Promise.resolve(),
);
}
Expand Down