Détail du package

childprocess

node-modules11.6kMIT2.0.2

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

childprocess, child_process, multiple_process, istanbul

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

changelog

2.0.2 / 2016-06-20

  • fix: should let the original file as mainModule rather than the mock file (#6)

2.0.1 / 2016-02-25

  • fix: ensure tmp file unique
  • fix: support fork tmpfile on windows

2.0.0 / 2015-10-31

  • test: coverage 100%
  • doc: update document
  • feat: inject script into multiple process

1.0.3 / 2015-10-29

  • fix: support options.cwd on fork()

1.0.2 / 2015-09-01

  • fix: support 0.12

1.0.1 / 2015-09-01

  • feat: add spawn and options.autoCoverage

1.0.0 / 2015-08-30

  • first release