diff --git a/__tests__/index.js b/__tests__/index.js index 4ca796758e..09e6dc29ec 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -26,9 +26,9 @@ Promise> { } return new Promise((resolve, reject) => { - exec(`node "${yarnBin}" ${cmd} ${args.join(' ')}`, {cwd:workingDir, env:process.env}, (err, stdout) => { - if (err) { - reject(err); + exec(`node "${yarnBin}" ${cmd} ${args.join(' ')}`, {cwd:workingDir, env:process.env}, (error, stdout) => { + if (error) { + reject({error, stdout}); } else { const stdoutLines = stdout.toString() .split('\n') @@ -81,7 +81,17 @@ function expectAnErrorMessage(command: Promise>, error: string) : throw new Error('the command did not fail'); }) .catch((reason) => - expect(reason.message).toContain(error), + expect(reason.error.message).toContain(error), + ); +} + +function expectAnInfoMessageAfterError(command: Promise>, info: string) : Promise { + return command + .then(function() { + throw new Error('the command did not fail'); + }) + .catch((reason) => + expect(reason.stdout).toContain(info), ); } @@ -197,6 +207,13 @@ test.concurrent('should interpolate aliases', async () => { ); }); +test.concurrent('should display correct documentation for aliases', async () => { + await expectAnInfoMessageAfterError( + execCommand('i', [], 'run-add', true), + 'Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.', + ); +}); + test.concurrent('should run help of run command if --help is before --', async () => { const stdout = await execCommand('run', ['custom-script', '--help', '--'], 'run-custom-script-with-arguments'); expect(stdout[0]).toEqual('Usage: yarn [command] [flags]'); diff --git a/src/cli/index.js b/src/cli/index.js index d6532d6d3d..e41117611e 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -385,7 +385,7 @@ config.init({ } if (commandName) { - const actualCommandForHelp = commands[commandName] ? commandName : aliases[commandName]; + const actualCommandForHelp = aliases[commandName] ? aliases[commandName] : commandName; if (command && actualCommandForHelp) { reporter.info(getDocsInfo(actualCommandForHelp)); }