jest-runtime
Advanced tools
Comparing version 27.0.0-next.2 to 27.0.0-next.3
@@ -49,2 +49,3 @@ /** | ||
private readonly _esmoduleRegistry; | ||
private readonly _cjsNamedExports; | ||
private readonly _testPath; | ||
@@ -66,3 +67,3 @@ private readonly _resolver; | ||
private jestGlobals?; | ||
constructor(config: Config.ProjectConfig, environment: JestEnvironment, resolver: Resolver, cacheFS?: Record<string, string>, coverageOptions?: ShouldInstrumentOptions, testPath?: Config.Path); | ||
constructor(config: Config.ProjectConfig, environment: JestEnvironment, resolver: Resolver, cacheFS: Map<string, string>, coverageOptions: ShouldInstrumentOptions, testPath: Config.Path); | ||
static shouldInstrument: typeof shouldInstrument; | ||
@@ -84,2 +85,3 @@ static createContext(config: Config.ProjectConfig, options: { | ||
private loadCjsAsEsm; | ||
private getExportsOfCjs; | ||
requireModule<T = unknown>(from: Config.Path, moduleName?: string, options?: InternalModuleOptions, isRequireActual?: boolean | null): T; | ||
@@ -86,0 +88,0 @@ requireInternalModule<T = unknown>(from: Config.Path, to?: string): T; |
@@ -170,4 +170,2 @@ 'use strict'; | ||
var _Object$fromEntries; | ||
function _interopRequireDefault(obj) { | ||
@@ -241,15 +239,16 @@ return obj && obj.__esModule ? obj : {default: obj}; | ||
}; | ||
// These are modules that we know | ||
// * are safe to require from the outside (not stateful, not prone to errors passing in instances from different realms), and | ||
// * take sufficiently long to require to warrant an optimization. | ||
// When required from the outside, they use the worker's require cache and are thus | ||
// only loaded once per worker, not once per test file. | ||
// Use /benchmarks/test-file-overhead to measure the impact. | ||
// Note that this only applies when they are required in an internal context; | ||
// users who require one of these modules in their tests will still get the module from inside the VM. | ||
// Prefer listing a module here only if it is impractical to use the jest-resolve-outside-vm-option where it is required, | ||
// e.g. because there are many require sites spread across the dependency graph. | ||
const INTERNAL_MODULE_REQUIRE_OUTSIDE_OPTIMIZED_MODULES = new Set(['chalk']); | ||
const JEST_RESOLVE_OUTSIDE_VM_OPTION = Symbol.for( | ||
'jest-resolve-outside-vm-option' | ||
); | ||
const fromEntries = | ||
(_Object$fromEntries = Object.fromEntries) !== null && | ||
_Object$fromEntries !== void 0 | ||
? _Object$fromEntries | ||
: function fromEntries(iterable) { | ||
return [...iterable].reduce((obj, [key, val]) => { | ||
obj[key] = val; | ||
return obj; | ||
}, {}); | ||
}; | ||
const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); | ||
@@ -294,4 +293,4 @@ const retryTimesSymbol = Symbol.for('RETRY_TIMES'); | ||
resolver, | ||
cacheFS = {}, | ||
coverageOptions, // TODO: Make mandatory in Jest 27 | ||
cacheFS, | ||
coverageOptions, | ||
testPath | ||
@@ -335,2 +334,4 @@ ) { | ||
_defineProperty(this, '_cjsNamedExports', void 0); | ||
_defineProperty(this, '_testPath', void 0); | ||
@@ -368,12 +369,5 @@ | ||
this._cacheFS = new Map(Object.entries(cacheFS)); | ||
this._cacheFS = cacheFS; | ||
this._config = config; | ||
this._coverageOptions = coverageOptions || { | ||
changedFiles: undefined, | ||
collectCoverage: false, | ||
collectCoverageFrom: [], | ||
collectCoverageOnlyFrom: undefined, | ||
coverageProvider: 'babel', | ||
sourcesRelatedToTestsInChangedFiles: undefined | ||
}; | ||
this._coverageOptions = coverageOptions; | ||
this._currentlyExecutingModulePath = ''; | ||
@@ -386,4 +380,7 @@ this._environment = environment; | ||
this._mockFactories = new Map(); | ||
this._mockRegistry = new Map(); // during setup, this cannot be null (and it's fine to explode if it is) | ||
this._mockRegistry = new Map(); | ||
invariant( | ||
this._environment.moduleMocker, | ||
'`moduleMocker` must be set on an environment when created' | ||
); | ||
this._moduleMocker = this._environment.moduleMocker; | ||
@@ -394,2 +391,3 @@ this._isolatedModuleRegistry = null; | ||
this._esmoduleRegistry = new Map(); | ||
this._cjsNamedExports = new Map(); | ||
this._testPath = testPath; | ||
@@ -424,6 +422,8 @@ this._resolver = resolver; | ||
if (config.automock) { | ||
const virtualMocks = fromEntries(this._virtualMocks); | ||
config.setupFiles.forEach(filePath => { | ||
if (filePath && filePath.includes(NODE_MODULES)) { | ||
const moduleID = this._resolver.getModuleID(virtualMocks, filePath); | ||
if (filePath.includes(NODE_MODULES)) { | ||
const moduleID = this._resolver.getModuleID( | ||
this._virtualMocks, | ||
filePath | ||
); | ||
@@ -438,3 +438,3 @@ this._transitiveShouldMock.set(moduleID, false); | ||
static createContext(config, options) { | ||
static async createContext(config, options) { | ||
(0, _jestUtil().createDirectory)(config.cacheDirectory); | ||
@@ -448,13 +448,9 @@ const instance = Runtime.createHasteMap(config, { | ||
}); | ||
return instance.build().then( | ||
hasteMap => ({ | ||
config, | ||
hasteFS: hasteMap.hasteFS, | ||
moduleMap: hasteMap.moduleMap, | ||
resolver: Runtime.createResolver(config, hasteMap.moduleMap) | ||
}), | ||
error => { | ||
throw error; | ||
} | ||
); | ||
const hasteMap = await instance.build(); | ||
return { | ||
config, | ||
hasteFS: hasteMap.hasteFS, | ||
moduleMap: hasteMap.moduleMap, | ||
resolver: Runtime.createResolver(config, hasteMap.moduleMap) | ||
}; | ||
} | ||
@@ -678,19 +674,11 @@ | ||
const cjs = this.requireModuleOrMock(from, modulePath); | ||
const parsedExports = this.getExportsOfCjs(modulePath); | ||
const cjsExports = [...parsedExports].filter(exportName => { | ||
// we don't wanna respect any exports _named_ default as a named export | ||
if (exportName === 'default') { | ||
return false; | ||
} | ||
const transformedCode = this._fileTransforms.get(modulePath); | ||
let cjsExports = []; | ||
if (transformedCode) { | ||
const {exports} = (0, _cjsModuleLexer().parse)(transformedCode.code); | ||
cjsExports = exports.filter(exportName => { | ||
// we don't wanna respect any exports _names_ default as a named export | ||
if (exportName === 'default') { | ||
return false; | ||
} | ||
return Object.hasOwnProperty.call(cjs, exportName); | ||
}); | ||
} | ||
return Object.hasOwnProperty.call(cjs, exportName); | ||
}); | ||
const module = new (_vm().SyntheticModule)( | ||
@@ -714,5 +702,37 @@ [...cjsExports, 'default'], | ||
getExportsOfCjs(modulePath) { | ||
var _this$_fileTransforms, _this$_fileTransforms2; | ||
const cachedNamedExports = this._cjsNamedExports.get(modulePath); | ||
if (cachedNamedExports) { | ||
return cachedNamedExports; | ||
} | ||
const transformedCode = | ||
(_this$_fileTransforms = | ||
(_this$_fileTransforms2 = this._fileTransforms.get(modulePath)) === | ||
null || _this$_fileTransforms2 === void 0 | ||
? void 0 | ||
: _this$_fileTransforms2.code) !== null && | ||
_this$_fileTransforms !== void 0 | ||
? _this$_fileTransforms | ||
: this.readFile(modulePath); | ||
const {exports, reexports} = (0, _cjsModuleLexer().parse)(transformedCode); | ||
const namedExports = new Set(exports); | ||
reexports.forEach(reexport => { | ||
const resolved = this._resolveModule(modulePath, reexport); | ||
const exports = this.getExportsOfCjs(resolved); | ||
exports.forEach(namedExports.add, namedExports); | ||
}); | ||
this._cjsNamedExports.set(modulePath, namedExports); | ||
return namedExports; | ||
} | ||
requireModule(from, moduleName, options, isRequireActual) { | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -754,9 +774,6 @@ moduleName | ||
} else { | ||
if ( | ||
this._moduleRegistry.get(modulePath) || | ||
!this._isolatedModuleRegistry | ||
) { | ||
if (this._isolatedModuleRegistry) { | ||
moduleRegistry = this._isolatedModuleRegistry; | ||
} else { | ||
moduleRegistry = this._moduleRegistry; | ||
} else { | ||
moduleRegistry = this._isolatedModuleRegistry; | ||
} | ||
@@ -797,2 +814,13 @@ } | ||
if (to) { | ||
var _nativeModule$createR; | ||
const require = ((_nativeModule$createR = nativeModule() | ||
.createRequire) !== null && _nativeModule$createR !== void 0 | ||
? _nativeModule$createR | ||
: nativeModule().createRequireFromPath)(from); | ||
if (INTERNAL_MODULE_REQUIRE_OUTSIDE_OPTIMIZED_MODULES.has(to)) { | ||
return require(to); | ||
} | ||
const outsideJestVmPath = (0, _helpers.decodePossibleOutsideJestVmPath)( | ||
@@ -822,3 +850,3 @@ to | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1037,2 +1065,4 @@ moduleName | ||
this._cjsNamedExports.clear(); | ||
if (this._environment) { | ||
@@ -1110,3 +1140,3 @@ if (this._environment.global) { | ||
getSourceMaps() { | ||
return fromEntries(this._sourceMapRegistry); | ||
return this._sourceMapRegistry; | ||
} | ||
@@ -1122,3 +1152,3 @@ | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1557,3 +1587,3 @@ moduleName | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1606,3 +1636,3 @@ moduleName | ||
const currentModuleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from | ||
@@ -1706,3 +1736,3 @@ ); | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1719,3 +1749,3 @@ moduleName | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1738,3 +1768,3 @@ moduleName | ||
const moduleID = this._resolver.getModuleID( | ||
fromEntries(this._virtualMocks), | ||
this._virtualMocks, | ||
from, | ||
@@ -1741,0 +1771,0 @@ moduleName |
{ | ||
"name": "jest-runtime", | ||
"version": "27.0.0-next.2", | ||
"version": "27.0.0-next.3", | ||
"repository": { | ||
@@ -17,11 +17,11 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/console": "^27.0.0-next.1", | ||
"@jest/environment": "^27.0.0-next.1", | ||
"@jest/fake-timers": "^27.0.0-next.1", | ||
"@jest/globals": "^27.0.0-next.1", | ||
"@jest/source-map": "^27.0.0-next.0", | ||
"@jest/test-result": "^27.0.0-next.1", | ||
"@jest/transform": "^27.0.0-next.2", | ||
"@jest/types": "^27.0.0-next.1", | ||
"@types/yargs": "^15.0.0", | ||
"@jest/console": "^27.0.0-next.3", | ||
"@jest/environment": "^27.0.0-next.3", | ||
"@jest/fake-timers": "^27.0.0-next.3", | ||
"@jest/globals": "^27.0.0-next.3", | ||
"@jest/source-map": "^27.0.0-next.3", | ||
"@jest/test-result": "^27.0.0-next.3", | ||
"@jest/transform": "^27.0.0-next.3", | ||
"@jest/types": "^27.0.0-next.3", | ||
"@types/yargs": "^16.0.0", | ||
"chalk": "^4.0.0", | ||
@@ -33,10 +33,10 @@ "cjs-module-lexer": "^1.0.0", | ||
"graceful-fs": "^4.2.4", | ||
"jest-haste-map": "^27.0.0-next.2", | ||
"jest-message-util": "^27.0.0-next.1", | ||
"jest-mock": "^27.0.0-next.1", | ||
"jest-haste-map": "^27.0.0-next.3", | ||
"jest-message-util": "^27.0.0-next.3", | ||
"jest-mock": "^27.0.0-next.3", | ||
"jest-regex-util": "^27.0.0-next.0", | ||
"jest-resolve": "^27.0.0-next.2", | ||
"jest-snapshot": "^27.0.0-next.2", | ||
"jest-util": "^27.0.0-next.1", | ||
"jest-validate": "^27.0.0-next.1", | ||
"jest-resolve": "^27.0.0-next.3", | ||
"jest-snapshot": "^27.0.0-next.3", | ||
"jest-util": "^27.0.0-next.3", | ||
"jest-validate": "^27.0.0-next.3", | ||
"slash": "^3.0.0", | ||
@@ -47,3 +47,3 @@ "strip-bom": "^4.0.0", | ||
"devDependencies": { | ||
"@jest/test-utils": "^27.0.0-next.1", | ||
"@jest/test-utils": "^27.0.0-next.3", | ||
"@types/exit": "^0.1.30", | ||
@@ -54,3 +54,3 @@ "@types/glob": "^7.1.1", | ||
"execa": "^5.0.0", | ||
"jest-environment-node": "^27.0.0-next.1", | ||
"jest-environment-node": "^27.0.0-next.3", | ||
"jest-snapshot-serializer-raw": "^1.1.0" | ||
@@ -64,3 +64,3 @@ }, | ||
}, | ||
"gitHead": "0006b152354237416ffbbc26d78c0b10375c0a49" | ||
"gitHead": "2e34f2cfaf9b6864c3ad4bdca05d3097d3108a41" | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
70728
1959
6
- Removed@types/yargs@15.0.19(transitive)
Updated@jest/console@^27.0.0-next.3
Updated@jest/globals@^27.0.0-next.3
Updated@jest/types@^27.0.0-next.3
Updated@types/yargs@^16.0.0
Updatedjest-mock@^27.0.0-next.3
Updatedjest-resolve@^27.0.0-next.3
Updatedjest-snapshot@^27.0.0-next.3
Updatedjest-util@^27.0.0-next.3
Updatedjest-validate@^27.0.0-next.3