-
-
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
Print deprecation warnings on CLI flags #5536
Merged
cpojer
merged 3 commits into
jestjs:master
from
Aftabnack:jest-validate-cli-deprecations
Feb 16, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
integration-tests/__tests__/deprecated_cli_options.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2014-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'; | ||
|
||
const path = require('path'); | ||
const runJest = require('../runJest'); | ||
|
||
const dir = path.resolve(__dirname, '../deprecated-cli-options'); | ||
|
||
it('Prints deprecation warnings for CLI flags', () => { | ||
const {stderr, status} = runJest(dir, ['--mapCoverage']); | ||
expect(status).toBe(0); | ||
expect(stderr).toMatch(/Test Suites: 1 passed, 1 total/); | ||
expect(stderr).toMatch(`● Deprecation Warning: | ||
|
||
Option "mapCoverage" has been removed, as it's no longer necessary. | ||
|
||
Please update your configuration. | ||
|
||
CLI Options Documentation: | ||
https://facebook.github.io/jest/docs/en/cli.html`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test('Dummy', () => { | ||
expect(2).toBe(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"jest": {} | ||
} |
3 changes: 0 additions & 3 deletions
3
...n-tests/snapshot-escape/__tests__/__snapshots__/snapshot_escape_substitution.test.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,15 @@ | |
import type {Argv} from 'types/Argv'; | ||
|
||
import chalk from 'chalk'; | ||
import {ValidationError, format, createDidYouMeanMessage} from 'jest-validate'; | ||
import {deprecationEntries} from 'jest-config'; | ||
import {createDidYouMeanMessage, format, ValidationError} from './utils'; | ||
import {deprecationWarning} from './deprecated'; | ||
import defaultConfig from './default_config'; | ||
|
||
const BULLET: string = chalk.bold('\u25cf'); | ||
export const DOCUMENTATION_NOTE = ` ${chalk.bold('CLI Options Documentation:')} | ||
https://facebook.github.io/jest/docs/en/cli.html | ||
`; | ||
|
||
const createCLIValidationError = ( | ||
unrecognizedOptions: Array<string>, | ||
|
@@ -43,6 +49,23 @@ const createCLIValidationError = ( | |
return new ValidationError(title, message, comment); | ||
}; | ||
|
||
const logDeprecatedOptions = ( | ||
deprecatedOptions: Array<string>, | ||
deprecationEntries: Object, | ||
argv: Argv, | ||
) => { | ||
deprecatedOptions.forEach(opt => { | ||
deprecationWarning( | ||
argv, | ||
opt, | ||
deprecationEntries, | ||
Object.assign({}, defaultConfig, { | ||
comment: DOCUMENTATION_NOTE, | ||
}), | ||
); | ||
}); | ||
}; | ||
|
||
export default function validateCLIOptions(argv: Argv, options: Object) { | ||
const yargsSpecialOptions = ['$0', '_', 'help', 'h']; | ||
const allowedOptions = Object.keys(options).reduce( | ||
|
@@ -57,5 +80,26 @@ export default function validateCLIOptions(argv: Argv, options: Object) { | |
throw createCLIValidationError(unrecognizedOptions, allowedOptions); | ||
} | ||
|
||
const CLIDeprecations = Object.keys(deprecationEntries).reduce( | ||
(acc, entry) => { | ||
if (options[entry]) { | ||
acc[entry] = deprecationEntries[entry]; | ||
if (options[entry].alias) { | ||
acc[options[entry].alias] = deprecationEntries[entry]; | ||
} | ||
} | ||
return acc; | ||
}, | ||
{}, | ||
); | ||
const deprecations = new Set(Object.keys(CLIDeprecations)); | ||
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. Could you add some tests for this behavior? |
||
const deprecatedOptions = Object.keys(argv).filter( | ||
arg => deprecations.has(arg) && argv[arg] != null, | ||
); | ||
|
||
if (deprecatedOptions.length) { | ||
logDeprecatedOptions(deprecatedOptions, CLIDeprecations, argv); | ||
} | ||
|
||
return true; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
technically a breaking change. not sure if it matters, though
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.
It absolutely matters. Please see #5749