Skip to content

Commit 6b7b6be

Browse files
committed
test: add test for -h/--help
1 parent 68b677e commit 6b7b6be

File tree

2 files changed

+84
-22
lines changed

2 files changed

+84
-22
lines changed

Diff for: src/cli/__snapshots__/htmlhint.spec.js.snap

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Executable should print help with --help: stderr 1`] = `""`;
4+
5+
exports[`Executable should print help with --help: stdout 1`] = `
6+
"Usage: htmlhint <file|folder|pattern|stdin|url ...> [options]
7+
8+
Options:
9+
-V, --version output the version number
10+
-l, --list show all of the rules available
11+
-c, --config <file> custom configuration file
12+
-r, --rules <ruleid, ruleid=value ...> set all of the rules available
13+
-R, --rulesdir <file|folder> load custom rules from file or folder
14+
-f, --format <checkstyle|compact|html|json|junit|markdown|unix> output messages as custom format
15+
-i, --ignore <pattern, pattern ...> add pattern to exclude matches
16+
--nocolor disable color
17+
--warn Warn only, exit with 0
18+
-h, --help display help for command
19+
Examples:
20+
21+
htmlhint
22+
htmlhint www
23+
htmlhint www/test.html
24+
htmlhint www/**/*.xhtml
25+
htmlhint www/**/*.{htm,html}
26+
htmlhint http://www.alibaba.com/
27+
cat test.html | htmlhint stdin
28+
htmlhint --list
29+
htmlhint --rules tag-pair,id-class-value=underline test.html
30+
htmlhint --config .htmlhintrc test.html
31+
htmlhint --ignore **/build/**,**/test/**
32+
htmlhint --rulesdir ./rules/
33+
"
34+
`;
35+
36+
exports[`Executable should print help with -h: stderr 1`] = `""`;
37+
38+
exports[`Executable should print help with -h: stdout 1`] = `
39+
"Usage: htmlhint <file|folder|pattern|stdin|url ...> [options]
40+
41+
Options:
42+
-V, --version output the version number
43+
-l, --list show all of the rules available
44+
-c, --config <file> custom configuration file
45+
-r, --rules <ruleid, ruleid=value ...> set all of the rules available
46+
-R, --rulesdir <file|folder> load custom rules from file or folder
47+
-f, --format <checkstyle|compact|html|json|junit|markdown|unix> output messages as custom format
48+
-i, --ignore <pattern, pattern ...> add pattern to exclude matches
49+
--nocolor disable color
50+
--warn Warn only, exit with 0
51+
-h, --help display help for command
52+
Examples:
53+
54+
htmlhint
55+
htmlhint www
56+
htmlhint www/test.html
57+
htmlhint www/**/*.xhtml
58+
htmlhint www/**/*.{htm,html}
59+
htmlhint http://www.alibaba.com/
60+
cat test.html | htmlhint stdin
61+
htmlhint --list
62+
htmlhint --rules tag-pair,id-class-value=underline test.html
63+
htmlhint --config .htmlhintrc test.html
64+
htmlhint --ignore **/build/**,**/test/**
65+
htmlhint --rulesdir ./rules/
66+
"
67+
`;

Diff for: src/cli/htmlhint.spec.js

+17-22
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,21 @@ describe('Executable', () => {
3636
})
3737
})
3838

39-
for (const format of [
40-
'checkstyle',
41-
'compact',
42-
'default',
43-
'html',
44-
'json',
45-
'junit',
46-
'markdown',
47-
'unix',
48-
]) {
49-
it(`should have stdout output with formatter ${format}`, async () => {
50-
const { exitCode, stdout, stderr } = await run(__dirname, [
51-
path.resolve(__dirname, '__fixtures__', 'executable.html'),
52-
'--format',
53-
format,
54-
])
55-
56-
expect(exitCode).toBe(1)
57-
expect(stdout).not.toBe('')
58-
expect(stderr).toBe('')
59-
})
60-
}
39+
it(`should print help with --help`, async () => {
40+
const { exitCode, stdout, stderr } = await run(__dirname, ['--help'])
41+
42+
expect(exitCode).toBe(0)
43+
expect(stdout).toMatchSnapshot('stdout')
44+
45+
expect(stderr).toMatchSnapshot('stderr')
46+
})
47+
48+
it(`should print help with -h`, async () => {
49+
const { exitCode, stdout, stderr } = await run(__dirname, ['-h'])
50+
51+
expect(exitCode).toBe(0)
52+
expect(stdout).toMatchSnapshot('stdout')
53+
54+
expect(stderr).toMatchSnapshot('stderr')
55+
})
6156
})

0 commit comments

Comments
 (0)