-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Support dashed args #7497
Support dashed args #7497
Changes from 3 commits
7c3e1ef
a9999f6
ec9ba73
3f45e11
bad4999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,6 +81,21 @@ you can use: | |||||
npm test -- -u -t="ColorPicker" | ||||||
``` | ||||||
|
||||||
## Camelcase & dashed args support | ||||||
|
||||||
Jest supports both camelcase and dashed arg formats. Which means the following examples will have equal result: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```bash | ||||||
jest --collect-coverage | ||||||
jest --collectCoverage | ||||||
``` | ||||||
|
||||||
They can also be mixed: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```bash | ||||||
jest --update-snapshot --detectOpenHandles | ||||||
``` | ||||||
|
||||||
## Options | ||||||
|
||||||
_Note: CLI options take precedence over values from the [Configuration](Configuration.md)._ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import path from 'path'; | ||
import runJest from '../runJest'; | ||
|
||
const consoleDir = path.resolve(__dirname, '../console'); | ||
const eachDir = path.resolve(__dirname, '../each'); | ||
|
||
expect.addSnapshotSerializer({ | ||
print: value => value, | ||
test: received => typeof received === 'string', | ||
}); | ||
|
||
test('works with passing tests', () => { | ||
const result = runJest(eachDir, [ | ||
'success.test.js', | ||
'--runInBand', | ||
'--collect-coverage', | ||
'--coverageReporters', | ||
'text-summary', | ||
'--clear-mocks', | ||
'--useStderr', | ||
]); | ||
if (result.status !== 0) { | ||
console.error(result.stderr); | ||
} | ||
expect(result.status).toBe(0); | ||
}); | ||
|
||
test('throws error for unknown dashed & camelcase args', () => { | ||
const result = runJest(consoleDir, [ | ||
'success.test.js', | ||
'--runInBand', | ||
'--collect-coverage', | ||
'--coverageReporters', | ||
'text-summary', | ||
'--clear-mocks', | ||
'--doesNotExist', | ||
'--also-does-not-exist', | ||
'--useStderr', | ||
]); | ||
expect(result.stderr).toMatchInlineSnapshot(` | ||
● Unrecognized CLI Parameters: | ||
|
||
Following options were not recognized: | ||
["doesNotExist", "also-does-not-exist"] | ||
|
||
CLI Options Documentation: | ||
https://jestjs.io/docs/en/cli.html | ||
|
||
|
||
`); | ||
expect(result.status).toBe(1); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,16 +65,27 @@ const logDeprecatedOptions = ( | |
}); | ||
}; | ||
|
||
export default function validateCLIOptions(argv: Argv, options: Object) { | ||
export default function validateCLIOptions( | ||
argv: Argv, | ||
options: Object, | ||
rawArgv: string[] = [], | ||
) { | ||
const yargsSpecialOptions = ['$0', '_', 'help', 'h']; | ||
const deprecationEntries = options.deprecationEntries || {}; | ||
const allowedOptions = Object.keys(options).reduce( | ||
(acc, option) => acc.add(option).add(options[option].alias || option), | ||
new Set(yargsSpecialOptions), | ||
); | ||
const unrecognizedOptions = Object.keys(argv).filter( | ||
arg => !allowedOptions.has(arg), | ||
); | ||
const unrecognizedOptions = Object.keys(argv).filter(arg => { | ||
const camelCased = arg.replace(/-([^-])/g, (a, b) => b.toUpperCase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add |
||
if ( | ||
!allowedOptions.has(camelCased) && | ||
(!rawArgv.length || rawArgv.includes(arg)) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
}, []); | ||
|
||
if (unrecognizedOptions.length) { | ||
throw createCLIValidationError(unrecognizedOptions, allowedOptions); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this below the breaking changes, preferably at the bottom of this section?