Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: silent does not always work #851
  • Loading branch information
uttpal authored and nfischer committed Oct 10, 2018
commit c368d562a932821058b6360f36ca57c994dad441
2 changes: 1 addition & 1 deletion src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function execSync(cmd, opts, pipe) {
try { common.unlinkSync(stdoutFile); } catch (e) {}

if (code !== 0) {
common.error(stderr, code, { continue: true });
common.error(stderr, code, { continue: true, silent: opts.silent });
}
var obj = common.ShellString(stdout, stderr, code);
return obj;
Expand Down
14 changes: 14 additions & 0 deletions test/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import test from 'ava';

import shell from '..';
import utils from './utils/utils';
import mocks from './utils/mocks';

const CWD = process.cwd();
const ORIG_EXEC_PATH = shell.config.execPath;
shell.config.silent = true;

test.beforeEach(() => {
mocks.init();
});

test.afterEach.always(() => {
process.chdir(CWD);
shell.config.execPath = ORIG_EXEC_PATH;
mocks.restore();
});

//
Expand Down Expand Up @@ -85,6 +91,14 @@ test('check if stdout + stderr go to output', t => {
t.is(result.stderr, '1234\n');
});

test('check if stdout + stderr should not be printed to console if silent', t => {
shell.exec(`${JSON.stringify(shell.config.execPath)} -e "console.error(1234); console.log(666); process.exit(12);"`, { silent: true });
const stdout = mocks.stdout();
const stderr = mocks.stderr();
t.is(stdout, '');
t.is(stderr, '');
});

test('check exit code', t => {
const result = shell.exec(`${JSON.stringify(shell.config.execPath)} -e "process.exit(12);"`);
t.truthy(shell.error());
Expand Down