diff --git a/test/index.js b/test/index.js index 92ff7d7..13d2a12 100644 --- a/test/index.js +++ b/test/index.js @@ -11,12 +11,18 @@ test('shows up help message without any args', async t => { t.snapshot(stdout); }); -test('shows version with arg -V', async t => { - const { stdout } = await execa(rootCommand, ['-V']); +const matchSnapshot = async (t, arg) => { + const { stdout } = await execa(rootCommand, [arg]); t.snapshot(stdout); -}); +}; -test('shows version with arg --version', async t => { - const { stdout } = await execa(rootCommand, ['--version']); - t.snapshot(stdout); +test('shows version with arg --version', matchSnapshot, '--version'); +test('shows version with arg -V', matchSnapshot, '-V'); +test('shows help with arg -h', matchSnapshot, '-h'); +test('shows help with arg --help', matchSnapshot, '--help'); +test('shows command usage with unknown command', matchSnapshot, 'junkcmd'); + +test('rejects promise due to error with arg -a', async t => { + const { stderr } = await execa(rootCommand, ['-a'], { reject: false }); + t.snapshot(stderr); }); diff --git a/test/snapshots/index.js.md b/test/snapshots/index.js.md index c31f925..4e79f25 100644 --- a/test/snapshots/index.js.md +++ b/test/snapshots/index.js.md @@ -32,3 +32,64 @@ Generated by [AVA](https://ava.li). > Snapshot 1 '1.2.6' + +## rejects promise due to error with arg -a + +> Snapshot 1 + + `error: unknown option `-a'␊ + ` + +## shows command usage with unknown command + +> Snapshot 1 + + `Usage: teachcode [options]␊ + ␊ + Options:␊ + -V, --version output the version number␊ + -h, --help output usage information␊ + ␊ + Commands:␊ + init Initialize challenges␊ + submit Submits current task␊ + fetchtask Fetches any task as per the key supplied␊ + showkeys Shows keys of all the completed tasks␊ + showcommands Shows all commands available␊ + ␊ + Unknown command junkcmd.␊ + ` + +## shows help with arg --help + +> Snapshot 1 + + `Usage: teachcode [options]␊ + ␊ + Options:␊ + -V, --version output the version number␊ + -h, --help output usage information␊ + ␊ + Commands:␊ + init Initialize challenges␊ + submit Submits current task␊ + fetchtask Fetches any task as per the key supplied␊ + showkeys Shows keys of all the completed tasks␊ + showcommands Shows all commands available` + +## shows help with arg -h + +> Snapshot 1 + + `Usage: teachcode [options]␊ + ␊ + Options:␊ + -V, --version output the version number␊ + -h, --help output usage information␊ + ␊ + Commands:␊ + init Initialize challenges␊ + submit Submits current task␊ + fetchtask Fetches any task as per the key supplied␊ + showkeys Shows keys of all the completed tasks␊ + showcommands Shows all commands available` diff --git a/test/snapshots/index.js.snap b/test/snapshots/index.js.snap index 13cd5fb..2a803dd 100644 Binary files a/test/snapshots/index.js.snap and b/test/snapshots/index.js.snap differ