jest-worker
Advanced tools
Comparing version 24.0.0-alpha.8 to 24.0.0-alpha.9
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,21 +15,26 @@ | ||
}); | ||
exports.default = void 0; | ||
var _mergeStream; | ||
function _mergeStream() { | ||
const data = _interopRequireDefault(require('merge-stream')); | ||
function _load_mergeStream() { | ||
return (_mergeStream = _interopRequireDefault(require('merge-stream'))); | ||
_mergeStream = function _mergeStream() { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _path; | ||
function _path() { | ||
const data = _interopRequireDefault(require('path')); | ||
function _load_path() { | ||
return (_path = _interopRequireDefault(require('path'))); | ||
_path = function _path() { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _types; | ||
var _types = require('../types'); | ||
function _load_types() { | ||
return (_types = require('../types')); | ||
} | ||
function _interopRequireDefault(obj) { | ||
@@ -48,9 +52,8 @@ return obj && obj.__esModule ? obj : {default: obj}; | ||
if (!(_path || _load_path()).default.isAbsolute(workerPath)) { | ||
if (!_path().default.isAbsolute(workerPath)) { | ||
workerPath = require.resolve(workerPath); | ||
} | ||
const stdout = (0, (_mergeStream || _load_mergeStream()).default)(); | ||
const stderr = (0, (_mergeStream || _load_mergeStream()).default)(); | ||
const stdout = (0, _mergeStream().default)(); | ||
const stderr = (0, _mergeStream().default)(); | ||
const forkOptions = options.forkOptions, | ||
@@ -62,9 +65,8 @@ maxRetries = options.maxRetries, | ||
const workerOptions = { | ||
forkOptions: forkOptions, | ||
maxRetries: maxRetries, | ||
setupArgs: setupArgs, | ||
forkOptions, | ||
maxRetries, | ||
setupArgs, | ||
workerId: i, | ||
workerPath: workerPath | ||
workerPath | ||
}; | ||
const worker = this.createWorker(workerOptions); | ||
@@ -114,3 +116,3 @@ const workerStdout = worker.getStdout(); | ||
this._workers[i].send( | ||
[(_types || _load_types()).CHILD_MESSAGE_END, false], | ||
[_types.CHILD_MESSAGE_END, false], | ||
emptyMethod, | ||
@@ -122,2 +124,3 @@ emptyMethod | ||
} | ||
exports.default = BaseWorkerPool; |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,9 +15,6 @@ | ||
}); | ||
exports.default = void 0; | ||
var _types; | ||
var _types = require('./types'); | ||
function _load_types() { | ||
return (_types = require('./types')); | ||
} | ||
class Farm { | ||
@@ -33,2 +29,3 @@ constructor(numOfWorkers, callback, computeWorkerKey) { | ||
this._offset = 0; | ||
if (computeWorkerKey) { | ||
@@ -39,22 +36,6 @@ this._computeWorkerKey = computeWorkerKey; | ||
doWork(method) { | ||
for ( | ||
var _len = arguments.length, | ||
args = Array(_len > 1 ? _len - 1 : 0), | ||
_key = 1; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
doWork(method, ...args) { | ||
return new Promise((resolve, reject) => { | ||
const computeWorkerKey = this._computeWorkerKey; | ||
const request = [ | ||
(_types || _load_types()).CHILD_MESSAGE_CALL, | ||
false, | ||
method, | ||
args | ||
]; | ||
const request = [_types.CHILD_MESSAGE_CALL, false, method, args]; | ||
let worker = null; | ||
@@ -82,3 +63,8 @@ let hash = null; | ||
const task = {onEnd: onEnd, onStart: onStart, request: request}; | ||
const task = { | ||
onEnd, | ||
onStart, | ||
request | ||
}; | ||
if (worker) { | ||
@@ -100,3 +86,2 @@ this._enqueue(task, worker.getWorkerId()); | ||
this._queue[workerId] = queueHead; | ||
return queueHead; | ||
@@ -119,2 +104,3 @@ } | ||
this.unlock(workerId); | ||
this._process(workerId); | ||
@@ -128,3 +114,2 @@ }; | ||
job.request[1] = true; | ||
return this; | ||
@@ -145,2 +130,3 @@ } | ||
this._last[workerId] = task; | ||
this._process(workerId); | ||
@@ -154,6 +140,7 @@ | ||
const workerIdx = (this._offset + i) % this._numOfWorkers; | ||
this._enqueue(task, workerIdx); | ||
} | ||
this._offset++; | ||
return this; | ||
@@ -174,2 +161,3 @@ } | ||
} | ||
exports.default = Farm; |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,20 +15,17 @@ | ||
}); | ||
exports.default = void 0; | ||
var _os; | ||
function _os() { | ||
const data = _interopRequireDefault(require('os')); | ||
function _load_os() { | ||
return (_os = _interopRequireDefault(require('os'))); | ||
} | ||
_os = function _os() { | ||
return data; | ||
}; | ||
var _WorkerPool; | ||
function _load_WorkerPool() { | ||
return (_WorkerPool = _interopRequireDefault(require('./WorkerPool'))); | ||
return data; | ||
} | ||
var _Farm; | ||
var _WorkerPool = _interopRequireDefault(require('./WorkerPool')); | ||
function _load_Farm() { | ||
return (_Farm = _interopRequireDefault(require('./Farm'))); | ||
} | ||
var _Farm = _interopRequireDefault(require('./Farm')); | ||
@@ -41,5 +37,4 @@ function _interopRequireDefault(obj) { | ||
function getExposedMethods(workerPath, options) { | ||
let exposedMethods = options.exposedMethods; | ||
let exposedMethods = options.exposedMethods; // If no methods list is given, try getting it by auto-requiring the module. | ||
// If no methods list is given, try getting it by auto-requiring the module. | ||
if (!exposedMethods) { | ||
@@ -60,3 +55,2 @@ // $FlowFixMe: This has to be a dynamic require. | ||
} | ||
/** | ||
@@ -87,6 +81,6 @@ * The Jest farm (publicly called "Worker") is a class that allows you to queue | ||
*/ | ||
class JestWorker { | ||
constructor(workerPath, options) { | ||
this._options = Object.assign({}, options); | ||
const workerPoolOptions = { | ||
@@ -97,14 +91,9 @@ forkOptions: this._options.forkOptions || {}, | ||
this._options.numWorkers || | ||
Math.max((_os || _load_os()).default.cpus().length - 1, 1), | ||
Math.max(_os().default.cpus().length - 1, 1), | ||
setupArgs: this._options.setupArgs || [] | ||
}; | ||
this._workerPool = this._options.WorkerPool | ||
? new this._options.WorkerPool(workerPath, workerPoolOptions) | ||
: new (_WorkerPool || _load_WorkerPool()).default( | ||
workerPath, | ||
workerPoolOptions | ||
); | ||
this._farm = new (_Farm || _load_Farm()).default( | ||
: new _WorkerPool.default(workerPath, workerPoolOptions); | ||
this._farm = new _Farm.default( | ||
workerPoolOptions.numWorkers, | ||
@@ -126,13 +115,9 @@ this._workerPool.send.bind(this._workerPool), | ||
throw new TypeError('Cannot define a method called ' + name); | ||
} | ||
} // $FlowFixMe: dynamic extension of the class instance is expected. | ||
// $FlowFixMe: dynamic extension of the class instance is expected. | ||
this[name] = this._callFunctionWithArgs.bind(this, name); | ||
}); | ||
} | ||
} // eslint-disable-next-line no-unclear-flowtypes | ||
// eslint-disable-next-line no-unclear-flowtypes | ||
_callFunctionWithArgs(method) { | ||
var _farm; | ||
_callFunctionWithArgs(method, ...args) { | ||
if (this._ending) { | ||
@@ -142,13 +127,3 @@ throw new Error('Farm is ended, no more calls can be done to it'); | ||
for ( | ||
var _len = arguments.length, | ||
args = Array(_len > 1 ? _len - 1 : 0), | ||
_key = 1; | ||
_key < _len; | ||
_key++ | ||
) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return (_farm = this._farm).doWork.apply(_farm, [method].concat(args)); | ||
return this._farm.doWork(method, ...args); | ||
} | ||
@@ -174,2 +149,3 @@ | ||
} | ||
exports.default = JestWorker; |
@@ -9,6 +9,3 @@ /** | ||
*/ | ||
'use strict'; | ||
// Because of the dynamic nature of a worker communication process, all messages | ||
'use strict'; // Because of the dynamic nature of a worker communication process, all messages | ||
// coming from any of the other processes cannot be typed. Thus, many types | ||
@@ -22,18 +19,16 @@ // include "any" as a flow type, which is (unfortunately) correct here. | ||
}); | ||
const CHILD_MESSAGE_INITIALIZE = (exports.CHILD_MESSAGE_INITIALIZE = 0); | ||
const CHILD_MESSAGE_CALL = (exports.CHILD_MESSAGE_CALL = 1); | ||
const CHILD_MESSAGE_END = (exports.CHILD_MESSAGE_END = 2); | ||
exports.PARENT_MESSAGE_SETUP_ERROR = exports.PARENT_MESSAGE_CLIENT_ERROR = exports.PARENT_MESSAGE_OK = exports.CHILD_MESSAGE_END = exports.CHILD_MESSAGE_CALL = exports.CHILD_MESSAGE_INITIALIZE = void 0; | ||
const CHILD_MESSAGE_INITIALIZE = 0; | ||
exports.CHILD_MESSAGE_INITIALIZE = CHILD_MESSAGE_INITIALIZE; | ||
const CHILD_MESSAGE_CALL = 1; | ||
exports.CHILD_MESSAGE_CALL = CHILD_MESSAGE_CALL; | ||
const CHILD_MESSAGE_END = 2; | ||
exports.CHILD_MESSAGE_END = CHILD_MESSAGE_END; | ||
const PARENT_MESSAGE_OK = 0; | ||
exports.PARENT_MESSAGE_OK = PARENT_MESSAGE_OK; | ||
const PARENT_MESSAGE_CLIENT_ERROR = 1; | ||
exports.PARENT_MESSAGE_CLIENT_ERROR = PARENT_MESSAGE_CLIENT_ERROR; | ||
const PARENT_MESSAGE_SETUP_ERROR = 2; | ||
exports.PARENT_MESSAGE_SETUP_ERROR = PARENT_MESSAGE_SETUP_ERROR; | ||
const PARENT_MESSAGE_OK = (exports.PARENT_MESSAGE_OK = 0); | ||
const PARENT_MESSAGE_CLIENT_ERROR = (exports.PARENT_MESSAGE_CLIENT_ERROR = 1); | ||
const PARENT_MESSAGE_SETUP_ERROR = (exports.PARENT_MESSAGE_SETUP_ERROR = 2); | ||
// Option objects. | ||
const EventEmitter = require('events'); | ||
// Messages passed from the parent to the children. | ||
// Messages passed from the children to the parent. | ||
// Queue types. |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,11 +15,6 @@ | ||
}); | ||
exports.default = void 0; | ||
var _BaseWorkerPool; | ||
var _BaseWorkerPool = _interopRequireDefault(require('./base/BaseWorkerPool')); | ||
function _load_BaseWorkerPool() { | ||
return (_BaseWorkerPool = _interopRequireDefault( | ||
require('./base/BaseWorkerPool') | ||
)); | ||
} | ||
function _interopRequireDefault(obj) { | ||
@@ -34,2 +28,3 @@ return obj && obj.__esModule ? obj : {default: obj}; | ||
require('worker_threads'); | ||
return true; | ||
@@ -41,3 +36,3 @@ } catch (_) { | ||
class WorkerPool extends (_BaseWorkerPool || _load_BaseWorkerPool()).default { | ||
class WorkerPool extends _BaseWorkerPool.default { | ||
send(workerId, request, onStart, onEnd) { | ||
@@ -49,2 +44,3 @@ this.getWorkerById(workerId).send(request, onStart, onEnd); | ||
let Worker; | ||
if (canUseWorkerThreads()) { | ||
@@ -60,2 +56,3 @@ Worker = require('./workers/NodeThreadsWorker').default; | ||
exports.default = WorkerPool; | ||
var _default = WorkerPool; | ||
exports.default = _default; |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,13 +15,24 @@ | ||
}); | ||
exports.default = void 0; | ||
var _child_process; | ||
function _child_process() { | ||
const data = _interopRequireDefault(require('child_process')); | ||
function _load_child_process() { | ||
return (_child_process = _interopRequireDefault(require('child_process'))); | ||
_child_process = function _child_process() { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _types; | ||
var _types = require('../types'); | ||
function _load_types() { | ||
return (_types = require('../types')); | ||
function _supportsColor() { | ||
const data = _interopRequireDefault(require('supports-color')); | ||
_supportsColor = function _supportsColor() { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
@@ -59,11 +69,21 @@ | ||
initialize() { | ||
const child = (_child_process || _load_child_process()).default.fork( | ||
require.resolve('./processChild'), | ||
// $FlowFixMe: Flow does not work well with Object.assign. | ||
const forceColor = _supportsColor().default.stdout | ||
? { | ||
FORCE_COLOR: '1' | ||
} | ||
: {}; | ||
const child = _child_process().default.fork( | ||
require.resolve('./processChild'), // $FlowFixMe: Flow does not work well with Object.assign. | ||
Object.assign( | ||
{ | ||
cwd: process.cwd(), | ||
env: Object.assign({}, process.env, { | ||
JEST_WORKER_ID: this._options.workerId | ||
}), | ||
env: Object.assign( | ||
{}, | ||
process.env, | ||
{ | ||
JEST_WORKER_ID: this._options.workerId | ||
}, | ||
forceColor | ||
), | ||
// Suppress --debug / --inspect flags while preserving others (like --harmony). | ||
@@ -78,7 +98,6 @@ execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), | ||
child.on('message', this.onMessage.bind(this)); | ||
child.on('exit', this.onExit.bind(this)); | ||
child.on('exit', this.onExit.bind(this)); // $FlowFixMe: wrong "ChildProcess.send" signature. | ||
// $FlowFixMe: wrong "ChildProcess.send" signature. | ||
child.send([ | ||
(_types || _load_types()).CHILD_MESSAGE_INITIALIZE, | ||
_types.CHILD_MESSAGE_INITIALIZE, | ||
false, | ||
@@ -88,18 +107,17 @@ this._options.workerPath, | ||
]); | ||
this._child = child; | ||
this._retries++; | ||
// If we exceeded the amount of retries, we will emulate an error reply | ||
this._retries++; // If we exceeded the amount of retries, we will emulate an error reply | ||
// coming from the child. This avoids code duplication related with cleaning | ||
// the queue, and scheduling the next call. | ||
if (this._retries > this._options.maxRetries) { | ||
const error = new Error('Call retries were exceeded'); | ||
this.onMessage([ | ||
(_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR, | ||
_types.PARENT_MESSAGE_CLIENT_ERROR, | ||
error.name, | ||
error.message, | ||
error.stack, | ||
{type: 'WorkerError'} | ||
{ | ||
type: 'WorkerError' | ||
} | ||
]); | ||
@@ -109,11 +127,15 @@ } | ||
onMessage(response /* Should be ParentMessage */) { | ||
onMessage( | ||
response | ||
/* Should be ParentMessage */ | ||
) { | ||
let error; | ||
switch (response[0]) { | ||
case (_types || _load_types()).PARENT_MESSAGE_OK: | ||
case _types.PARENT_MESSAGE_OK: | ||
this._onProcessEnd(null, response[1]); | ||
break; | ||
case (_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR: | ||
case _types.PARENT_MESSAGE_CLIENT_ERROR: | ||
error = response[4]; | ||
@@ -125,5 +147,4 @@ | ||
const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error; | ||
error = new Ctor(response[2]); // $FlowFixMe: adding custom properties to errors. | ||
error = new Ctor(response[2]); | ||
// $FlowFixMe: adding custom properties to errors. | ||
error.type = response[1]; | ||
@@ -139,8 +160,8 @@ error.stack = response[3]; | ||
this._onProcessEnd(error, null); | ||
break; | ||
case (_types || _load_types()).PARENT_MESSAGE_SETUP_ERROR: | ||
error = new Error('Error when calling setup: ' + response[2]); | ||
case _types.PARENT_MESSAGE_SETUP_ERROR: | ||
error = new Error('Error when calling setup: ' + response[2]); // $FlowFixMe: adding custom properties to errors. | ||
// $FlowFixMe: adding custom properties to errors. | ||
error.type = response[1]; | ||
@@ -150,2 +171,3 @@ error.stack = response[3]; | ||
this._onProcessEnd(error, null); | ||
break; | ||
@@ -167,5 +189,4 @@ | ||
this._onProcessEnd = onProcessEnd; | ||
this._retries = 0; // $FlowFixMe | ||
this._retries = 0; | ||
// $FlowFixMe | ||
this._child.send(request); | ||
@@ -186,2 +207,3 @@ } | ||
} | ||
exports.default = ChildProcessWorker; |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -16,13 +15,14 @@ | ||
}); | ||
exports.default = void 0; | ||
var _types; | ||
var _types = require('../types'); | ||
function _load_types() { | ||
return (_types = require('../types')); | ||
} | ||
function _path() { | ||
const data = _interopRequireDefault(require('path')); | ||
var _path; | ||
_path = function _path() { | ||
return data; | ||
}; | ||
function _load_path() { | ||
return (_path = _interopRequireDefault(require('path'))); | ||
return data; | ||
} | ||
@@ -35,5 +35,5 @@ | ||
// $FlowFixMe: Flow doesn't know about experimental features of Node | ||
var _require = require('worker_threads'); | ||
const _require = require('worker_threads'), | ||
Worker = _require.Worker; | ||
const Worker = _require.Worker; | ||
class ExperimentalWorker { | ||
@@ -47,3 +47,3 @@ constructor(options) { | ||
this._worker = new Worker( | ||
(_path || _load_path()).default.resolve(__dirname, './threadChild.js'), | ||
_path().default.resolve(__dirname, './threadChild.js'), | ||
{ | ||
@@ -72,6 +72,7 @@ eval: false, | ||
this._worker.on('message', this.onMessage.bind(this)); | ||
this._worker.on('exit', this.onExit.bind(this)); | ||
this._worker.postMessage([ | ||
(_types || _load_types()).CHILD_MESSAGE_INITIALIZE, | ||
_types.CHILD_MESSAGE_INITIALIZE, | ||
false, | ||
@@ -82,16 +83,16 @@ this._options.workerPath, | ||
this._retries++; | ||
// If we exceeded the amount of retries, we will emulate an error reply | ||
this._retries++; // If we exceeded the amount of retries, we will emulate an error reply | ||
// coming from the child. This avoids code duplication related with cleaning | ||
// the queue, and scheduling the next call. | ||
if (this._retries > this._options.maxRetries) { | ||
const error = new Error('Call retries were exceeded'); | ||
this.onMessage([ | ||
(_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR, | ||
_types.PARENT_MESSAGE_CLIENT_ERROR, | ||
error.name, | ||
error.message, | ||
error.stack, | ||
{type: 'WorkerError'} | ||
{ | ||
type: 'WorkerError' | ||
} | ||
]); | ||
@@ -101,11 +102,15 @@ } | ||
onMessage(response /* Should be ParentMessage */) { | ||
onMessage( | ||
response | ||
/* Should be ParentMessage */ | ||
) { | ||
let error; | ||
switch (response[0]) { | ||
case (_types || _load_types()).PARENT_MESSAGE_OK: | ||
case _types.PARENT_MESSAGE_OK: | ||
this._onProcessEnd(null, response[1]); | ||
break; | ||
case (_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR: | ||
case _types.PARENT_MESSAGE_CLIENT_ERROR: | ||
error = response[4]; | ||
@@ -117,5 +122,4 @@ | ||
const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error; | ||
error = new Ctor(response[2]); // $FlowFixMe: adding custom properties to errors. | ||
error = new Ctor(response[2]); | ||
// $FlowFixMe: adding custom properties to errors. | ||
error.type = response[1]; | ||
@@ -131,7 +135,8 @@ error.stack = response[3]; | ||
this._onProcessEnd(error, null); | ||
break; | ||
case (_types || _load_types()).PARENT_MESSAGE_SETUP_ERROR: | ||
error = new Error('Error when calling setup: ' + response[2]); | ||
// $FlowFixMe: adding custom properties to errors. | ||
case _types.PARENT_MESSAGE_SETUP_ERROR: | ||
error = new Error('Error when calling setup: ' + response[2]); // $FlowFixMe: adding custom properties to errors. | ||
error.type = response[1]; | ||
@@ -141,3 +146,5 @@ error.stack = response[3]; | ||
this._onProcessEnd(error, null); | ||
break; | ||
default: | ||
@@ -157,3 +164,2 @@ throw new TypeError('Unexpected response from worker: ' + response[0]); | ||
this._onProcessEnd = onProcessEnd; | ||
this._retries = 0; | ||
@@ -176,2 +182,3 @@ | ||
} | ||
exports.default = ExperimentalWorker; |
@@ -9,15 +9,9 @@ /** | ||
*/ | ||
'use strict'; | ||
var _types; | ||
var _types = require('../types'); | ||
function _load_types() { | ||
return (_types = require('../types')); | ||
} | ||
let file = null; | ||
let setupArgs = []; | ||
let initialized = false; | ||
/** | ||
@@ -36,5 +30,6 @@ * This file is a small bootstrapper for workers. It sets up the communication | ||
*/ | ||
process.on('message', request => { | ||
switch (request[0]) { | ||
case (_types || _load_types()).CHILD_MESSAGE_INITIALIZE: | ||
case _types.CHILD_MESSAGE_INITIALIZE: | ||
const init = request; | ||
@@ -45,3 +40,3 @@ file = init[2]; | ||
case (_types || _load_types()).CHILD_MESSAGE_CALL: | ||
case _types.CHILD_MESSAGE_CALL: | ||
const call = request; | ||
@@ -51,3 +46,3 @@ execMethod(call[2], call[3]); | ||
case (_types || _load_types()).CHILD_MESSAGE_END: | ||
case _types.CHILD_MESSAGE_END: | ||
end(); | ||
@@ -68,17 +63,11 @@ break; | ||
process.send([(_types || _load_types()).PARENT_MESSAGE_OK, result]); | ||
process.send([_types.PARENT_MESSAGE_OK, result]); | ||
} | ||
function reportClientError(error) { | ||
return reportError( | ||
error, | ||
(_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR | ||
); | ||
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR); | ||
} | ||
function reportInitializeError(error) { | ||
return reportError( | ||
error, | ||
(_types || _load_types()).PARENT_MESSAGE_SETUP_ERROR | ||
); | ||
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR); | ||
} | ||
@@ -99,4 +88,3 @@ | ||
error.message, | ||
error.stack, | ||
// $FlowFixMe: this is safe to just inherit from Object. | ||
error.stack, // $FlowFixMe: this is safe to just inherit from Object. | ||
typeof error === 'object' ? Object.assign({}, error) : error | ||
@@ -112,3 +100,2 @@ ]); | ||
exitProcess(); | ||
return; | ||
@@ -142,3 +129,2 @@ } | ||
execHelper(); | ||
return; | ||
@@ -148,3 +134,2 @@ } | ||
initialized = true; | ||
execFunction(main.setup, main, setupArgs, execHelper, reportInitializeError); | ||
@@ -160,3 +145,2 @@ } | ||
onError(err); | ||
return; | ||
@@ -163,0 +147,0 @@ } |
@@ -9,15 +9,14 @@ /** | ||
*/ | ||
'use strict'; | ||
var _types; | ||
var _types = require('../types'); | ||
function _load_types() { | ||
return (_types = require('../types')); | ||
} | ||
function _worker_threads() { | ||
const data = require('worker_threads'); | ||
var _worker_threads; | ||
_worker_threads = function _worker_threads() { | ||
return data; | ||
}; | ||
function _load_worker_threads() { | ||
return (_worker_threads = require('worker_threads')); | ||
return data; | ||
} | ||
@@ -28,3 +27,2 @@ | ||
let initialized = false; | ||
/* eslint-disable import/no-unresolved */ | ||
@@ -48,56 +46,44 @@ // $FlowFixMe: Flow doesn't support experimental node modules | ||
*/ | ||
(_worker_threads || _load_worker_threads()).parentPort.on( | ||
'message', | ||
request => { | ||
switch (request[0]) { | ||
case (_types || _load_types()).CHILD_MESSAGE_INITIALIZE: | ||
const init = request; | ||
file = init[2]; | ||
setupArgs = request[3]; | ||
break; | ||
_worker_threads().parentPort.on('message', request => { | ||
switch (request[0]) { | ||
case _types.CHILD_MESSAGE_INITIALIZE: | ||
const init = request; | ||
file = init[2]; | ||
setupArgs = request[3]; | ||
break; | ||
case (_types || _load_types()).CHILD_MESSAGE_CALL: | ||
const call = request; | ||
execMethod(call[2], call[3]); | ||
break; | ||
case _types.CHILD_MESSAGE_CALL: | ||
const call = request; | ||
execMethod(call[2], call[3]); | ||
break; | ||
case (_types || _load_types()).CHILD_MESSAGE_END: | ||
end(); | ||
break; | ||
case _types.CHILD_MESSAGE_END: | ||
end(); | ||
break; | ||
default: | ||
throw new TypeError( | ||
'Unexpected request from parent process: ' + request[0] | ||
); | ||
} | ||
default: | ||
throw new TypeError( | ||
'Unexpected request from parent process: ' + request[0] | ||
); | ||
} | ||
); | ||
}); | ||
function reportSuccess(result) { | ||
if ((_worker_threads || _load_worker_threads()).isMainThread) { | ||
if (_worker_threads().isMainThread) { | ||
throw new Error('Child can only be used on a forked process'); | ||
} | ||
(_worker_threads || _load_worker_threads()).parentPort.postMessage([ | ||
(_types || _load_types()).PARENT_MESSAGE_OK, | ||
result | ||
]); | ||
_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_OK, result]); | ||
} | ||
function reportClientError(error) { | ||
return reportError( | ||
error, | ||
(_types || _load_types()).PARENT_MESSAGE_CLIENT_ERROR | ||
); | ||
return reportError(error, _types.PARENT_MESSAGE_CLIENT_ERROR); | ||
} | ||
function reportInitializeError(error) { | ||
return reportError( | ||
error, | ||
(_types || _load_types()).PARENT_MESSAGE_SETUP_ERROR | ||
); | ||
return reportError(error, _types.PARENT_MESSAGE_SETUP_ERROR); | ||
} | ||
function reportError(error, type) { | ||
if ((_worker_threads || _load_worker_threads()).isMainThread) { | ||
if (_worker_threads().isMainThread) { | ||
throw new Error('Child can only be used on a forked process'); | ||
@@ -110,8 +96,7 @@ } | ||
(_worker_threads || _load_worker_threads()).parentPort.postMessage([ | ||
_worker_threads().parentPort.postMessage([ | ||
type, | ||
error.constructor && error.constructor.name, | ||
error.message, | ||
error.stack, | ||
// $FlowFixMe: this is safe to just inherit from Object. | ||
error.stack, // $FlowFixMe: this is safe to just inherit from Object. | ||
typeof error === 'object' ? Object.assign({}, error) : error | ||
@@ -127,3 +112,2 @@ ]); | ||
exitProcess(); | ||
return; | ||
@@ -157,3 +141,2 @@ } | ||
execHelper(); | ||
return; | ||
@@ -163,3 +146,2 @@ } | ||
initialized = true; | ||
execFunction(main.setup, main, setupArgs, execHelper, reportInitializeError); | ||
@@ -175,3 +157,2 @@ } | ||
onError(err); | ||
return; | ||
@@ -178,0 +159,0 @@ } |
{ | ||
"name": "jest-worker", | ||
"version": "24.0.0-alpha.8", | ||
"version": "24.0.0-alpha.9", | ||
"repository": { | ||
@@ -11,3 +11,4 @@ "type": "git", | ||
"dependencies": { | ||
"merge-stream": "^1.0.1" | ||
"merge-stream": "^1.0.1", | ||
"supports-color": "^5.5.0" | ||
}, | ||
@@ -17,3 +18,3 @@ "engines": { | ||
}, | ||
"gitHead": "700e0dadb85f5dc8ff5dac6c7e98956690049734" | ||
"gitHead": "c7caa7ba5904d0c61e586694cde5f536639e4afc" | ||
} |
@@ -194,3 +194,3 @@ # jest-worker | ||
```javascript | ||
import babel from 'babel-core'; | ||
import babel from '@babel/core'; | ||
@@ -206,12 +206,8 @@ const cache = Object.create(null); | ||
// thenable is returned, it will be await'ed until it resolves. | ||
return new Promise((resolve, reject) => { | ||
babel.transformFile(filename, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve((cache[filename] = result)); | ||
} | ||
}); | ||
return babel.transformFileAsync(filename).then(result => { | ||
cache[filename] = result; | ||
return result; | ||
}); | ||
} | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
38629
2
12
947
212
+ Addedsupports-color@^5.5.0
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)