Skip to content

remove config from workerData #1887

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

Merged
merged 1 commit into from
Sep 23, 2019
Merged
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
35 changes: 12 additions & 23 deletions lib/command/run-workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ module.exports = function (workers, options) {

// run bootstrap all
runHook(config.bootstrapAll, () => {
const workerList = createWorkers(groups, config, options, testRoot);
const workerList = createWorkers(groups, options, testRoot);
workerList.forEach(worker => assignWorkerMethods(worker, groups.length));
}, 'bootstrapAll');

function createWorkers(groups, config, options, testRoot) {
delete config.mocha;
function createWorkers(groups, options, testRoot) {
const workers = groups.map((tests, workerIndex) => {
workerIndex++;
return new Worker(pathToWorker, {
workerData: {
config: simplifyObject(config, { objects: false, underscores: false }),
options: simplifyObject(options),
tests,
testRoot,
Expand Down Expand Up @@ -159,7 +157,7 @@ function appendStats(newStats) {
}

function repackTest(test) {
test = Object.assign(new Test(test.title || '', () => {}), test);
test = Object.assign(new Test(test.title || '', () => { }), test);
test.parent = Object.assign(new Suite(test.parent.title), test.parent);
return test;
}
Expand All @@ -169,22 +167,13 @@ function repackSuite(suite) {
}


function simplifyObject(object, remove = {}) {
const defaultRemove = {
objects: true,
functions: true,
underscores: true,
};

remove = Object.assign(defaultRemove, remove);

let tempObj = Object.keys(object);
if (remove.underscores) tempObj = tempObj.filter(k => k.indexOf('_') !== 0);
if (remove.functions) tempObj = tempObj.filter(k => typeof object[k] !== 'function');
if (remove.objects) tempObj = tempObj.filter(k => typeof object[k] !== 'object');

return tempObj.reduce((obj, key) => {
obj[key] = object[key];
return obj;
}, {});
function simplifyObject(object) {
return Object.keys(object)
.filter(k => k.indexOf('_') !== 0)
.filter(k => typeof object[k] !== 'function')
.filter(k => typeof object[k] !== 'object')
.reduce((obj, key) => {
obj[key] = object[key];
return obj;
}, {});
}