Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

alibaba-archive/childprocess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published