jest-config
Advanced tools
Comparing version 19.2.0-alpha.993e64af to 19.3.0-alpha.85402254
@@ -16,14 +16,47 @@ /** | ||
const fs = require('fs'); | ||
const jsonlint = require('./vendor/jsonlint'); | ||
const path = require('path'); | ||
const JEST_CONFIG = 'jest.config.js'; | ||
const PACAKAGE_JSON = 'package.json'; | ||
const PACKAGE_JSON = 'package.json'; | ||
const isFile = filePath => | ||
fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory(); | ||
const findConfig = root => { | ||
let directory = root; | ||
// $FlowFixMe | ||
let options = {}; | ||
let directory = root; | ||
const isJS = directory.endsWith('.js'); | ||
if ((isJS || directory.endsWith('.json')) && isFile(directory)) { | ||
const filePath = path.resolve(process.cwd(), directory); | ||
if (isJS) { | ||
// $FlowFixMe | ||
options = require(filePath); | ||
} else { | ||
let pkg; | ||
try { | ||
// $FlowFixMe | ||
pkg = require(filePath); | ||
} catch (error) { | ||
throw new Error( | ||
`Jest: Failed to parse config file ${filePath}\n` + | ||
` ${jsonlint.errors(fs.readFileSync(filePath, 'utf8'))}`); | ||
} | ||
if (directory.endsWith(PACKAGE_JSON)) { | ||
options = pkg.jest || options; | ||
} else { | ||
options = pkg; | ||
} | ||
} | ||
options.rootDir = options.rootDir ? | ||
path.resolve(path.dirname(directory), options.rootDir) : | ||
path.dirname(directory); | ||
return options; | ||
} | ||
do { | ||
const configJsFilePath = path.join(directory, JEST_CONFIG); | ||
if (fs.existsSync(configJsFilePath)) { | ||
if (isFile(configJsFilePath)) { | ||
// $FlowFixMe | ||
@@ -33,4 +66,5 @@ options = require(configJsFilePath); | ||
} | ||
const packageJsonFilePath = path.join(directory, PACAKAGE_JSON); | ||
if (fs.existsSync(packageJsonFilePath)) { | ||
const packageJsonFilePath = path.join(directory, PACKAGE_JSON); | ||
if (isFile(packageJsonFilePath)) { | ||
// $FlowFixMe | ||
@@ -46,5 +80,7 @@ const pkg = require(packageJsonFilePath); | ||
} while (directory !== (directory = path.dirname(directory))); | ||
options.rootDir = options.rootDir ? | ||
path.resolve(root, options.rootDir) : | ||
root; | ||
directory; | ||
return options; | ||
@@ -51,0 +87,0 @@ }; |
@@ -18,3 +18,2 @@ /** | ||
const findConfig = require('./findConfig'); | ||
const loadFromFile = require('./loadFromFile'); | ||
const normalize = require('./normalize'); | ||
@@ -47,6 +46,2 @@ const path = require('path'); | ||
if (typeof rawOptions === 'string') { | ||
return loadFromFile(path.resolve(process.cwd(), rawOptions)); | ||
} | ||
if (typeof rawOptions === 'object') { | ||
@@ -58,2 +53,6 @@ const config = Object.assign({}, rawOptions); | ||
if (typeof rawOptions === 'string') { | ||
root = path.resolve(process.cwd(), rawOptions); | ||
} | ||
return findConfig(root); | ||
@@ -60,0 +59,0 @@ }; |
@@ -384,3 +384,3 @@ /** | ||
'haste.hasteImplModulePath', | ||
value.hasteImplModulePath); | ||
_replaceRootDirInPath(options.rootDir, value.hasteImplModulePath)); | ||
@@ -387,0 +387,0 @@ } |
{ | ||
"name": "jest-config", | ||
"version": "19.2.0-alpha.993e64af", | ||
"version": "19.3.0-alpha.85402254", | ||
"repository": { | ||
@@ -13,10 +13,10 @@ "type": "git", | ||
"glob": "^7.1.1", | ||
"jest-environment-jsdom": "^19.2.0-alpha.993e64af", | ||
"jest-environment-node": "^19.2.0-alpha.993e64af", | ||
"jest-jasmine2": "^19.2.0-alpha.993e64af", | ||
"jest-regex-util": "^19.2.0-alpha.993e64af", | ||
"jest-resolve": "^19.2.0-alpha.993e64af", | ||
"jest-validate": "^19.2.0-alpha.993e64af", | ||
"pretty-format": "^19.2.0-alpha.993e64af" | ||
"jest-environment-jsdom": "^19.3.0-alpha.85402254", | ||
"jest-environment-node": "^19.3.0-alpha.85402254", | ||
"jest-jasmine2": "^19.3.0-alpha.85402254", | ||
"jest-regex-util": "^19.3.0-alpha.85402254", | ||
"jest-resolve": "^19.3.0-alpha.85402254", | ||
"jest-validate": "^19.3.0-alpha.85402254", | ||
"pretty-format": "^19.3.0-alpha.85402254" | ||
} | ||
} |
55004
13
1695
+ Addedjest-diff@19.3.0-alpha.85402254(transitive)
+ Addedjest-environment-jsdom@19.3.0-alpha.85402254(transitive)
+ Addedjest-environment-node@19.3.0-alpha.85402254(transitive)
+ Addedjest-jasmine2@19.3.0-alpha.85402254(transitive)
+ Addedjest-matcher-utils@19.3.0-alpha.85402254(transitive)
+ Addedjest-matchers@19.3.0-alpha.85402254(transitive)
+ Addedjest-message-util@19.3.0-alpha.85402254(transitive)
+ Addedjest-mock@19.3.0-alpha.85402254(transitive)
+ Addedjest-regex-util@19.3.0-alpha.85402254(transitive)
+ Addedjest-resolve@19.3.0-alpha.85402254(transitive)
+ Addedjest-snapshot@19.3.0-alpha.85402254(transitive)
+ Addedjest-util@19.3.0-alpha.85402254(transitive)
+ Addedjest-validate@19.3.0-alpha.85402254(transitive)
+ Addedpretty-format@19.3.0-alpha.85402254(transitive)
- Removedjest-diff@19.2.0-alpha.993e64af(transitive)
- Removedjest-environment-jsdom@19.2.0-alpha.993e64af(transitive)
- Removedjest-environment-node@19.2.0-alpha.993e64af(transitive)
- Removedjest-jasmine2@19.2.0-alpha.993e64af(transitive)
- Removedjest-matcher-utils@19.2.0-alpha.993e64af(transitive)
- Removedjest-matchers@19.2.0-alpha.993e64af(transitive)
- Removedjest-message-util@19.2.0-alpha.993e64af(transitive)
- Removedjest-mock@19.2.0-alpha.993e64af(transitive)
- Removedjest-regex-util@19.2.0-alpha.993e64af(transitive)
- Removedjest-resolve@19.2.0-alpha.993e64af(transitive)
- Removedjest-snapshot@19.2.0-alpha.993e64af(transitive)
- Removedjest-util@19.2.0-alpha.993e64af(transitive)
- Removedjest-validate@19.2.0-alpha.993e64af(transitive)
- Removedpretty-format@19.2.0-alpha.993e64af(transitive)