childprocess

Wrap `child_process` module to support Multiple Process Code Coverage with istanbul.

Usage no npm install needed!

<script type="module">
  import childprocess from 'https://cdn.skypack.dev/childprocess';
</script>

README

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