forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate config with
jest-validate
package (jestjs#2524)
* WIP validate.js * Add validate.js to handle config validation * Validate before normalizing * Add deprecated config handling * Fix lint errors * Fix Runtime-NODE_PATH-test * Fix linting on validate-test * Adjust tests * Move config validation to jest-validate package * Update readme * Make 'deprecated' configurable * Fix normalize and add test for preset * Move helper functions outside normalize() * Further simplify normalize.js * Add copyright to jest-validate types * Make normalize() a little more declarative * New Validation Errors for normalize * Fix extra quotation mark * Remove scripts from jest-validate's package.json * Update snapshots * Simplify condition * chalk.white -> chalk.reset * Sort config keys * Simplify footer condition * deprecatedWarning -> deprecationWarning * use getType() from jest-matcher-utils instead of prettyPrintType() * Adjust README * Remove preset.preprocessorIgnorePatterns check * Adjust jest-validate to be more generic * Update yarn.lock * Add missing 'testResultsProcessor' to validConfig * Update types with testResultsProcessor * Rename runtimeConfigError -> createConfigError * Rename footer -> comment * Rename validationError -> createValidationError * Remove scripts form jest-config package.json * Add defaultConfig and exampleConfig for self-validation check * Furhter refine the API of jest-validate * Adjust validate() usage in normalize.js * Update README.md * Update types.js
- Loading branch information
Showing
26 changed files
with
1,423 additions
and
365 deletions.
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
52 changes: 27 additions & 25 deletions
52
packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap
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 |
---|---|---|
@@ -1,44 +1,46 @@ | ||
exports[`Upgrade help logs a warning when \`scriptPreprocessor\` and/or \`preprocessorIgnorePatterns\` are used 1`] = ` | ||
"[33m[1m● [22mThe settings \`scriptPreprocessor\` and \`preprocessorIgnorePatterns\` were replaced by \`transform\` and \`transformIgnorePatterns\` which support multiple preprocessors. | ||
"[33m[1m[1m●[1m Deprecation Warning[22m: | ||
Jest now treats your current settings as: | ||
Option [1mpreprocessorIgnorePatterns[22m was replaced by [1mtransformIgnorePatterns[22m, which support multiple preprocessors. | ||
\"transform\": {\".*\": \"bar/baz\"} | ||
\"transformIgnorePatterns\": \"bar/baz,qux/quux\" | ||
Jest now treats your current configuration as: | ||
{ | ||
[1m\"transformIgnorePatterns\"[22m: [1m[\"bar/baz\", \"qux/quux\"][22m | ||
} | ||
Please update your configuration. | ||
Jest changed the default configuration for tests. | ||
[1mConfiguration Documentation:[22m https://facebook.github.io/jest/docs/configuration.html | ||
[1mJest Issue Tracker:[22m https://github.com/facebook/jest/issues | ||
[1mConfiguration Documentation:[22m | ||
https://facebook.github.io/jest/docs/configuration.html | ||
[39m" | ||
`; | ||
exports[`transform throws for invalid value 1`] = ` | ||
"[31mConfiguration option \`[1mtransform[22m\` must be an object. Use it like this: | ||
[1m \"transform\": { | ||
\"^.+\\\\.js$\": \"string\" | ||
}[22m | ||
exports[`preset throws when preset not found 1`] = ` | ||
"[31m[1m[1m● [1mValidation Error[22m: | ||
Jest changed the default configuration for tests. | ||
Preset [1mdoesnt-exist[22m not found. | ||
[1mConfiguration Documentation:[22m https://facebook.github.io/jest/docs/configuration.html | ||
[1mJest Issue Tracker:[22m https://github.com/facebook/jest/issues | ||
[1mConfiguration Documentation:[22m | ||
https://facebook.github.io/jest/docs/configuration.html | ||
[39m" | ||
`; | ||
exports[`transform throws for invalid value 2`] = ` | ||
"[31mConfiguration option \`[1mtransform[22m\` must be an object. Use it like this: | ||
exports[`rootDir throws if the config is missing a rootDir property 1`] = ` | ||
"[31m[1m[1m● [1mValidation Error[22m: | ||
Configuration option [1mrootDir[22m must be specified. | ||
[1mConfiguration Documentation:[22m | ||
https://facebook.github.io/jest/docs/configuration.html | ||
[39m" | ||
`; | ||
[1m \"transform\": { | ||
\"^.+\\\\.js$\": \"<rootDir>/node_modules/babel-jest\" | ||
}[22m | ||
exports[`testEnvironment throws on invalid environment names 1`] = ` | ||
"[31m[1m[1m● [1mValidation Error[22m: | ||
Jest changed the default configuration for tests. | ||
Test environment [1mphantom[22m cannot be found. Make sure the [1mtestEnvironment[22m configuration option points to an existing node module. | ||
[1mConfiguration Documentation:[22m https://facebook.github.io/jest/docs/configuration.html | ||
[1mJest Issue Tracker:[22m https://github.com/facebook/jest/issues | ||
[1mConfiguration Documentation:[22m | ||
https://facebook.github.io/jest/docs/configuration.html | ||
[39m" | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
const format = (value: string) => require('pretty-format')(value, {min: true}); | ||
|
||
/* eslint-disable max-len */ | ||
const deprecatedOptions = { | ||
preprocessorIgnorePatterns: (config: Object) => | ||
` Option ${chalk.bold('preprocessorIgnorePatterns')} was replaced by ${chalk.bold('transformIgnorePatterns')}, which support multiple preprocessors. | ||
Jest now treats your current configuration as: | ||
{ | ||
${chalk.bold('"transformIgnorePatterns"')}: ${chalk.bold(`${format(config.preprocessorIgnorePatterns)}`)} | ||
} | ||
Please update your configuration.`, | ||
|
||
scriptPreprocessor: (config: Object) => | ||
` Option ${chalk.bold('scriptPreprocessor')} was replaced by ${chalk.bold('transform')}, which support multiple preprocessors. | ||
Jest now treats your current configuration as: | ||
{ | ||
${chalk.bold('"transform"')}: ${chalk.bold(`{".*": ${format(config.scriptPreprocessor)}}`)} | ||
} | ||
Please update your configuration.`, | ||
}; | ||
/* eslint-enable max-len */ | ||
|
||
module.exports = deprecatedOptions; |
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
Oops, something went wrong.