jest-runtime
Advanced tools
Comparing version 13.3.0-alpha.g8b48d59 to 13.4.0-alpha.d2632006
@@ -64,3 +64,3 @@ /** | ||
then(config => { | ||
Runtime.buildHasteMap(config, { | ||
Runtime.createHasteContext(config, { | ||
maxWorkers: os.cpus().length - 1 }). | ||
@@ -67,0 +67,0 @@ |
@@ -18,5 +18,5 @@ /** | ||
const HasteMap = require('jest-haste-map'); | ||
const Resolver = require('jest-resolve'); | ||
const createHasteMap = require('jest-haste-map').create; | ||
const createResolver = require('jest-resolve').create; | ||
const fs = require('graceful-fs'); | ||
@@ -41,4 +41,19 @@ const moduleMocker = require('jest-mock'); | ||
const NODE_MODULES = path.sep + 'node_modules' + path.sep; | ||
const SNAPSHOT_EXTENSION = 'snap'; | ||
const getModuleNameMapper = config => { | ||
if (config.moduleNameMapper.length) { | ||
const moduleNameMapper = Object.create(null); | ||
config.moduleNameMapper.forEach( | ||
map => moduleNameMapper[map[1]] = new RegExp(map[0])); | ||
return moduleNameMapper;} | ||
return null;}; | ||
const mockParentModule = { | ||
@@ -138,3 +153,3 @@ exports: {}, | ||
static buildHasteMap( | ||
static createHasteContext( | ||
config, | ||
@@ -144,3 +159,3 @@ options) | ||
utils.createDirectory(config.cacheDirectory); | ||
const instance = createHasteMap(config, { | ||
const instance = Runtime.createHasteMap(config, { | ||
maxWorkers: options.maxWorkers, | ||
@@ -153,3 +168,3 @@ resetCache: !config.cache }); | ||
moduleMap, | ||
resolver: createResolver(config, moduleMap) }), | ||
resolver: Runtime.createResolver(config, moduleMap) }), | ||
@@ -162,2 +177,41 @@ error => { | ||
static createHasteMap( | ||
config, | ||
options) | ||
{ | ||
const ignorePattern = new RegExp( | ||
[config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|')); | ||
return new HasteMap({ | ||
cacheDirectory: config.cacheDirectory, | ||
extensions: [SNAPSHOT_EXTENSION].concat(config.moduleFileExtensions), | ||
ignorePattern, | ||
maxWorkers: options && options.maxWorkers || 1, | ||
mocksPattern: config.mocksPattern, | ||
name: config.name, | ||
platforms: config.haste.platforms || ['ios', 'android'], | ||
providesModuleNodeModules: config.haste.providesModuleNodeModules, | ||
resetCache: options && options.resetCache, | ||
roots: config.testPathDirs, | ||
useWatchman: config.watchman });} | ||
static createResolver( | ||
config, | ||
moduleMap) | ||
{ | ||
return new Resolver(moduleMap, { | ||
browser: config.browser, | ||
defaultPlatform: config.haste.defaultPlatform, | ||
extensions: config.moduleFileExtensions.map(extension => '.' + extension), | ||
hasCoreModules: true, | ||
moduleDirectories: config.moduleDirectories, | ||
moduleNameMapper: getModuleNameMapper(config), | ||
modulePaths: config.modulePaths, | ||
platforms: config.haste.platforms });} | ||
static runCLI(args, info) { | ||
@@ -171,3 +225,7 @@ return require('./cli').run(args, info);} | ||
requireModule(from, moduleName) { | ||
requireModule( | ||
from, | ||
moduleName, | ||
options) | ||
{ | ||
const moduleID = this._normalizeID(from, moduleName); | ||
@@ -183,2 +241,3 @@ let modulePath; | ||
if ( | ||
(!options || !options.isInternalModule) && | ||
!moduleResource && | ||
@@ -209,3 +268,2 @@ manualMockResource && | ||
this._moduleRegistry[modulePath] = localModule; | ||
@@ -220,3 +278,3 @@ if (path.extname(modulePath) === '.json') { | ||
{ | ||
this._execModule(localModule);}} | ||
this._execModule(localModule, options);}} | ||
@@ -227,2 +285,6 @@ | ||
requireInternalModule(from, to) { | ||
return this.requireModule(from, to, { isInternalModule: true });} | ||
requireMock(from, moduleName) { | ||
@@ -348,11 +410,11 @@ const moduleID = this._normalizeID(from, moduleName); | ||
return ( | ||
shouldCollectCoverage && | ||
!this._coverageRegex.test(filename) && | ||
!(this._mocksPattern && this._mocksPattern.test(filename)) && | ||
!this._testRegex.test(filename));} | ||
return !!( | ||
shouldCollectCoverage && | ||
!this._coverageRegex.test(filename) && | ||
!(this._mocksPattern && this._mocksPattern.test(filename)) && | ||
!this._testRegex.test(filename));} | ||
_execModule(localModule) { | ||
_execModule(localModule, options) { | ||
// If the environment was disposed, prevent this module from being executed. | ||
@@ -364,3 +426,5 @@ if (!this._environment.global) { | ||
const filename = localModule.filename; | ||
const shouldCollectCoverage = this._shouldCollectCoverage(filename); | ||
const shouldCollectCoverage = | ||
(!options || !options.isInternalModule) && | ||
this._shouldCollectCoverage(filename); | ||
const collectors = this._coverageCollectors; | ||
@@ -382,13 +446,15 @@ if (shouldCollectCoverage && !collectors[filename]) { | ||
localModule.paths = this._resolver.getModulePaths(dirname); | ||
localModule.require = this._createRequireImplementation(filename); | ||
localModule.require = this._createRequireImplementation(filename, options); | ||
const script = transform(filename, this._config, { | ||
instrument: shouldCollectCoverage && ( | ||
source => collectors[filename].getInstrumentedSource( | ||
const script = transform( | ||
filename, | ||
options && options.isInternalModule ? null : this._config, | ||
shouldCollectCoverage ? { | ||
instrument: source => collectors[filename].getInstrumentedSource( | ||
source, | ||
filename, | ||
'$JEST')) }); | ||
'$JEST') } : | ||
null); | ||
const wrapper = this._runScript(script, filename); | ||
@@ -610,9 +676,14 @@ wrapper.call( | ||
_createRequireImplementation(from) { | ||
const moduleRequire = this.requireModuleOrMock.bind(this, from); | ||
_createRequireImplementation( | ||
from, | ||
options) | ||
{ | ||
const moduleRequire = options && options.isInternalModule ? | ||
moduleName => this.requireInternalModule(from, moduleName) : | ||
this.requireModuleOrMock.bind(this, from); | ||
moduleRequire.cache = Object.create(null); | ||
moduleRequire.extensions = Object.create(null); | ||
moduleRequire.requireActual = this.requireModule.bind(this, from); | ||
moduleRequire.requireMock = this.requireMock.bind(this, from); | ||
moduleRequire.requireActual = this.requireModule.bind(this, from); | ||
moduleRequire.resolve = moduleName => this._resolveModule(from, moduleName); | ||
moduleRequire.cache = Object.create(null); | ||
moduleRequire.extensions = Object.create(null); | ||
return moduleRequire;} | ||
@@ -619,0 +690,0 @@ |
@@ -14,6 +14,5 @@ /** | ||
const Resolver = require('jest-resolve'); | ||
const createDirectory = require('jest-util').createDirectory; | ||
const crypto = require('crypto'); | ||
const fileExists = require('jest-file-exists'); | ||
const fs = require('graceful-fs'); | ||
@@ -68,3 +67,3 @@ const getCacheFilePath = require('jest-haste-map').getCacheFilePath; | ||
const configStr = configToJsonMap.get(config); | ||
const configStr = configToJsonMap.get(config) || ''; | ||
if (typeof preprocessor.getCacheKey === 'function') { | ||
@@ -95,3 +94,3 @@ return preprocessor.getCacheKey(fileData, filePath, configStr);} else | ||
const readCacheFile = (filePath, cachePath) => { | ||
if (!Resolver.fileExists(cachePath)) { | ||
if (!fileExists(cachePath)) { | ||
return null;} | ||
@@ -123,6 +122,7 @@ | ||
const mtime = fs.statSync(filename).mtime; | ||
const mapCacheKey = filename + '_' + mtime.getTime(); | ||
const instrumentCacheKey = options && options.instrument ? '1' : '0'; | ||
const key = filename + '-' + mtime.getTime() + '-' + instrumentCacheKey; | ||
if (cache.has(mapCacheKey)) { | ||
const content = cache.get(mapCacheKey); | ||
if (cache.has(key)) { | ||
const content = cache.get(key); | ||
if (content) { | ||
@@ -140,3 +140,3 @@ return content;}} | ||
if (!ignoreCache.has(config)) { | ||
if (config && !ignoreCache.has(config)) { | ||
ignoreCache.set( | ||
@@ -149,2 +149,3 @@ config, | ||
if ( | ||
config && | ||
config.scriptPreprocessor && ( | ||
@@ -169,3 +170,6 @@ | ||
const cacheKey = getCacheKey(preprocessor, content, filename, config); | ||
const cacheKey = | ||
getCacheKey(preprocessor, content, filename, config) + | ||
instrumentCacheKey; | ||
// Create sub folders based on the cacheKey to avoid creating one | ||
@@ -202,3 +206,3 @@ // directory with many files. | ||
cache.set(mapCacheKey, script); | ||
cache.set(key, script); | ||
return script;}; | ||
@@ -205,0 +209,0 @@ |
{ | ||
"name": "jest-runtime", | ||
"version": "13.3.0-alpha.g8b48d59", | ||
"version": "13.4.0-alpha.d2632006", | ||
"repository": { | ||
@@ -13,8 +13,9 @@ "type": "git", | ||
"graceful-fs": "^4.1.3", | ||
"jest-config": "^13.3.0-alpha.g8b48d59", | ||
"jest-haste-map": "^13.3.0-alpha.g8b48d59", | ||
"jest-mock": "^13.3.0-alpha.g8b48d59", | ||
"jest-resolve": "^13.3.0-alpha.g8b48d59", | ||
"jest-snapshot": "^13.3.0-alpha.g8b48d59", | ||
"jest-util": "^13.3.0-alpha.g8b48d59", | ||
"jest-config": "^13.4.0-alpha.d2632006", | ||
"jest-file-exists": "^13.4.0-alpha.d2632006", | ||
"jest-haste-map": "^13.4.0-alpha.d2632006", | ||
"jest-mock": "^13.4.0-alpha.d2632006", | ||
"jest-resolve": "^13.4.0-alpha.d2632006", | ||
"jest-snapshot": "^13.4.0-alpha.d2632006", | ||
"jest-util": "^13.4.0-alpha.d2632006", | ||
"json-stable-stringify": "^1.0.0", | ||
@@ -27,4 +28,4 @@ "yargs": "^4.7.1" | ||
"devDependencies": { | ||
"jest-config": "^13.3.0-alpha.g8b48d59", | ||
"jest-environment-node": "^13.3.0-alpha.g8b48d59" | ||
"jest-config": "^13.4.0-alpha.d2632006", | ||
"jest-environment-node": "^13.4.0-alpha.d2632006" | ||
}, | ||
@@ -31,0 +32,0 @@ "jest": { |
33038
788
11
+ Addedjest-config@13.4.0-alpha.d2632006(transitive)
+ Addedjest-diff@13.4.0-alpha.d2632006(transitive)
+ Addedjest-environment-jsdom@13.4.0-alpha.d2632006(transitive)
+ Addedjest-environment-node@13.4.0-alpha.d2632006(transitive)
+ Addedjest-file-exists@13.4.0-alpha.d2632006(transitive)
+ Addedjest-haste-map@13.4.0-alpha.d2632006(transitive)
+ Addedjest-jasmine2@13.4.0-alpha.d2632006(transitive)
+ Addedjest-matcher-utils@13.4.0-alpha.d2632006(transitive)
+ Addedjest-matchers@13.4.0-alpha.d2632006(transitive)
+ Addedjest-mock@13.4.0-alpha.d2632006(transitive)
+ Addedjest-resolve@13.4.0-alpha.d2632006(transitive)
+ Addedjest-snapshot@13.4.0-alpha.d2632006(transitive)
+ Addedjest-util@13.4.0-alpha.d2632006(transitive)
- Removedansi-escapes@3.2.0(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedansicolors@0.3.2(transitive)
- Removedcardinal@2.1.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcli-table@0.3.11(transitive)
- Removedcli-usage@0.1.10(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcolors@1.0.3(transitive)
- Removedgrowly@1.3.0(transitive)
- Removedhas-flag@2.0.03.0.0(transitive)
- Removedjest-config@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-diff@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-environment-jsdom@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-environment-node@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-haste-map@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-jasmine1@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-jasmine2@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-matcher-utils@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-matchers@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-mock@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-resolve@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-snapshot@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-util@13.3.0-alpha.g8b48d59(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash._arraycopy@3.0.0(transitive)
- Removedlodash._arrayeach@3.0.0(transitive)
- Removedlodash._baseassign@3.2.0(transitive)
- Removedlodash._baseclone@3.3.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basefor@3.0.3(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.clonedeep@3.0.2(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedmarked@0.7.0(transitive)
- Removedmarked-terminal@3.3.0(transitive)
- Removednode-emoji@1.11.0(transitive)
- Removednode-notifier@4.6.1(transitive)
- Removedredeyed@2.1.1(transitive)
- Removedshellwords@0.1.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-hyperlinks@1.0.1(transitive)