Skip to content

Commit

Permalink
display correct help link for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
voxsim committed Apr 10, 2017
1 parent 0899ac7 commit 71072db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Promise<Array<?string>> {
}

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')
Expand Down Expand Up @@ -81,7 +81,17 @@ function expectAnErrorMessage(command: Promise<Array<?string>>, 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<Array<?string>>, info: string) : Promise<void> {
return command
.then(function() {
throw new Error('the command did not fail');
})
.catch((reason) =>
expect(reason.stdout).toContain(info),
);
}

Expand Down Expand Up @@ -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]');
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 71072db

Please sign in to comment.