Skip to content

Commit

Permalink
feat: expose proc (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Jul 3, 2020
1 parent b2c6dac commit 34cad2a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.forkNode = (modulePath, args = [], options = {}) => {
const proc = cp.fork(modulePath, args, options);
gracefull(proc);

return new Promise((resolve, reject) => {
const promise = new Promise((resolve, reject) => {
proc.once('exit', code => {
childs.delete(proc);
if (code !== 0) {
Expand All @@ -61,6 +61,10 @@ exports.forkNode = (modulePath, args = [], options = {}) => {
}
});
});

promise.proc = proc;

return promise;
};

/**
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/my-helper/command/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class ForkCommand extends Command {
}

* run({ argv, rawArgv }) {
yield this.helper.forkNode(path.join(__dirname, '../scripts', argv.target), rawArgv.concat('--from=test'));
const task = this.helper.forkNode(path.join(__dirname, '../scripts', argv.target), rawArgv.concat('--from=test'));
console.log('task proc: %s', !!task.proc);
yield task;
}

get description() {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/my-helper/scripts/test_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

console.log('node version: %s', process.version);
console.log('process.argv: %j', process.argv.slice(2));
console.log('process.pid: %s, process.ppid: %s', process.pid, process.ppid);
1 change: 1 addition & 0 deletions test/my-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('test/my-helper.test.js', () => {
coffee.fork(myBin, [ 'fork', '--target=test_script' ], { cwd })
// .debug()
// .coverage(false)
.expect('stdout', /task proc: true/)
.expect('stdout', /process.argv: \["--target=test_script","--from=test"]/)
.expect('code', 0)
.end(done);
Expand Down

0 comments on commit 34cad2a

Please sign in to comment.