Skip to content

Commit

Permalink
Do not log err.message of ProcessTermErrors if silent (#7472)
Browse files Browse the repository at this point in the history
* Do not log `err.message` of `ProcessTermError`s if silent

Fixes #5359

* Ensure `YARN_SILENT=0` by default in the integration tests
  • Loading branch information
kaste authored and arcanis committed Aug 16, 2019
1 parent 8deceab commit 7575b1f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions __tests__/fixtures/index/run-failing-script/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test_run_failing_script",
"version": "1.0.0",
"license": "UNLICENSED",
"scripts": {
"custom-script": "echo \"Hi\" && exit 1"
}
}
13 changes: 11 additions & 2 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ async function execCommand(
cwd: workingDir,
env: cleanedEnv,
},
(error, stdout) => {
(error, stdout, stderr) => {
if (error) {
reject(Object.assign((new Error(error.message): any), {stdout}));
reject(Object.assign((new Error(error.message): any), {stdout, stderr}));
} else {
const stdoutLines = stdout
.toString()
Expand Down Expand Up @@ -171,6 +171,15 @@ test.concurrent('should run custom script without run command', async () => {
expectRunOutput(stdout);
});

test.concurrent('should run without extra output for failing sub commands', async () => {
try {
await execCommand('run', ['--silent', 'custom-script'], 'run-failing-script');
throw new Error('the command did not fail');
} catch (err) {
expect(err.stderr).toBe('');
}
});

test.concurrent('should run help command', async () => {
const stdout = await execCommand('help', [], 'run-help');
expectHelpOutput(stdout);
Expand Down
1 change: 1 addition & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const getRandomPort = () => Math.floor(Math.random() * PORT_RANGE) + MIN_PORT_NU
async function runYarn(args: Array<string> = [], options: Object = {}): Promise<Array<Buffer>> {
if (!options['env']) {
options['env'] = {...process.env};
options['env']['YARN_SILENT'] = 0;
options['extendEnv'] = false;
}
options['env']['FORCE_COLOR'] = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ export async function main({
.catch((err: Error) => {
reporter.verbose(err.stack);

if (err instanceof ProcessTermError && reporter.isSilent) {
return exit(err.EXIT_CODE || 1);
}

if (err instanceof MessageError) {
reporter.error(err.message);
} else {
Expand Down

0 comments on commit 7575b1f

Please sign in to comment.