Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Report error if unwanted positional arguments are received #1100

Merged
merged 1 commit into from May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/commands/check-coverage.js
Expand Up @@ -7,6 +7,7 @@ exports.describe = 'check whether coverage is within thresholds provided'

exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.option('exclude', {
alias: 'x',
default: testExclude.defaultExclude,
Expand Down
9 changes: 9 additions & 0 deletions lib/commands/instrument.js
Expand Up @@ -9,6 +9,15 @@ exports.describe = 'instruments a file or a directory tree and writes the instru

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.positional('input', {
describe: 'file or directory to instrument',
type: 'text'
})
.positional('output', {
describe: 'directory to output instrumented files',
type: 'text'
})
.option('require', {
alias: 'i',
default: [],
Expand Down
1 change: 1 addition & 0 deletions lib/commands/merge.js
Expand Up @@ -11,6 +11,7 @@ exports.describe = 'merge istanbul format coverage output in a given folder'

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.positional('input-directory', {
describe: 'directory containing multiple istanbul coverage files',
type: 'text',
Expand Down
1 change: 1 addition & 0 deletions lib/commands/report.js
Expand Up @@ -7,6 +7,7 @@ exports.describe = 'run coverage report for .nyc_output'

exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.option('reporter', {
alias: 'r',
describe: 'coverage reporter(s) to use',
Expand Down
38 changes: 19 additions & 19 deletions tap-snapshots/test-nyc-integration.js-TAP.test.js
Expand Up @@ -20,25 +20,6 @@ All files | 33.33 | 0 | 100 | 33.33 |

`

exports[`test/nyc-integration.js TAP --check-coverage fails when check-coverage command is used rather than flag > stderr 1`] = `
ERROR: Coverage for lines (50%) does not meet global threshold (51%)

`

exports[`test/nyc-integration.js TAP --check-coverage fails when check-coverage command is used rather than flag > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|

`

exports[`test/nyc-integration.js TAP --check-coverage fails when check-coverage command is used rather than flag > stdout 2`] = `

`

exports[`test/nyc-integration.js TAP --check-coverage fails when the expected coverage is below a threshold > stderr 1`] = `
ERROR: Coverage for lines (50%) does not meet global threshold (51%)

Expand Down Expand Up @@ -310,6 +291,25 @@ end_of_record

`

exports[`test/nyc-integration.js TAP check-coverage command is equivalent to the flag > stderr 1`] = `
ERROR: Coverage for lines (50%) does not meet global threshold (51%)

`

exports[`test/nyc-integration.js TAP check-coverage command is equivalent to the flag > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|

`

exports[`test/nyc-integration.js TAP check-coverage command is equivalent to the flag > stdout 2`] = `

`

exports[`test/nyc-integration.js TAP does not interpret args intended for instrumented bin > undefined 1`] = `
[ '--help', '--version' ]
`
Expand Down
4 changes: 2 additions & 2 deletions test/nyc-integration.js
Expand Up @@ -45,11 +45,11 @@ t.test('--check-coverage fails when the expected coverage is below a threshold',
}))

// https://github.com/istanbuljs/nyc/issues/384
t.test('--check-coverage fails when check-coverage command is used rather than flag', t => {
t.test('check-coverage command is equivalent to the flag', t => {
return testSuccess(t, {
args: [process.execPath, './half-covered.js']
}).then(() => testFailure(t, {
args: ['check-coverage', '--lines', '51', process.execPath, './half-covered.js']
args: ['check-coverage', '--lines', '51']
coreyfarrell marked this conversation as resolved.
Show resolved Hide resolved
}))
})

Expand Down