childprocess

2.0.2 • Public • Published

childprocess

NPM version build status appveyor build status Test coverage David deps npm download

Inject script into multiple process when using child_process.fork.

One of the use case is Multiple Process Code Coverage with istanbul.

Install

$ npm i childprocess

Usage

require('childprocess').inject(function(modulePath, args, opt) {
  const execFile = 'path/to/istanbul';
  const cwd = opt.cwd && process.cwd();
  const execArgs = [
    'cover',
    '--root', cwd,
    '--dir', path.join(cwd, './coverage'),
    '--report', 'none',
    '--print', 'none',
    '--include-pid',
    modulePath,
    '--',
  ].concat(args);
  return [execFile, execArgs, opt];
});
require('child_process').fork();

APIs

inject(cb) / inject(filepath)

Inject script when using child_process.fork.

The inject script is a function that running in sandbox in every process. that mean you can't use the variable out of the function.

The function should return an array that contains 3 arguments same as fork.

childprocess.inject(function(modulePath, args, opt) {
  return [modulePath, args, opt];
});

reset()

Use child_process.fork without injected script.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.2
    2,926
    • latest

Version History

Package Sidebar

Install

npm i childprocess

Weekly Downloads

2,930

Version

2.0.2

License

MIT

Last publish

Collaborators

  • fengmk2
  • popomore