Skip to content

Commit

Permalink
Pass destinationRoot to spawn-command by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 15, 2021
1 parent 097cd20 commit 7050e53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/actions/spawn-command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const _ = require('lodash');
const spawn = require('execa');

/**
Expand All @@ -17,8 +16,11 @@ const spawnCommand = module.exports;
* @return {String} spawned process reference
*/
spawnCommand.spawnCommand = (command, args, opt) => {
opt = opt || {};
return spawn(command, args, _.defaults(opt, {stdio: 'inherit'}));
return spawn(command, args, {
stdio: 'inherit',
cwd: this.destinationRoot(),
...opt
});
};

/**
Expand All @@ -30,6 +32,9 @@ spawnCommand.spawnCommand = (command, args, opt) => {
* @return {String} spawn.sync result
*/
spawnCommand.spawnCommandSync = (command, args, opt) => {
opt = opt || {};
return spawn.sync(command, args, _.defaults(opt, {stdio: 'inherit'}));
return spawn.sync(command, args, {
stdio: 'inherit',
cwd: this.destinationRoot(),
...opt
});
};
12 changes: 12 additions & 0 deletions test/spawn-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ const proxyquire = require('proxyquire');
const sinon = require('sinon');

describe('generators.Base (actions/spawn-command)', () => {
let cwd;

beforeEach(function () {
this.crossSpawn = sinon.spy();
this.crossSpawn.sync = sinon.spy();
this.spawn = proxyquire('../lib/actions/spawn-command', {
execa: this.crossSpawn
});
cwd = Math.random().toString(36).slice(7);
this.spawn.destinationRoot = sinon.stub().returns(cwd);
});

describe('#spawnCommand()', () => {
it('provide default options', function () {
this.spawn.spawnCommand('foo');
sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, {
cwd,
stdio: 'inherit'
});
});

it('pass arguments', function () {
this.spawn.spawnCommand('foo', 'bar');
sinon.assert.calledWith(this.crossSpawn, 'foo', 'bar', {
cwd,
stdio: 'inherit'
});
});

it('pass options', function () {
this.spawn.spawnCommand('foo', undefined, {foo: 1});
sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, {
cwd,
foo: 1,
stdio: 'inherit'
});
Expand All @@ -37,6 +44,7 @@ describe('generators.Base (actions/spawn-command)', () => {
it('allow overriding default options', function () {
this.spawn.spawnCommand('foo', undefined, {stdio: 'ignore'});
sinon.assert.calledWith(this.crossSpawn, 'foo', undefined, {
cwd,
stdio: 'ignore'
});
});
Expand All @@ -46,20 +54,23 @@ describe('generators.Base (actions/spawn-command)', () => {
it('provide default options', function () {
this.spawn.spawnCommandSync('foo');
sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, {
cwd,
stdio: 'inherit'
});
});

it('pass arguments', function () {
this.spawn.spawnCommandSync('foo', 'bar');
sinon.assert.calledWith(this.crossSpawn.sync, 'foo', 'bar', {
cwd,
stdio: 'inherit'
});
});

it('pass options', function () {
this.spawn.spawnCommandSync('foo', undefined, {foo: 1});
sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, {
cwd,
foo: 1,
stdio: 'inherit'
});
Expand All @@ -68,6 +79,7 @@ describe('generators.Base (actions/spawn-command)', () => {
it('allow overriding default options', function () {
this.spawn.spawnCommandSync('foo', undefined, {stdio: 'wut'});
sinon.assert.calledWith(this.crossSpawn.sync, 'foo', undefined, {
cwd,
stdio: 'wut'
});
});
Expand Down

0 comments on commit 7050e53

Please sign in to comment.