jest-config
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -7,13 +7,9 @@ 'use strict'; | ||
exports.getDisplayNameColor = void 0; | ||
function _crypto() { | ||
const data = require('crypto'); | ||
_crypto = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
@@ -25,4 +21,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']; | ||
const getDisplayNameColor = seed => { | ||
@@ -32,3 +28,2 @@ if (seed === undefined) { | ||
} | ||
const hash = (0, _crypto().createHash)('sha256'); | ||
@@ -39,3 +34,2 @@ hash.update(seed); | ||
}; | ||
exports.getDisplayNameColor = getDisplayNameColor; |
@@ -17,13 +17,9 @@ 'use strict'; | ||
void 0; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -37,3 +33,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -71,3 +66,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -79,2 +73,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const NODE_MODULES = `${path().sep}node_modules${path().sep}`; | ||
@@ -81,0 +76,0 @@ exports.NODE_MODULES = NODE_MODULES; |
@@ -7,41 +7,28 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _path() { | ||
const data = require('path'); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _ciInfo() { | ||
const data = require('ci-info'); | ||
_ciInfo = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestRegexUtil() { | ||
const data = require('jest-regex-util'); | ||
_jestRegexUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = require('./constants'); | ||
var _getCacheDirectory = _interopRequireDefault(require('./getCacheDirectory')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -53,2 +40,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const NODE_MODULES_REGEXP = (0, _jestRegexUtil().replacePathSepForRegex)( | ||
@@ -55,0 +43,0 @@ _constants.NODE_MODULES |
@@ -7,17 +7,12 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -29,2 +24,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const deprecatedOptions = { | ||
@@ -31,0 +27,0 @@ browser: () => |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = void 0; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const descriptions = { | ||
@@ -17,0 +17,0 @@ automock: 'All imported modules in your tests should be mocked automatically', |
@@ -7,33 +7,23 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _os() { | ||
const data = require('os'); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -47,3 +37,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -81,3 +70,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -89,2 +77,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const getCacheDirectory = () => { | ||
@@ -96,3 +85,2 @@ const {getuid} = process; | ||
); | ||
if (getuid == null) { | ||
@@ -107,4 +95,3 @@ return tmpdirPath; | ||
}; | ||
var _default = getCacheDirectory; | ||
exports.default = _default; |
@@ -7,13 +7,9 @@ 'use strict'; | ||
exports.default = getMaxWorkers; | ||
function _os() { | ||
const data = require('os'); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
@@ -25,2 +21,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
function getMaxWorkers(argv, defaultOptions) { | ||
@@ -44,6 +41,4 @@ if (argv.runInBand) { | ||
} | ||
const parseWorkers = maxWorkers => { | ||
const parsed = parseInt(maxWorkers.toString(), 10); | ||
if ( | ||
@@ -59,4 +54,3 @@ typeof maxWorkers === 'string' && | ||
} | ||
return parsed > 0 ? parsed : 1; | ||
}; |
@@ -99,2 +99,44 @@ /** | ||
/** | ||
* Reads the jest config, without validating them or filling it out with defaults. | ||
* @param config The path to the file or serialized config. | ||
* @param param1 Additional options | ||
* @returns The raw initial config (not validated) | ||
*/ | ||
export declare function readInitialOptions( | ||
config?: string, | ||
{ | ||
packageRootOrConfig, | ||
parentConfigDirname, | ||
readFromCwd, | ||
skipMultipleConfigError, | ||
}?: ReadJestConfigOptions, | ||
): Promise<{ | ||
config: Config.InitialOptions; | ||
configPath: string | null; | ||
}>; | ||
export declare interface ReadJestConfigOptions { | ||
/** | ||
* The package root or deserialized config (default is cwd) | ||
*/ | ||
packageRootOrConfig?: string | Config.InitialOptions; | ||
/** | ||
* When the `packageRootOrConfig` contains config, this parameter should | ||
* contain the dirname of the parent config | ||
*/ | ||
parentConfigDirname?: null | string; | ||
/** | ||
* Indicates whether or not to read the specified config file from disk. | ||
* When true, jest will read try to read config from the current working directory. | ||
* (default is false) | ||
*/ | ||
readFromCwd?: boolean; | ||
/** | ||
* Indicates whether or not to ignore the error of jest finding multiple config files. | ||
* (default is false) | ||
*/ | ||
skipMultipleConfigError?: boolean; | ||
} | ||
export declare const replaceRootDirInPath: ( | ||
@@ -101,0 +143,0 @@ rootDir: string, |
@@ -39,2 +39,3 @@ 'use strict'; | ||
exports.readConfigs = readConfigs; | ||
exports.readInitialOptions = readInitialOptions; | ||
Object.defineProperty(exports, 'replaceRootDirInPath', { | ||
@@ -46,67 +47,44 @@ enumerable: true, | ||
}); | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var constants = _interopRequireWildcard(require('./constants')); | ||
exports.constants = constants; | ||
var _normalize = _interopRequireDefault(require('./normalize')); | ||
var _readConfigFileAndSetRootDir = _interopRequireDefault( | ||
require('./readConfigFileAndSetRootDir') | ||
); | ||
var _resolveConfigPath = _interopRequireDefault(require('./resolveConfigPath')); | ||
var _utils = require('./utils'); | ||
var _Deprecated = _interopRequireDefault(require('./Deprecated')); | ||
var _Defaults = _interopRequireDefault(require('./Defaults')); | ||
var _Descriptions = _interopRequireDefault(require('./Descriptions')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -120,3 +98,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -154,3 +131,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -162,5 +138,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
async function readConfig( | ||
argv, | ||
packageRootOrConfig, // Whether it needs to look into `--config` arg passed to CLI. | ||
packageRootOrConfig, | ||
// Whether it needs to look into `--config` arg passed to CLI. | ||
// It only used to read initial config. If the initial config contains | ||
@@ -174,54 +152,13 @@ // `project` property, we don't want to read `--config` value and rather | ||
) { | ||
let rawOptions; | ||
let configPath = null; | ||
if (typeof packageRootOrConfig !== 'string') { | ||
if (parentConfigDirname) { | ||
rawOptions = packageRootOrConfig; | ||
rawOptions.rootDir = rawOptions.rootDir | ||
? (0, _utils.replaceRootDirInPath)( | ||
parentConfigDirname, | ||
rawOptions.rootDir | ||
) | ||
: parentConfigDirname; | ||
} else { | ||
throw new Error( | ||
'Jest: Cannot use configuration as an object without a file path.' | ||
); | ||
} | ||
} else if ((0, _utils.isJSONString)(argv.config)) { | ||
// A JSON string was passed to `--config` argument and we can parse it | ||
// and use as is. | ||
let config; | ||
try { | ||
config = JSON.parse(argv.config); | ||
} catch { | ||
throw new Error( | ||
'There was an error while parsing the `--config` argument as a JSON string.' | ||
); | ||
} // NOTE: we might need to resolve this dir to an absolute path in the future | ||
config.rootDir = config.rootDir || packageRootOrConfig; | ||
rawOptions = config; // A string passed to `--config`, which is either a direct path to the config | ||
// or a path to directory containing `package.json`, `jest.config.js` or `jest.config.ts` | ||
} else if (!skipArgvConfigOption && typeof argv.config == 'string') { | ||
configPath = (0, _resolveConfigPath.default)( | ||
argv.config, | ||
process.cwd(), | ||
skipMultipleConfigError | ||
); | ||
rawOptions = await (0, _readConfigFileAndSetRootDir.default)(configPath); | ||
} else { | ||
// Otherwise just try to find config in the current rootDir. | ||
configPath = (0, _resolveConfigPath.default)( | ||
const {config: initialOptions, configPath} = await readInitialOptions( | ||
argv.config, | ||
{ | ||
packageRootOrConfig, | ||
process.cwd(), | ||
parentConfigDirname, | ||
readFromCwd: skipArgvConfigOption, | ||
skipMultipleConfigError | ||
); | ||
rawOptions = await (0, _readConfigFileAndSetRootDir.default)(configPath); | ||
} | ||
} | ||
); | ||
const {options, hasDeprecationWarnings} = await (0, _normalize.default)( | ||
rawOptions, | ||
initialOptions, | ||
argv, | ||
@@ -239,3 +176,2 @@ configPath, | ||
} | ||
const groupOptions = options => ({ | ||
@@ -282,3 +218,5 @@ globalConfig: Object.freeze({ | ||
runTestsByPath: options.runTestsByPath, | ||
seed: options.seed, | ||
shard: options.shard, | ||
showSeed: options.showSeed, | ||
silent: options.silent, | ||
@@ -360,3 +298,2 @@ skipFilter: options.skipFilter, | ||
}); | ||
const ensureNoDuplicateConfigs = (parsedConfigs, projects) => { | ||
@@ -366,8 +303,5 @@ if (projects.length <= 1) { | ||
} | ||
const configPathMap = new Map(); | ||
for (const config of parsedConfigs) { | ||
const {configPath} = config; | ||
if (configPathMap.has(configPath)) { | ||
@@ -391,3 +325,2 @@ const message = `Whoops! Two projects resolved to the same config path: ${_chalk().default.bold( | ||
} | ||
if (configPath !== null) { | ||
@@ -397,3 +330,80 @@ configPathMap.set(configPath, config); | ||
} | ||
}; // Possible scenarios: | ||
}; | ||
/** | ||
* Reads the jest config, without validating them or filling it out with defaults. | ||
* @param config The path to the file or serialized config. | ||
* @param param1 Additional options | ||
* @returns The raw initial config (not validated) | ||
*/ | ||
async function readInitialOptions( | ||
config, | ||
{ | ||
packageRootOrConfig = process.cwd(), | ||
parentConfigDirname = null, | ||
readFromCwd = false, | ||
skipMultipleConfigError = false | ||
} = {} | ||
) { | ||
if (typeof packageRootOrConfig !== 'string') { | ||
if (parentConfigDirname) { | ||
const rawOptions = packageRootOrConfig; | ||
rawOptions.rootDir = rawOptions.rootDir | ||
? (0, _utils.replaceRootDirInPath)( | ||
parentConfigDirname, | ||
rawOptions.rootDir | ||
) | ||
: parentConfigDirname; | ||
return { | ||
config: rawOptions, | ||
configPath: null | ||
}; | ||
} else { | ||
throw new Error( | ||
'Jest: Cannot use configuration as an object without a file path.' | ||
); | ||
} | ||
} | ||
if ((0, _utils.isJSONString)(config)) { | ||
try { | ||
// A JSON string was passed to `--config` argument and we can parse it | ||
// and use as is. | ||
const initialOptions = JSON.parse(config); | ||
// NOTE: we might need to resolve this dir to an absolute path in the future | ||
initialOptions.rootDir = initialOptions.rootDir || packageRootOrConfig; | ||
return { | ||
config: initialOptions, | ||
configPath: null | ||
}; | ||
} catch { | ||
throw new Error( | ||
'There was an error while parsing the `--config` argument as a JSON string.' | ||
); | ||
} | ||
} | ||
if (!readFromCwd && typeof config == 'string') { | ||
// A string passed to `--config`, which is either a direct path to the config | ||
// or a path to directory containing `package.json`, `jest.config.js` or `jest.config.ts` | ||
const configPath = (0, _resolveConfigPath.default)( | ||
config, | ||
process.cwd(), | ||
skipMultipleConfigError | ||
); | ||
return { | ||
config: await (0, _readConfigFileAndSetRootDir.default)(configPath), | ||
configPath | ||
}; | ||
} | ||
// Otherwise just try to find config in the current rootDir. | ||
const configPath = (0, _resolveConfigPath.default)( | ||
packageRootOrConfig, | ||
process.cwd(), | ||
skipMultipleConfigError | ||
); | ||
return { | ||
config: await (0, _readConfigFileAndSetRootDir.default)(configPath), | ||
configPath | ||
}; | ||
} | ||
// Possible scenarios: | ||
// 1. jest --config config.json | ||
@@ -407,3 +417,2 @@ // 2. jest --projects p1 p2 | ||
// (and only) project. | ||
async function readConfigs(argv, projectPaths) { | ||
@@ -415,3 +424,2 @@ let globalConfig; | ||
let configPath; | ||
if (projectPaths.length === 1) { | ||
@@ -423,3 +431,2 @@ const parsedConfig = await readConfig(argv, projects[0]); | ||
configs = [parsedConfig.projectConfig]; | ||
if (globalConfig.projects && globalConfig.projects.length) { | ||
@@ -433,3 +440,2 @@ // Even though we had one project in CLI args, there might be more | ||
} | ||
if (projects.length > 0) { | ||
@@ -453,3 +459,2 @@ const cwd = | ||
} | ||
return true; | ||
@@ -468,3 +473,4 @@ }) | ||
configPath ? path().dirname(configPath) : cwd, | ||
projectIndex, // we wanna skip the warning if this is the "main" project | ||
projectIndex, | ||
// we wanna skip the warning if this is the "main" project | ||
projectIsCwd | ||
@@ -476,3 +482,2 @@ ); | ||
configs = parsedConfigs.map(({projectConfig}) => projectConfig); | ||
if (!hasDeprecationWarnings) { | ||
@@ -482,4 +487,4 @@ hasDeprecationWarnings = parsedConfigs.some( | ||
); | ||
} // If no config was passed initially, use the one from the first project | ||
} | ||
// If no config was passed initially, use the one from the first project | ||
if (!globalConfig) { | ||
@@ -489,7 +494,5 @@ globalConfig = parsedConfigs[0].globalConfig; | ||
} | ||
if (!globalConfig || !configs.length) { | ||
throw new Error('jest: No configuration found for any project.'); | ||
} | ||
return { | ||
@@ -496,0 +499,0 @@ configs, |
@@ -7,151 +7,101 @@ 'use strict'; | ||
exports.default = normalize; | ||
function _crypto() { | ||
const data = require('crypto'); | ||
_crypto = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _os() { | ||
const data = require('os'); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _deepmerge() { | ||
const data = _interopRequireDefault(require('deepmerge')); | ||
_deepmerge = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _glob() { | ||
const data = require('glob'); | ||
_glob = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _gracefulFs() { | ||
const data = require('graceful-fs'); | ||
_gracefulFs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _micromatch() { | ||
const data = _interopRequireDefault(require('micromatch')); | ||
_micromatch = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestRegexUtil() { | ||
const data = require('jest-regex-util'); | ||
_jestRegexUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestResolve() { | ||
const data = _interopRequireWildcard(require('jest-resolve')); | ||
_jestResolve = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestValidate() { | ||
const data = require('jest-validate'); | ||
_jestValidate = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _Defaults = _interopRequireDefault(require('./Defaults')); | ||
var _Deprecated = _interopRequireDefault(require('./Deprecated')); | ||
var _ReporterValidationErrors = require('./ReporterValidationErrors'); | ||
var _ValidConfig = _interopRequireDefault(require('./ValidConfig')); | ||
var _color = require('./color'); | ||
var _constants = require('./constants'); | ||
var _getMaxWorkers = _interopRequireDefault(require('./getMaxWorkers')); | ||
var _parseShardPair = require('./parseShardPair'); | ||
var _setFromArgv = _interopRequireDefault(require('./setFromArgv')); | ||
var _stringToBytes = _interopRequireDefault(require('./stringToBytes')); | ||
var _utils = require('./utils'); | ||
var _validatePattern = _interopRequireDefault(require('./validatePattern')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -165,3 +115,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -199,3 +148,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -207,6 +155,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const ERROR = `${_utils.BULLET}Validation Error`; | ||
const PRESET_EXTENSIONS = ['.json', '.js', '.cjs', '.mjs']; | ||
const PRESET_NAME = 'jest-preset'; | ||
const createConfigError = message => | ||
@@ -218,7 +166,5 @@ new (_jestValidate().ValidationError)( | ||
); | ||
function verifyDirectoryExists(path, key) { | ||
try { | ||
const rootStat = (0, _gracefulFs().statSync)(path); | ||
if (!rootStat.isDirectory()) { | ||
@@ -235,3 +181,2 @@ throw createConfigError( | ||
} | ||
if (err.code === 'ENOENT') { | ||
@@ -243,4 +188,5 @@ throw createConfigError( | ||
); | ||
} // Not sure in which cases `statSync` can throw, so let's just show the underlying error to the user | ||
} | ||
// Not sure in which cases `statSync` can throw, so let's just show the underlying error to the user | ||
throw createConfigError( | ||
@@ -255,3 +201,2 @@ ` Got an error trying to find ${_chalk().default.bold( | ||
} | ||
const mergeOptionWithPreset = (options, preset, optionName) => { | ||
@@ -266,12 +211,10 @@ if (options[optionName] && preset[optionName]) { | ||
}; | ||
const mergeGlobalsWithPreset = (options, preset) => { | ||
if (options['globals'] && preset['globals']) { | ||
options['globals'] = (0, _deepmerge().default)( | ||
preset['globals'], | ||
options['globals'] | ||
if (options.globals && preset.globals) { | ||
options.globals = (0, _deepmerge().default)( | ||
preset.globals, | ||
options.globals | ||
); | ||
} | ||
}; | ||
const setupPreset = async (options, optionsPreset) => { | ||
@@ -283,3 +226,2 @@ let preset; | ||
); | ||
const presetModule = _jestResolve().default.findNodeModule( | ||
@@ -294,12 +236,11 @@ presetPath.startsWith('.') | ||
); | ||
try { | ||
if (!presetModule) { | ||
throw new Error(`Cannot find module '${presetPath}'`); | ||
} // Force re-evaluation to support multiple projects | ||
} | ||
// Force re-evaluation to support multiple projects | ||
try { | ||
delete require.cache[require.resolve(presetModule)]; | ||
} catch {} | ||
preset = await (0, _jestUtil().requireOrImportModule)(presetModule); | ||
@@ -314,3 +255,2 @@ } catch (error) { | ||
} | ||
if (error.message.includes('Cannot find module')) { | ||
@@ -321,3 +261,2 @@ if (error.message.includes(presetPath)) { | ||
}); | ||
if (preset) { | ||
@@ -330,3 +269,2 @@ throw createConfigError( | ||
} | ||
throw createConfigError( | ||
@@ -336,3 +274,2 @@ ` Preset ${_chalk().default.bold(presetPath)} not found.` | ||
} | ||
throw createConfigError( | ||
@@ -344,3 +281,2 @@ ` Missing dependency in ${_chalk().default.bold(presetPath)}:\n\n ${ | ||
} | ||
throw createConfigError( | ||
@@ -352,7 +288,5 @@ ` An unknown error occurred in ${_chalk().default.bold( | ||
} | ||
if (options.setupFiles) { | ||
options.setupFiles = (preset.setupFiles || []).concat(options.setupFiles); | ||
} | ||
if (options.setupFilesAfterEnv) { | ||
@@ -363,3 +297,2 @@ options.setupFilesAfterEnv = (preset.setupFilesAfterEnv || []).concat( | ||
} | ||
if (options.modulePathIgnorePatterns && preset.modulePathIgnorePatterns) { | ||
@@ -370,13 +303,13 @@ options.modulePathIgnorePatterns = preset.modulePathIgnorePatterns.concat( | ||
} | ||
mergeOptionWithPreset(options, preset, 'moduleNameMapper'); | ||
mergeOptionWithPreset(options, preset, 'transform'); | ||
mergeGlobalsWithPreset(options, preset); | ||
return {...preset, ...options}; | ||
return { | ||
...preset, | ||
...options | ||
}; | ||
}; | ||
const setupBabelJest = options => { | ||
const transform = options.transform; | ||
let babelJest; | ||
if (transform) { | ||
@@ -394,3 +327,2 @@ const customJSPattern = Object.keys(transform).find(pattern => { | ||
const customTransformer = transform[pattern]; | ||
if (Array.isArray(customTransformer)) { | ||
@@ -420,11 +352,8 @@ if (customTransformer[0] === 'babel-jest') { | ||
}; | ||
const normalizeCollectCoverageFrom = (options, key) => { | ||
const initialCollectCoverageFrom = options[key]; | ||
let value; | ||
if (!initialCollectCoverageFrom) { | ||
value = []; | ||
} | ||
if (!Array.isArray(initialCollectCoverageFrom)) { | ||
@@ -434,3 +363,2 @@ try { | ||
} catch {} | ||
if (options[key] && !Array.isArray(value)) { | ||
@@ -442,3 +370,2 @@ value = [initialCollectCoverageFrom]; | ||
} | ||
if (value) { | ||
@@ -449,10 +376,6 @@ value = value.map(filePath => | ||
} | ||
return value; | ||
}; | ||
const normalizeUnmockedModulePathPatterns = ( | ||
options, | ||
key // _replaceRootDirTags is specifically well-suited for substituting | ||
) => | ||
const normalizeUnmockedModulePathPatterns = (options, key) => | ||
// _replaceRootDirTags is specifically well-suited for substituting | ||
// <rootDir> in paths (it deals with properly interpreting relative path | ||
@@ -468,7 +391,7 @@ // separators, etc). | ||
); | ||
const normalizeMissingOptions = (options, configPath, projectIndex) => { | ||
if (!options.id) { | ||
options.id = (0, _crypto().createHash)('sha256') | ||
.update(options.rootDir) // In case we load config from some path that has the same root dir | ||
.update(options.rootDir) | ||
// In case we load config from some path that has the same root dir | ||
.update(configPath || '') | ||
@@ -479,10 +402,7 @@ .update(String(projectIndex)) | ||
} | ||
if (!options.setupFiles) { | ||
options.setupFiles = []; | ||
} | ||
return options; | ||
}; | ||
const normalizeRootDir = options => { | ||
@@ -497,5 +417,3 @@ // Assert that there *is* a rootDir | ||
} | ||
options.rootDir = path().normalize(options.rootDir); | ||
try { | ||
@@ -507,7 +425,8 @@ // try to resolve windows short paths, ignoring errors (permission errors, mostly) | ||
} | ||
verifyDirectoryExists(options.rootDir, 'rootDir'); | ||
return {...options, rootDir: options.rootDir}; | ||
return { | ||
...options, | ||
rootDir: options.rootDir | ||
}; | ||
}; | ||
const normalizeReporters = ({reporters, rootDir}) => { | ||
@@ -517,8 +436,8 @@ if (!reporters || !Array.isArray(reporters)) { | ||
} | ||
(0, _ReporterValidationErrors.validateReporters)(reporters); | ||
return reporters.map(reporterConfig => { | ||
const normalizedReporterConfig = | ||
typeof reporterConfig === 'string' // if reporter config is a string, we wrap it in an array | ||
? // and pass an empty object for options argument, to normalize | ||
typeof reporterConfig === 'string' | ||
? // if reporter config is a string, we wrap it in an array | ||
// and pass an empty object for options argument, to normalize | ||
// the shape. | ||
@@ -531,3 +450,2 @@ [reporterConfig, {}] | ||
); | ||
if (!['default', 'github-actions', 'summary'].includes(reporterPath)) { | ||
@@ -537,3 +455,2 @@ const reporter = _jestResolve().default.findNodeModule(reporterPath, { | ||
}); | ||
if (!reporter) { | ||
@@ -545,34 +462,24 @@ throw new (_jestResolve().default.ModuleNotFoundError)( | ||
} | ||
normalizedReporterConfig[0] = reporter; | ||
} | ||
return normalizedReporterConfig; | ||
}); | ||
}; | ||
const buildTestPathPattern = argv => { | ||
const patterns = []; | ||
if (argv._) { | ||
patterns.push(...argv._); | ||
} | ||
if (argv.testPathPattern) { | ||
patterns.push(...argv.testPathPattern); | ||
} | ||
const replacePosixSep = pattern => { | ||
// yargs coerces positional args into numbers | ||
const patternAsString = pattern.toString(); | ||
if (path().sep === '/') { | ||
return patternAsString; | ||
} | ||
return patternAsString.replace(/\//g, '\\\\'); | ||
}; | ||
const testPathPattern = patterns.map(replacePosixSep).join('|'); | ||
if ((0, _validatePattern.default)(testPathPattern)) { | ||
@@ -585,6 +492,6 @@ return testPathPattern; | ||
}; | ||
const showTestPathPatternError = testPathPattern => { | ||
(0, _jestUtil().clearLine)(process.stdout); // eslint-disable-next-line no-console | ||
(0, _jestUtil().clearLine)(process.stdout); | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
@@ -597,3 +504,2 @@ _chalk().default.red( | ||
}; | ||
function validateExtensionsToTreatAsEsm(extensionsToTreatAsEsm) { | ||
@@ -603,3 +509,2 @@ if (!extensionsToTreatAsEsm || extensionsToTreatAsEsm.length === 0) { | ||
} | ||
function printConfig(opts) { | ||
@@ -609,7 +514,5 @@ const string = opts.map(ext => `'${ext}'`).join(', '); | ||
} | ||
const extensionWithoutDot = extensionsToTreatAsEsm.some( | ||
ext => !ext.startsWith('.') | ||
); | ||
if (extensionWithoutDot) { | ||
@@ -625,3 +528,2 @@ throw createConfigError(` Option: ${printConfig( | ||
} | ||
if (extensionsToTreatAsEsm.includes('.js')) { | ||
@@ -638,3 +540,2 @@ throw createConfigError( | ||
} | ||
if (extensionsToTreatAsEsm.includes('.cjs')) { | ||
@@ -649,3 +550,2 @@ throw createConfigError( | ||
} | ||
if (extensionsToTreatAsEsm.includes('.mjs')) { | ||
@@ -661,3 +561,2 @@ throw createConfigError( | ||
} | ||
async function normalize( | ||
@@ -691,11 +590,8 @@ initialOptions, | ||
); | ||
if (options.preset) { | ||
options = await setupPreset(options, options.preset); | ||
} | ||
if (!options.setupFilesAfterEnv) { | ||
options.setupFilesAfterEnv = []; | ||
} | ||
options.testEnvironment = (0, _jestResolve().resolveTestEnvironment)({ | ||
@@ -708,7 +604,5 @@ requireResolveFunction: require.resolve, | ||
}); | ||
if (!options.roots) { | ||
options.roots = [options.rootDir]; | ||
} | ||
if ( | ||
@@ -730,15 +624,13 @@ !options.testRunner || | ||
} | ||
throw error; | ||
} | ||
} | ||
if (!options.coverageDirectory) { | ||
options.coverageDirectory = path().resolve(options.rootDir, 'coverage'); | ||
} | ||
setupBabelJest(options); // TODO: Type this properly | ||
const newOptions = {..._Defaults.default}; | ||
setupBabelJest(options); | ||
// TODO: Type this properly | ||
const newOptions = { | ||
..._Defaults.default | ||
}; | ||
if (options.resolver) { | ||
@@ -751,9 +643,6 @@ newOptions.resolver = (0, _utils.resolve)(null, { | ||
} | ||
validateExtensionsToTreatAsEsm(options.extensionsToTreatAsEsm); | ||
if (options.watchman == null) { | ||
options.watchman = _Defaults.default.watchman; | ||
} | ||
const optionKeys = Object.keys(options); | ||
@@ -764,9 +653,9 @@ optionKeys.reduce((newOptions, key) => { | ||
return newOptions; | ||
} // This is cheating, because it claims that all keys of InitialOptions are Required. | ||
} | ||
// This is cheating, because it claims that all keys of InitialOptions are Required. | ||
// We only really know it's Required for oldOptions[key], not for oldOptions.someOtherKey, | ||
// so oldOptions[key] is the only way it should be used. | ||
const oldOptions = options; | ||
let value; | ||
switch (key) { | ||
@@ -789,3 +678,2 @@ case 'setupFiles': | ||
break; | ||
case 'modulePaths': | ||
@@ -805,7 +693,5 @@ case 'roots': | ||
break; | ||
case 'collectCoverageFrom': | ||
value = normalizeCollectCoverageFrom(oldOptions, key); | ||
break; | ||
case 'cacheDirectory': | ||
@@ -823,3 +709,2 @@ case 'coverageDirectory': | ||
break; | ||
case 'dependencyExtractor': | ||
@@ -844,3 +729,2 @@ case 'globalSetup': | ||
break; | ||
case 'runner': | ||
@@ -858,3 +742,2 @@ { | ||
break; | ||
case 'prettierPath': | ||
@@ -865,2 +748,3 @@ { | ||
// set it to null and throw an error lazily when it is used. | ||
const option = oldOptions[key]; | ||
@@ -877,3 +761,2 @@ value = | ||
break; | ||
case 'moduleNameMapper': | ||
@@ -893,3 +776,2 @@ const moduleNameMapper = oldOptions[key]; | ||
break; | ||
case 'transform': | ||
@@ -914,7 +796,5 @@ const transform = oldOptions[key]; | ||
break; | ||
case 'reporters': | ||
value = normalizeReporters(oldOptions); | ||
break; | ||
case 'coveragePathIgnorePatterns': | ||
@@ -928,6 +808,6 @@ case 'modulePathIgnorePatterns': | ||
break; | ||
case 'haste': | ||
value = {...oldOptions[key]}; | ||
value = { | ||
...oldOptions[key] | ||
}; | ||
if (value.hasteImplModulePath != null) { | ||
@@ -944,5 +824,3 @@ const resolvedHasteImpl = (0, _utils.resolve)(newOptions.resolver, { | ||
} | ||
break; | ||
case 'projects': | ||
@@ -964,3 +842,2 @@ value = (oldOptions[key] || []) | ||
break; | ||
case 'moduleDirectories': | ||
@@ -973,3 +850,2 @@ case 'testMatch': | ||
); | ||
if (replacedRootDirTags) { | ||
@@ -984,3 +860,2 @@ value = Array.isArray(replacedRootDirTags) | ||
break; | ||
case 'testRegex': | ||
@@ -996,10 +871,10 @@ { | ||
break; | ||
case 'moduleFileExtensions': { | ||
value = oldOptions[key]; | ||
if ( | ||
Array.isArray(value) && // If it's the wrong type, it can throw at a later time | ||
Array.isArray(value) && | ||
// If it's the wrong type, it can throw at a later time | ||
(options.runner === undefined || | ||
options.runner === _Defaults.default.runner) && // Only require 'js' for the default jest-runner | ||
options.runner === _Defaults.default.runner) && | ||
// Only require 'js' for the default jest-runner | ||
!value.includes('js') | ||
@@ -1010,3 +885,5 @@ ) { | ||
' but instead received:\n' + | ||
` ${_chalk().default.bold.red(JSON.stringify(value))}`; // If `js` is not included, any dependency Jest itself injects into | ||
` ${_chalk().default.bold.red(JSON.stringify(value))}`; | ||
// If `js` is not included, any dependency Jest itself injects into | ||
// the environment, like jasmine or sourcemap-support, will need to | ||
@@ -1019,3 +896,2 @@ // `require` its modules with a file extension. This is not plausible | ||
// works in Node normally. | ||
throw createConfigError( | ||
@@ -1025,16 +901,13 @@ `${errorMessage}\n Please change your configuration to include 'js'.` | ||
} | ||
break; | ||
} | ||
case 'bail': { | ||
const bail = oldOptions[key]; | ||
if (typeof bail === 'boolean') { | ||
value = bail ? 1 : 0; | ||
} else if (typeof bail === 'string') { | ||
value = 1; // If Jest is invoked as `jest --bail someTestPattern` then need to | ||
value = 1; | ||
// If Jest is invoked as `jest --bail someTestPattern` then need to | ||
// move the pattern from the `bail` configuration and into `argv._` | ||
// to be processed as an extra parameter | ||
argv._.push(bail); | ||
@@ -1044,6 +917,4 @@ } else { | ||
} | ||
break; | ||
} | ||
case 'displayName': { | ||
@@ -1055,6 +926,4 @@ const displayName = oldOptions[key]; | ||
*/ | ||
if (typeof displayName === 'object') { | ||
const {name, color} = displayName; | ||
if ( | ||
@@ -1076,3 +945,2 @@ !name || | ||
} | ||
value = oldOptions[key]; | ||
@@ -1085,6 +953,4 @@ } else { | ||
} | ||
break; | ||
} | ||
case 'testTimeout': { | ||
@@ -1098,12 +964,12 @@ if (oldOptions[key] < 0) { | ||
} | ||
value = oldOptions[key]; | ||
break; | ||
} | ||
case 'snapshotFormat': { | ||
value = {..._Defaults.default.snapshotFormat, ...oldOptions[key]}; | ||
value = { | ||
..._Defaults.default.snapshotFormat, | ||
...oldOptions[key] | ||
}; | ||
break; | ||
} | ||
case 'automock': | ||
@@ -1149,2 +1015,3 @@ case 'cache': | ||
case 'silent': | ||
case 'showSeed': | ||
case 'skipFilter': | ||
@@ -1165,3 +1032,2 @@ case 'skipNodeResolution': | ||
break; | ||
case 'workerIdleMemoryLimit': | ||
@@ -1173,3 +1039,2 @@ value = (0, _stringToBytes.default)( | ||
break; | ||
case 'watchPlugins': | ||
@@ -1204,8 +1069,7 @@ value = (oldOptions[key] || []).map(watchPlugin => { | ||
break; | ||
} // @ts-expect-error: automock is missing in GlobalConfig, so what | ||
} | ||
// @ts-expect-error: automock is missing in GlobalConfig, so what | ||
newOptions[key] = value; | ||
return newOptions; | ||
}, newOptions); | ||
if (options.watchman && options.haste?.enableSymlinks) { | ||
@@ -1218,7 +1082,5 @@ throw new (_jestValidate().ValidationError)( | ||
} | ||
newOptions.roots.forEach((root, i) => { | ||
verifyDirectoryExists(root, `roots[${i}]`); | ||
}); | ||
try { | ||
@@ -1230,3 +1092,2 @@ // try to resolve windows short paths, ignoring errors (permission errors, mostly) | ||
} | ||
newOptions.testSequencer = (0, _jestResolve().resolveSequencer)( | ||
@@ -1242,7 +1103,5 @@ newOptions.resolver, | ||
); | ||
if (newOptions.runner === _Defaults.default.runner) { | ||
newOptions.runner = require.resolve(newOptions.runner); | ||
} | ||
newOptions.nonFlagArgs = argv._?.map(arg => `${arg}`); | ||
@@ -1252,3 +1111,2 @@ newOptions.testPathPattern = buildTestPathPattern(argv); | ||
newOptions.testFailureExitCode = parseInt(newOptions.testFailureExitCode, 10); | ||
if ( | ||
@@ -1261,3 +1119,2 @@ newOptions.lastCommit || | ||
} | ||
if (argv.all) { | ||
@@ -1271,27 +1128,38 @@ newOptions.onlyChanged = false; | ||
} | ||
newOptions.showSeed = newOptions.showSeed || argv.showSeed; | ||
const upperBoundSeedValue = 2 ** 31; | ||
// xoroshiro128plus is used in v8 and is used here (at time of writing) | ||
newOptions.seed = | ||
argv.seed ?? | ||
Math.floor((2 ** 32 - 1) * Math.random() - upperBoundSeedValue); | ||
if ( | ||
newOptions.seed < -upperBoundSeedValue || | ||
newOptions.seed > upperBoundSeedValue - 1 | ||
) { | ||
throw new (_jestValidate().ValidationError)( | ||
'Validation Error', | ||
`seed value must be between \`-0x80000000\` and \`0x7fffffff\` inclusive - is ${newOptions.seed}` | ||
); | ||
} | ||
if (!newOptions.onlyChanged) { | ||
newOptions.onlyChanged = false; | ||
} | ||
if (!newOptions.lastCommit) { | ||
newOptions.lastCommit = false; | ||
} | ||
if (!newOptions.onlyFailures) { | ||
newOptions.onlyFailures = false; | ||
} | ||
if (!newOptions.watchAll) { | ||
newOptions.watchAll = false; | ||
} // as unknown since it can happen. We really need to fix the types here | ||
} | ||
// as unknown since it can happen. We really need to fix the types here | ||
if (newOptions.moduleNameMapper === _Defaults.default.moduleNameMapper) { | ||
newOptions.moduleNameMapper = []; | ||
} | ||
if (argv.ci != null) { | ||
newOptions.ci = argv.ci; | ||
} | ||
newOptions.updateSnapshot = | ||
@@ -1305,4 +1173,3 @@ newOptions.ci && !argv.updateSnapshot | ||
newOptions.maxWorkers = (0, _getMaxWorkers.default)(argv, options); | ||
if (newOptions.testRegex.length && options.testMatch) { | ||
if (newOptions.testRegex.length > 0 && options.testMatch) { | ||
throw createConfigError( | ||
@@ -1313,9 +1180,9 @@ ` Configuration options ${_chalk().default.bold('testMatch')} and` + | ||
} | ||
if (newOptions.testRegex.length && !options.testMatch) { | ||
if (newOptions.testRegex.length > 0 && !options.testMatch) { | ||
// Prevent the default testMatch conflicting with any explicitly | ||
// configured `testRegex` value | ||
newOptions.testMatch = []; | ||
} // If argv.json is set, coverageReporters shouldn't print a text report. | ||
} | ||
// If argv.json is set, coverageReporters shouldn't print a text report. | ||
if (argv.json) { | ||
@@ -1325,3 +1192,5 @@ newOptions.coverageReporters = (newOptions.coverageReporters || []).filter( | ||
); | ||
} // If collectCoverage is enabled while using --findRelatedTests we need to | ||
} | ||
// If collectCoverage is enabled while using --findRelatedTests we need to | ||
// avoid having false negatives in the generated coverage report. | ||
@@ -1332,3 +1201,2 @@ // The following: `--findRelatedTests '/rootDir/file1.js' --coverage` | ||
// paths to the rootDir) | ||
if (newOptions.collectCoverage && argv.findRelatedTests) { | ||
@@ -1340,4 +1208,5 @@ let collectCoverageFrom = newOptions.nonFlagArgs.map(filename => { | ||
: filename; | ||
}); // Don't override existing collectCoverageFrom options | ||
}); | ||
// Don't override existing collectCoverageFrom options | ||
if (newOptions.collectCoverageFrom) { | ||
@@ -1357,7 +1226,5 @@ collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => { | ||
} | ||
return [...patterns, filename]; | ||
}, newOptions.collectCoverageFrom); | ||
} | ||
newOptions.collectCoverageFrom = collectCoverageFrom; | ||
@@ -1367,27 +1234,20 @@ } else if (!newOptions.collectCoverageFrom) { | ||
} | ||
if (!newOptions.findRelatedTests) { | ||
newOptions.findRelatedTests = false; | ||
} | ||
if (!newOptions.projects) { | ||
newOptions.projects = []; | ||
} | ||
if (!newOptions.sandboxInjectedGlobals) { | ||
newOptions.sandboxInjectedGlobals = []; | ||
} | ||
if (!newOptions.forceExit) { | ||
newOptions.forceExit = false; | ||
} | ||
if (!newOptions.logHeapUsage) { | ||
newOptions.logHeapUsage = false; | ||
} | ||
if (argv.shard) { | ||
newOptions.shard = (0, _parseShardPair.parseShardPair)(argv.shard); | ||
} | ||
return { | ||
@@ -1394,0 +1254,0 @@ hasDeprecationWarnings, |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.parseShardPair = void 0; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const parseShardPair = pair => { | ||
@@ -23,3 +23,2 @@ const shardPair = pair | ||
const [shardIndex, shardCount] = shardPair; | ||
if (shardPair.length !== 2) { | ||
@@ -30,3 +29,2 @@ throw new Error( | ||
} | ||
if (shardIndex === 0 || shardCount === 0) { | ||
@@ -37,3 +35,2 @@ throw new Error( | ||
} | ||
if (shardIndex > shardCount) { | ||
@@ -44,3 +41,2 @@ throw new Error( | ||
} | ||
return { | ||
@@ -51,3 +47,2 @@ shardCount, | ||
}; | ||
exports.parseShardPair = parseShardPair; |
@@ -7,59 +7,41 @@ 'use strict'; | ||
exports.default = readConfigFileAndSetRootDir; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _parseJson() { | ||
const data = _interopRequireDefault(require('parse-json')); | ||
_parseJson = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _stripJsonComments() { | ||
const data = _interopRequireDefault(require('strip-json-comments')); | ||
_stripJsonComments = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -73,3 +55,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -107,3 +88,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -115,2 +95,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// Read the configuration and set its `rootDir` | ||
@@ -125,3 +106,2 @@ // 1. If it's a `package.json` file, we look into its "jest" property | ||
let configObject; | ||
try { | ||
@@ -146,6 +126,4 @@ if (isTS) { | ||
} | ||
throw error; | ||
} | ||
if (configPath.endsWith(_constants.PACKAGE_JSON)) { | ||
@@ -156,7 +134,5 @@ // Event if there's no "jest" property in package.json we will still use | ||
} | ||
if (typeof configObject === 'function') { | ||
configObject = await configObject(); | ||
} | ||
if (configObject.rootDir) { | ||
@@ -175,6 +151,6 @@ // We don't touch it if it has an absolute path specified | ||
} | ||
return configObject; | ||
} // Load the TypeScript configuration | ||
} | ||
// Load the TypeScript configuration | ||
const loadTSConfigFile = async configPath => { | ||
@@ -186,14 +162,12 @@ // Get registered TypeScript compiler instance | ||
require(configPath) | ||
).default; // In case the config is a function which imports more Typescript code | ||
).default; | ||
// In case the config is a function which imports more Typescript code | ||
if (typeof configObject === 'function') { | ||
configObject = await configObject(); | ||
} | ||
registeredCompiler.enabled(false); | ||
return configObject; | ||
}; | ||
let registeredCompilerPromise; | ||
function getRegisteredCompiler() { | ||
@@ -204,3 +178,2 @@ // Cache the promise to avoid multiple registrations | ||
} | ||
async function registerTsNode() { | ||
@@ -224,5 +197,4 @@ try { | ||
} | ||
throw e; | ||
} | ||
} |
@@ -9,39 +9,27 @@ 'use strict'; | ||
exports.validateReporters = validateReporters; | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestGetType() { | ||
const data = require('jest-get-type'); | ||
_jestGetType = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestValidate() { | ||
const data = require('jest-validate'); | ||
_jestValidate = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -53,4 +41,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const validReporterTypes = ['array', 'string']; | ||
const ERROR = `${_utils.BULLET}Reporter Validation Error`; | ||
/** | ||
@@ -64,3 +54,2 @@ * Reporter Validation Error is thrown if the given arguments | ||
*/ | ||
function createReporterError(reporterIndex, reporterValue) { | ||
@@ -80,3 +69,2 @@ const errorMessage = | ||
} | ||
function createArrayReporterError( | ||
@@ -107,3 +95,2 @@ arrayReporter, | ||
} | ||
function validateReporters(reporterConfig) { | ||
@@ -116,10 +103,7 @@ return reporterConfig.every((reporter, index) => { | ||
} | ||
return true; | ||
}); | ||
} | ||
function validateArrayReporter(arrayReporter, reporterIndex) { | ||
const [path, options] = arrayReporter; | ||
if (typeof path !== 'string') { | ||
@@ -126,0 +110,0 @@ throw createArrayReporterError( |
@@ -7,61 +7,42 @@ 'use strict'; | ||
exports.default = resolveConfigPath; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _slash() { | ||
const data = _interopRequireDefault(require('slash')); | ||
_slash = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestValidate() { | ||
const data = require('jest-validate'); | ||
_jestValidate = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = require('./constants'); | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -75,3 +56,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -109,3 +89,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -117,7 +96,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const isFile = filePath => | ||
fs().existsSync(filePath) && !fs().lstatSync(filePath).isDirectory(); | ||
const getConfigFilename = ext => _constants.JEST_CONFIG_BASE_NAME + ext; | ||
function resolveConfigPath( | ||
@@ -131,10 +109,10 @@ pathToResolve, | ||
} | ||
const absolutePath = path().isAbsolute(pathToResolve) | ||
? pathToResolve | ||
: path().resolve(cwd, pathToResolve); | ||
if (isFile(absolutePath)) { | ||
return absolutePath; | ||
} // This is a guard against passing non existing path as a project/config, | ||
} | ||
// This is a guard against passing non existing path as a project/config, | ||
// that will otherwise result in a very confusing situation. | ||
@@ -149,3 +127,2 @@ // e.g. | ||
// try to run all tests it finds under `my_project` directory. | ||
if (!fs().existsSync(absolutePath)) { | ||
@@ -158,3 +135,2 @@ throw new Error( | ||
} | ||
return resolveConfigPathByTraversing( | ||
@@ -167,3 +143,2 @@ absolutePath, | ||
} | ||
const resolveConfigPathByTraversing = ( | ||
@@ -178,9 +153,6 @@ pathToResolve, | ||
).filter(isFile); | ||
const packageJson = findPackageJson(pathToResolve); | ||
if (packageJson && hasPackageJsonJestKey(packageJson)) { | ||
configFiles.push(packageJson); | ||
} | ||
if (!skipMultipleConfigError && configFiles.length > 1) { | ||
@@ -191,12 +163,13 @@ throw new (_jestValidate().ValidationError)( | ||
} | ||
if (configFiles.length > 0 || packageJson) { | ||
return configFiles[0] ?? packageJson; | ||
} // This is the system root. | ||
} | ||
// This is the system root. | ||
// We tried everything, config is nowhere to be found ¯\_(ツ)_/¯ | ||
if (pathToResolve === path().dirname(pathToResolve)) { | ||
throw new Error(makeResolutionErrorMessage(initialPath, cwd)); | ||
} // go up a level and try it again | ||
} | ||
// go up a level and try it again | ||
return resolveConfigPathByTraversing( | ||
@@ -209,16 +182,11 @@ path().dirname(pathToResolve), | ||
}; | ||
const findPackageJson = pathToResolve => { | ||
const packagePath = path().resolve(pathToResolve, _constants.PACKAGE_JSON); | ||
if (isFile(packagePath)) { | ||
return packagePath; | ||
} | ||
return undefined; | ||
}; | ||
const hasPackageJsonJestKey = packagePath => { | ||
const content = fs().readFileSync(packagePath, 'utf8'); | ||
try { | ||
@@ -231,3 +199,2 @@ return 'jest' in JSON.parse(content); | ||
}; | ||
const makeResolutionErrorMessage = (initialPath, cwd) => | ||
@@ -242,3 +209,2 @@ 'Could not find a config file based on provided values:\n' + | ||
).join(' or ')}.`; | ||
function extraIfPackageJson(configPath) { | ||
@@ -248,6 +214,4 @@ if (configPath.endsWith(_constants.PACKAGE_JSON)) { | ||
} | ||
return ''; | ||
} | ||
const makeMultipleConfigsErrorMessage = configPaths => [ | ||
@@ -254,0 +218,0 @@ `${_utils.BULLET}${_chalk().default.bold('Multiple configurations found')}`, |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.default = setFromArgv; | ||
var _utils = require('./utils'); | ||
/** | ||
@@ -17,4 +15,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const specialArgs = ['_', '$0', 'h', 'help', 'config']; | ||
function setFromArgv(options, argv) { | ||
@@ -28,7 +26,5 @@ const argvToOptions = Object.keys(argv) | ||
break; | ||
case 'json': | ||
options.useStderr = argv[key]; | ||
break; | ||
case 'watchAll': | ||
@@ -38,10 +34,7 @@ options.watch = false; | ||
break; | ||
case 'env': | ||
options.testEnvironment = argv[key]; | ||
break; | ||
case 'config': | ||
break; | ||
case 'coverageThreshold': | ||
@@ -54,13 +47,9 @@ case 'globals': | ||
const str = argv[key]; | ||
if ((0, _utils.isJSONString)(str)) { | ||
options[key] = JSON.parse(str); | ||
} | ||
break; | ||
default: | ||
options[key] = argv[key]; | ||
} | ||
return options; | ||
@@ -67,0 +56,0 @@ }, {}); |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = void 0; | ||
/** | ||
@@ -26,3 +25,2 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
} | ||
if (typeof input === 'string') { | ||
@@ -33,7 +31,5 @@ if (isNaN(Number.parseFloat(input.slice(-1)))) { | ||
input.match(/(.*?)([^0-9.-]+)$/i) || []; | ||
if (trailingChars && numericString) { | ||
const numericValue = Number.parseFloat(numericString); | ||
trailingChars = trailingChars.toLowerCase(); | ||
switch (trailingChars) { | ||
@@ -43,25 +39,21 @@ case '%': | ||
break; | ||
case 'kb': | ||
case 'k': | ||
return numericValue * 1000; | ||
case 'kib': | ||
return numericValue * 1024; | ||
case 'mb': | ||
case 'm': | ||
return numericValue * 1000 * 1000; | ||
case 'mib': | ||
return numericValue * 1024 * 1024; | ||
case 'gb': | ||
case 'g': | ||
return numericValue * 1000 * 1000 * 1000; | ||
case 'gib': | ||
return numericValue * 1024 * 1024 * 1024; | ||
} | ||
} // It ends in some kind of char so we need to do some parsing | ||
} | ||
// It ends in some kind of char so we need to do some parsing | ||
} else { | ||
@@ -71,3 +63,2 @@ input = Number.parseFloat(input); | ||
} | ||
if (typeof input === 'number') { | ||
@@ -88,7 +79,7 @@ if (input <= 1 && input > 0) { | ||
} | ||
throw new Error('Unexpected input'); | ||
} // https://github.com/import-js/eslint-plugin-import/issues/1590 | ||
} | ||
// https://github.com/import-js/eslint-plugin-import/issues/1590 | ||
var _default = stringToBytes; | ||
exports.default = _default; |
@@ -14,47 +14,33 @@ 'use strict'; | ||
void 0; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _chalk() { | ||
const data = _interopRequireDefault(require('chalk')); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestResolve() { | ||
const data = _interopRequireDefault(require('jest-resolve')); | ||
_jestResolve = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestValidate() { | ||
const data = require('jest-validate'); | ||
_jestValidate = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -68,3 +54,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -102,3 +87,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -110,4 +94,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const BULLET = _chalk().default.bold('\u25cf '); | ||
exports.BULLET = BULLET; | ||
@@ -120,3 +104,2 @@ const DOCUMENTATION_NOTE = ` ${_chalk().default.bold( | ||
exports.DOCUMENTATION_NOTE = DOCUMENTATION_NOTE; | ||
const createValidationError = message => | ||
@@ -128,3 +111,2 @@ new (_jestValidate().ValidationError)( | ||
); | ||
const resolve = (resolver, {key, filePath, rootDir, optional}) => { | ||
@@ -138,3 +120,2 @@ const module = _jestResolve().default.findNodeModule( | ||
); | ||
if (!module && !optional) { | ||
@@ -145,13 +126,9 @@ throw createValidationError(` Module ${_chalk().default.bold( | ||
${_chalk().default.bold('<rootDir>')} is: ${rootDir}`); | ||
} /// can cast as string since nulls will be thrown | ||
} | ||
/// can cast as string since nulls will be thrown | ||
return module; | ||
}; | ||
exports.resolve = resolve; | ||
const escapeGlobCharacters = path => path.replace(/([()*{}[\]!?\\])/g, '\\$1'); | ||
exports.escapeGlobCharacters = escapeGlobCharacters; | ||
const replaceRootDirInPath = (rootDir, filePath) => { | ||
@@ -161,3 +138,2 @@ if (!/^<rootDir>/.test(filePath)) { | ||
} | ||
return path().resolve( | ||
@@ -168,8 +144,5 @@ rootDir, | ||
}; | ||
exports.replaceRootDirInPath = replaceRootDirInPath; | ||
const _replaceRootDirInObject = (rootDir, config) => { | ||
const newConfig = {}; | ||
for (const configKey in config) { | ||
@@ -181,6 +154,4 @@ newConfig[configKey] = | ||
} | ||
return newConfig; | ||
}; | ||
const _replaceRootDirTags = (rootDir, config) => { | ||
@@ -190,3 +161,2 @@ if (config == null) { | ||
} | ||
switch (typeof config) { | ||
@@ -198,18 +168,12 @@ case 'object': | ||
} | ||
if (config instanceof RegExp) { | ||
return config; | ||
} | ||
return _replaceRootDirInObject(rootDir, config); | ||
case 'string': | ||
return replaceRootDirInPath(rootDir, config); | ||
} | ||
return config; | ||
}; | ||
exports._replaceRootDirTags = _replaceRootDirTags; | ||
// newtype | ||
@@ -221,3 +185,2 @@ const isJSONString = text => | ||
text.endsWith('}'); | ||
exports.isJSONString = isJSONString; |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = validatePattern; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
function validatePattern(pattern) { | ||
@@ -25,4 +25,3 @@ if (pattern) { | ||
} | ||
return true; | ||
} |
@@ -7,35 +7,24 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _jestRegexUtil() { | ||
const data = require('jest-regex-util'); | ||
_jestRegexUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestValidate() { | ||
const data = require('jest-validate'); | ||
_jestValidate = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _prettyFormat() { | ||
const data = require('pretty-format'); | ||
_prettyFormat = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = require('./constants'); | ||
/** | ||
@@ -47,2 +36,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const NODE_MODULES_REGEXP = (0, _jestRegexUtil().replacePathSepForRegex)( | ||
@@ -182,2 +172,3 @@ _constants.NODE_MODULES | ||
setupFilesAfterEnv: ['<rootDir>/testSetupFile.js'], | ||
showSeed: false, | ||
silent: true, | ||
@@ -184,0 +175,0 @@ skipFilter: false, |
{ | ||
"name": "jest-config", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -33,5 +33,5 @@ "type": "git", | ||
"@babel/core": "^7.11.6", | ||
"@jest/test-sequencer": "^29.1.2", | ||
"@jest/types": "^29.1.2", | ||
"babel-jest": "^29.1.2", | ||
"@jest/test-sequencer": "^29.2.0", | ||
"@jest/types": "^29.2.0", | ||
"babel-jest": "^29.2.0", | ||
"chalk": "^4.0.0", | ||
@@ -42,13 +42,13 @@ "ci-info": "^3.2.0", | ||
"graceful-fs": "^4.2.9", | ||
"jest-circus": "^29.1.2", | ||
"jest-environment-node": "^29.1.2", | ||
"jest-get-type": "^29.0.0", | ||
"jest-regex-util": "^29.0.0", | ||
"jest-resolve": "^29.1.2", | ||
"jest-runner": "^29.1.2", | ||
"jest-util": "^29.1.2", | ||
"jest-validate": "^29.1.2", | ||
"jest-circus": "^29.2.0", | ||
"jest-environment-node": "^29.2.0", | ||
"jest-get-type": "^29.2.0", | ||
"jest-regex-util": "^29.2.0", | ||
"jest-resolve": "^29.2.0", | ||
"jest-runner": "^29.2.0", | ||
"jest-util": "^29.2.0", | ||
"jest-validate": "^29.2.0", | ||
"micromatch": "^4.0.4", | ||
"parse-json": "^5.2.0", | ||
"pretty-format": "^29.1.2", | ||
"pretty-format": "^29.2.0", | ||
"slash": "^3.0.0", | ||
@@ -71,3 +71,3 @@ "strip-json-comments": "^3.1.1" | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
110053
3416
Updated@jest/test-sequencer@^29.2.0
Updated@jest/types@^29.2.0
Updatedbabel-jest@^29.2.0
Updatedjest-circus@^29.2.0
Updatedjest-get-type@^29.2.0
Updatedjest-regex-util@^29.2.0
Updatedjest-resolve@^29.2.0
Updatedjest-runner@^29.2.0
Updatedjest-util@^29.2.0
Updatedjest-validate@^29.2.0
Updatedpretty-format@^29.2.0