UNPKG

857 BJavaScriptView Raw
1'use strict';
2
3var path = require('path');
4var spawn = require('child_process').spawn;
5var finished = require('tap-finished');
6
7var DUMP_NODE_PATH = path.join(__dirname, './ipc-helpers/dump-node.js');
8
9function runNode(entry, cb) {
10 var coverage = {};
11 var exitCode = 0;
12 var child = spawn('node', [], {stdio: [null, null, null, 'ipc']});
13 child.on('message', function(message) {
14 coverage = message.coverage;
15 });
16 child.stdout.pipe(finished(function (results) {
17 if (!results.ok) {
18 exitCode = 1;
19 }
20 }));
21 child.on('exit', function(code) {
22 if (typeof code !== 'number') {
23 exitCode = 1;
24 } else if (code) {
25 exitCode = code;
26 }
27 cb(coverage, exitCode);
28 });
29 var script = 'require("' + DUMP_NODE_PATH + '");require("' + entry + '");';
30 child.stdin.end(script);
31 return child;
32}
33
34module.exports = runNode;