Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inner =>
function() {
if (isIntroscopedModule(arguments[1])) {
// content
arguments[0] =
arguments[0] + '\n\n// @introscope "enable": true';
}
// filename
arguments[1] = removeQuery(arguments[1]);
return inner.apply(this, arguments);
},
);
wrap(
Runtime.prototype,
'requireModule',
inner =>
function(from, moduleName) {
if (isIntroscopedModule(moduleName)) {
let modulePath = this._resolveModule(from, moduleName);
const realPath = removeQuery(modulePath);
// makes module resolver find the proper transformer
const ext = extname(realPath);
moduleName += ext;
modulePath += ext;
arguments[1] = moduleName;
this._cacheFS[modulePath] = fs.readFileSync(realPath, 'utf8');
}
return inner.apply(this, arguments);
const getResolver = (config, rawModuleMap) => {
// In watch mode, the raw module map with all haste modules is passed from
// the test runner to the watch command. This is because jest-haste-map's
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (rawModuleMap) {
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(rawModuleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
const runnerGlobal = environment.global
const context = dangerfileContext
// Adds things like fail, warn ... to global
for (const prop in context) {
if (context.hasOwnProperty(prop)) {
const anyContext: any = context
runnerGlobal[prop] = anyContext[prop]
}
}
// Setup a runtime environment
const hasteConfig = { automock: false, maxWorkers: 1, resetCache: false }
const hasteMap = await Runtime.createHasteMap(config, hasteConfig).build()
const resolver = Runtime.createResolver(config, hasteMap.moduleMap)
const runtime = new Runtime(config, environment, resolver)
return {
context,
environment,
runtime
}
}
// In watch mode, the raw module map with all haste modules is passed from
// the test runner to the watch command. This is because jest-haste-map's
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (serializableModuleMap) {
const moduleMap = serializableModuleMap
? HasteMap.ModuleMap.fromJSON(serializableModuleMap)
: null;
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(moduleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
const getResolver = (config, rawModuleMap) => {
// In watch mode, the raw module map with all haste modules is passed from
// the test runner to the watch command. This is because jest-haste-map's
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (rawModuleMap) {
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(rawModuleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
export const getResolver = (
config: ProjectConfig,
serializableModuleMap: Object,
) => {
// In watch mode, the raw module map with all haste modules is passed from
// the test runner to the watch command. This is because jest-haste-map's
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (serializableModuleMap) {
const moduleMap = serializableModuleMap
? HasteMap.ModuleMap.fromJSON(serializableModuleMap)
: null;
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(moduleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (serializableModuleMap) {
const moduleMap = serializableModuleMap
? HasteMap.ModuleMap.fromJSON(serializableModuleMap)
: null;
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(moduleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
const getResolver = (config, rawModuleMap) => {
// In watch mode, the raw module map with all haste modules is passed from
// the test runner to the watch command. This is because jest-haste-map's
// watch mode does not persist the haste map on disk after every file change.
// To make this fast and consistent, we pass it from the TestRunner.
if (rawModuleMap) {
return wrapResolver(
Runtime.createResolver(config, new HasteMap.ModuleMap(rawModuleMap)),
);
} else {
const name = config.name;
if (!resolvers[name]) {
resolvers[name] = wrapResolver(
Runtime.createResolver(
config,
Runtime.createHasteMap(config).readModuleMap(),
),
);
}
return resolvers[name];
}
};
const environment: Environment = new NodeEnvironment(config)
const runnerGlobal = environment.global
const context = dangerfileContext
// Adds things like fail, warn ... to global
for (const prop in context) {
if (context.hasOwnProperty(prop)) {
const anyContext: any = context
runnerGlobal[prop] = anyContext[prop]
}
}
// Setup a runtime environment
const hasteConfig = { automock: false, maxWorkers: 1, resetCache: false }
const hasteMap = await Runtime.createHasteMap(config, hasteConfig).build()
const resolver = Runtime.createResolver(config, hasteMap.moduleMap)
const runtime = new Runtime(config, environment, resolver)
return {
context,
environment,
runtime
}
}
#!/usr/bin/env node
/* eslint-disable */
const jestRuntime = require('jest-runtime');
const oldexecModule = jestRuntime.prototype._execModule;
jestRuntime.prototype._execModule = function _execModule(localModule, options) {
// Do not apply esm to dependencies & test files to have access to jest globals
if (
localModule.id.includes('node_modules') ||
localModule.id.includes('__tests__')
) {
return oldexecModule.apply(this, [localModule, options]);
}
localModule.exports = require('esm')(localModule)(localModule.id);
return localModule;
};
cli = require('jest/bin/jest');