Skip to content

Commit 7881c16

Browse files
committed
test: add tests for showing help and version
1 parent 8d7fa64 commit 7881c16

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"eslint-plugin-filenames": "^1.2.0",
5252
"eslint-plugin-security": "^1.4.0",
5353
"eslint-plugin-unicorn": "^4.0.2",
54+
"is-semver": "^1.0.8",
5455
"nsp": "^3.2.1",
5556
"nyc": "^11.4.1",
5657
"standard-version": "^4.3.0"

test/cli.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import test from 'ava';
22
import execa from 'execa';
3+
import isSemver from 'is-semver';
34

4-
test('Unknown command', async t => {
5+
test('"Unknown command"', async t => {
56
const result = await t.throws(execa('./cli.js', ['Hej']));
67
t.is(result.code, 127);
78
t.regex(result.stderr, /Hej:.+not found/);
@@ -22,23 +23,55 @@ test('"Command which exits properly with exit code 0"', async t => {
2223
t.is(result.stderr, '');
2324
});
2425

25-
test('No input given', async t => {
26+
test('"No input given"', async t => {
2627
const result = await t.throws(execa('./cli.js', []));
2728
t.is(result.code, 2);
2829
t.regex(result.stdout, /Invalid input. Please check the help below:/);
2930
t.regex(result.stdout, /Usage/);
3031
});
3132

32-
test('To much input', async t => {
33+
test('"To much input"', async t => {
3334
const result = await t.throws(execa('./cli.js', ['Hu', 'Ha']));
3435
t.is(result.code, 2);
3536
t.regex(result.stdout, /Invalid input. Please check the help below:/);
3637
t.regex(result.stdout, /Usage/);
3738
});
3839

39-
test('wrong options', async t => {
40+
test('"wrong options"', async t => {
4041
const result = await t.throws(execa('./cli.js', ['echo Hej', '-p']));
4142
t.is(result.code, 2);
4243
t.regex(result.stdout, /Wrong option\(s\) provided. Please check the help below:/);
4344
t.regex(result.stdout, /Usage/);
4445
});
46+
47+
test('"Show version number via flag"', async t => {
48+
await t.notThrows(execa('./cli.js', ['--version']));
49+
const result = await execa('./cli.js', ['--version']);
50+
t.true(isSemver(result.stdout));
51+
t.is(result.code, 0);
52+
t.is(result.stderr, '');
53+
});
54+
55+
test('"Show version number via alias"', async t => {
56+
await t.notThrows(execa('./cli.js', ['-v']));
57+
const result = await execa('./cli.js', ['-v']);
58+
t.true(isSemver(result.stdout));
59+
t.is(result.code, 0);
60+
t.is(result.stderr, '');
61+
});
62+
63+
test('"Show help via flag"', async t => {
64+
await t.notThrows(execa('./cli.js', ['--help']));
65+
const result = await execa('./cli.js', ['--help']);
66+
t.regex(result.stdout, /^\n {2}Sends native desktop notifications/m);
67+
t.is(result.code, 0);
68+
t.is(result.stderr, '');
69+
});
70+
71+
test('"Show help via alias"', async t => {
72+
await t.notThrows(execa('./cli.js', ['-h']));
73+
const result = await execa('./cli.js', ['-h']);
74+
t.regex(result.stdout, /^\n {2}Sends native desktop notifications/m);
75+
t.is(result.code, 0);
76+
t.is(result.stderr, '');
77+
});

0 commit comments

Comments
 (0)