Skip to content

Commit

Permalink
sets shell option to true for childprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
chrkhl committed Nov 21, 2018
1 parent 909aa9a commit f97137b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/read-dependencies.js
Expand Up @@ -7,9 +7,13 @@ const readDependencies = (options = []) => {

options.forEach(option => args.push(`--${option}`));

const result = childProcess.spawnSync('npm', args);
const result = childProcess.spawnSync('npm', args, { shell: true });
const tree = JSON.parse(result.stdout);

if (!tree) {
throw new Error('Failed to read dependencies');
}

// mark root level -> we want to exclude this level from analysis
tree.isRoot = true;

Expand Down
12 changes: 9 additions & 3 deletions lib/read-dependencies.test.js
Expand Up @@ -41,7 +41,7 @@ describe('readDependencies', () => {
it('calls child_process.spawnSync "npm ls --json"', () => {
readDependencies();

expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json' ]);
expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json' ], { shell: true });
});

it('returns parsed json returned by child process', () => {
Expand All @@ -59,7 +59,7 @@ describe('readDependencies', () => {
it('calls child_process.spawnSync "npm ls --json --production"', () => {
readDependencies([ 'production' ]);

expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json', '--production' ]);
expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json', '--production' ], { shell: true });
});

it('returns parsed json returned by child process', () => {
Expand All @@ -77,7 +77,7 @@ describe('readDependencies', () => {
it('calls child_process.spawnSync "npm ls --json --development"', () => {
readDependencies([ 'development' ]);

expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json', '--development' ]);
expect(childProcess.spawnSync).toHaveBeenCalledWith('npm', [ 'ls', '--json', '--development' ], { shell: true });
});

it('returns parsed json returned by child process', () => {
Expand All @@ -91,6 +91,12 @@ describe('readDependencies', () => {
});
});

it('throws when parsed tree is null', () => {
childProcess.spawnSync.mockImplementation(() => ({ stdout: null }));

expect(readDependencies).toThrow('Failed to read dependencies');
});

it('returns problems found by npm ls', () => {
childProcess.spawnSync.mockImplementation(() => ({ stdout: stringifiedTree, stderr: 'missing peer dependencies' }));

Expand Down

0 comments on commit f97137b

Please sign in to comment.