Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
argv: Arguments,
): null | JestConfigNormalize {
/* tslint:disable */
const R_OK = (fs.constants && fs.constants.R_OK) || (fs['R_OK'] as number);
/* tslint:enable */
try {
fs.accessSync(filePath, R_OK);
} catch (e) {
return null;
}
const packageData = require(filePath);
const config = packageData.jest || {};
const root = path.dirname(filePath);
config.rootDir = config.rootDir ? path.resolve(root, config.rootDir) : root;
return normalize(config, argv);
}
function readRawConfig(argv: Arguments, root: string): JestConfigNormalize {
const rawConfig = parseConfig(argv);
if (typeof rawConfig === 'string') {
return loadJestConfigFromFile(path.resolve(process.cwd(), rawConfig), argv);
}
if (typeof rawConfig === 'object') {
const config = Object.assign({}, rawConfig);
config.rootDir = config.rootDir || root;
return normalize(config, argv);
}
// Rawconfig is undefined
const packageConfig = loadJestConfigFromPackage(
path.join(root, 'package.json'),
argv,
);
return packageConfig || normalize({ rootDir: root }, argv);
}
if (typeof rawConfig === 'string') {
return loadJestConfigFromFile(path.resolve(process.cwd(), rawConfig), argv);
}
if (typeof rawConfig === 'object') {
const config = Object.assign({}, rawConfig);
config.rootDir = config.rootDir || root;
return normalize(config, argv);
}
// Rawconfig is undefined
const packageConfig = loadJestConfigFromPackage(
path.join(root, 'package.json'),
argv,
);
return packageConfig || normalize({ rootDir: root }, argv);
}
function loadJestConfigFromFile(
filePath: string,
argv: Arguments,
): JestConfigNormalize {
const config = JSON.parse(fs.readFileSync(filePath, 'utf8'));
config.rootDir = config.rootDir
? path.resolve(path.dirname(filePath), config.rootDir)
: process.cwd();
return normalize(config, argv);
}
module.exports = function createRuntime(filename, config) {
const NodeEnvironment = require('jest-environment-node');
const Runtime = require('../');
const {normalize} = require('jest-config');
config = normalize(
{
haste: {
hasteImplModulePath: path.resolve(
__dirname,
'..',
'..',
'..',
'jest-haste-map',
'src',
'__tests__',
'haste_impl.js',
),
},
name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests',
rootDir: path.resolve(path.dirname(filename), 'test_root'),
...config,
export default function getConfig(rootPath: string): Config {
return {
jest: normalize(
{
rootDir: rootPath,
testMatch: [
'/src/**/__tests__/**/*.{js,jsx,mjs}',
'/src/**/?(*.)(spec|test).{js,jsx,mjs}'
]
},
{}
).options,
jestScript: resolveJestCliPath(
rootPath,
'react-scripts',
'scripts/test.js'
),
args: ['--env=jsdom'],
env: {