Skip to content

Commit

Permalink
Bring back support for multi process run
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed May 23, 2019
1 parent 1f70100 commit 5e14363
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 17 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -4,6 +4,7 @@ module.exports = {
"plugins": [],
"rules": {
"func-names": "off",
"global-require": "off", // Interferes with optional and eventual circular references

// doesn't work in node v4 :(
"strict": "off",
Expand Down
56 changes: 40 additions & 16 deletions bin/test-isolated
Expand Up @@ -39,31 +39,55 @@ globby(patterns).then(paths => {
process.exit(1);
}

const processesCount = 1;
const isMultiProcessRun = processesCount > 1;

const { ongoing, cliFooter } = (() => {
if (!isMultiProcessRun) return {};
return { ongoing: new Set(), cliFooter: require('cli-progress-footer')() };
})();

const run = path => {
const onFinally = () =>
Promise.all([initialGitStatusDeferred, resolveGitStatus()]).then(
([initialStatus, currentStatus]) => {
if (initialStatus !== currentStatus) {
process.stderr.write(
chalk.red.bold(`${path} didn't clean created temporary files\n\n`)
);
process.exit(1);
if (isMultiProcessRun) {
ongoing.add(path);
cliFooter.updateProgress(Array.from(ongoing));
}

const onFinally = (() => {
if (isMultiProcessRun) {
return ({ stdoutBuffer, stderrBuffer }) => {
ongoing.delete(path);
cliFooter.updateProgress(Array.from(ongoing));
process.stdout.write(stdoutBuffer);
process.stderr.write(stderrBuffer);
};
}
return () =>
Promise.all([initialGitStatusDeferred, resolveGitStatus()]).then(
([initialStatus, currentStatus]) => {
if (initialStatus !== currentStatus) {
process.stderr.write(
chalk.red.bold(`${path} didn't clean created temporary files\n\n`)
);
process.exit(1);
}
}
}
);
);
})();

return spawn('./bin/test', [path], {
stdio: 'inherit',
stdio: isMultiProcessRun ? null : 'inherit',
env: { FORCE_COLOR: '1', PATH: process.env.PATH },
}).then(onFinally, error =>
onFinally(error).then(() => {
}).then(onFinally, error => {
if (isMultiProcessRun) ongoing.clear();
return onFinally(error).then(() => {
process.stderr.write(chalk.red.bold(`${path} failed\n\n`));
if (error.code === 2) process.exit(2);
throw error;
})
);
});
});
};

const limit = pLimit(1);
const limit = pLimit(processesCount);
return initialSetupDeferred.then(() => Promise.all(paths.map(path => limit(() => run(path)))));
});
81 changes: 80 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -72,6 +72,7 @@
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"child-process-ext": "^2.0.0",
"cli-progress-footer": "^1.1.1",
"coveralls": "^3.0.3",
"eslint": "^3.3.1",
"eslint-config-airbnb": "^10.0.1",
Expand Down

0 comments on commit 5e14363

Please sign in to comment.