-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show help for unrecognized commands (#308)
- Loading branch information
1 parent
1832213
commit a7204d4
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`helpMisspelledCommand - show help for misspelled commands should return command is invalid if no commands are configured 1`] = `lingui: command compile is not a lingui command. See 'lingui --help' for the list of available commands.`; | ||
|
||
exports[`helpMisspelledCommand - show help for misspelled commands should return suggestions for mispelled 1`] = ` | ||
lingui: command compilesss is not a lingui command. See 'lingui --help' for the list of available commands. | ||
Did you mean: compile? | ||
`; | ||
|
||
exports[`helpMisspelledCommand - show help for misspelled commands shouldn't output anything if user passes no command 1`] = `undefined`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { helpMisspelledCommand } from "./utils" | ||
import { mockConsole } from "../mocks" | ||
|
||
function getConsoleMockCalls({ mock }) { | ||
if (!mock.calls.length) return | ||
return mock.calls.map(call => call[0]).join("\n") | ||
} | ||
|
||
describe("helpMisspelledCommand - show help for misspelled commands", function() { | ||
function mockCommands(command, commandNames) { | ||
return helpMisspelledCommand( | ||
command, | ||
commandNames.map(commandName => ({ name: () => commandName })) | ||
) | ||
} | ||
|
||
it("shouldn't output anything if command is valid", function() { | ||
mockConsole(console => { | ||
mockCommands("compile", ["compile"]) | ||
expect(getConsoleMockCalls(console.log)).toBeUndefined() | ||
}) | ||
}) | ||
|
||
it("shouldn't output anything if user passes no command", function() { | ||
mockConsole(console => { | ||
mockCommands("", ["compile"]) | ||
expect(getConsoleMockCalls(console.log)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it("should return command is invalid if no commands are configured", function() { | ||
mockConsole(console => { | ||
mockCommands("compile", []) | ||
expect(getConsoleMockCalls(console.log)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it("should return suggestions for mispelled", function() { | ||
mockConsole(console => { | ||
mockCommands("compilesss", ["compile"]) | ||
expect(getConsoleMockCalls(console.log)).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters