Skip to content

Commit

Permalink
test: add test for -h/--help
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni committed Dec 5, 2021
1 parent b7d51f4 commit 6bf424f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 22 deletions.
67 changes: 67 additions & 0 deletions src/cli/__snapshots__/htmlhint.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Executable should print help with --help: stderr 1`] = `""`;

exports[`Executable should print help with --help: stdout 1`] = `
"Usage: htmlhint <file|folder|pattern|stdin|url ...> [options]
Options:
-V, --version output the version number
-l, --list show all of the rules available
-c, --config <file> custom configuration file
-r, --rules <ruleid, ruleid=value ...> set all of the rules available
-R, --rulesdir <file|folder> load custom rules from file or folder
-f, --format <checkstyle|compact|html|json|junit|markdown|unix> output messages as custom format
-i, --ignore <pattern, pattern ...> add pattern to exclude matches
--nocolor disable color
--warn Warn only, exit with 0
-h, --help display help for command
Examples:
htmlhint
htmlhint www
htmlhint www/test.html
htmlhint www/**/*.xhtml
htmlhint www/**/*.{htm,html}
htmlhint http://www.alibaba.com/
cat test.html | htmlhint stdin
htmlhint --list
htmlhint --rules tag-pair,id-class-value=underline test.html
htmlhint --config .htmlhintrc test.html
htmlhint --ignore **/build/**,**/test/**
htmlhint --rulesdir ./rules/
"
`;
exports[`Executable should print help with -h: stderr 1`] = `""`;
exports[`Executable should print help with -h: stdout 1`] = `
"Usage: htmlhint <file|folder|pattern|stdin|url ...> [options]
Options:
-V, --version output the version number
-l, --list show all of the rules available
-c, --config <file> custom configuration file
-r, --rules <ruleid, ruleid=value ...> set all of the rules available
-R, --rulesdir <file|folder> load custom rules from file or folder
-f, --format <checkstyle|compact|html|json|junit|markdown|unix> output messages as custom format
-i, --ignore <pattern, pattern ...> add pattern to exclude matches
--nocolor disable color
--warn Warn only, exit with 0
-h, --help display help for command
Examples:
htmlhint
htmlhint www
htmlhint www/test.html
htmlhint www/**/*.xhtml
htmlhint www/**/*.{htm,html}
htmlhint http://www.alibaba.com/
cat test.html | htmlhint stdin
htmlhint --list
htmlhint --rules tag-pair,id-class-value=underline test.html
htmlhint --config .htmlhintrc test.html
htmlhint --ignore **/build/**,**/test/**
htmlhint --rulesdir ./rules/
"
`;
39 changes: 17 additions & 22 deletions src/cli/htmlhint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,21 @@ describe('Executable', () => {
})
})

for (const format of [
'checkstyle',
'compact',
'default',
'html',
'json',
'junit',
'markdown',
'unix',
]) {
it(`should have stdout output with formatter ${format}`, async () => {
const { exitCode, stdout, stderr } = await run(__dirname, [
path.resolve(__dirname, '__fixtures__', 'executable.html'),
'--format',
format,
])

expect(exitCode).toBe(1)
expect(stdout).not.toBe('')
expect(stderr).toBe('')
})
}
it(`should print help with --help`, async () => {
const { exitCode, stdout, stderr } = await run(__dirname, ['--help'])

expect(exitCode).toBe(0)
expect(stdout).toMatchSnapshot('stdout')

expect(stderr).toMatchSnapshot('stderr')
})

it(`should print help with -h`, async () => {
const { exitCode, stdout, stderr } = await run(__dirname, ['-h'])

expect(exitCode).toBe(0)
expect(stdout).toMatchSnapshot('stdout')

expect(stderr).toMatchSnapshot('stderr')
})
})

0 comments on commit 6bf424f

Please sign in to comment.