本文整理汇总了TypeScript中jest-resolve.isCoreModule函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isCoreModule函数的具体用法?TypeScript isCoreModule怎么用?TypeScript isCoreModule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isCoreModule函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _requireResolvePaths
private _requireResolvePaths(from: Config.Path, moduleName?: string) {
if (moduleName == null) {
throw new Error(
'The first argument to require.resolve.paths must be a string. Received null or undefined.',
);
}
if (!moduleName.length) {
throw new Error(
'The first argument to require.resolve.paths must not be the empty string.',
);
}
if (moduleName[0] === '.') {
return [path.resolve(from, '..')];
}
if (this._resolver.isCoreModule(moduleName)) {
return null;
}
return this._resolver.getModulePaths(path.resolve(from, '..'));
}
示例2: catch
return dependencies.reduce<Array<Config.Path>>((acc, dependency) => {
if (this._resolver.isCoreModule(dependency)) {
return acc;
}
let resolvedDependency;
try {
resolvedDependency = this._resolver.resolveModule(
file,
dependency,
options,
);
} catch (e) {
resolvedDependency = this._resolver.getMockModule(file, dependency);
}
if (resolvedDependency) {
acc.push(resolvedDependency);
}
return acc;
}, []);
示例3: _shouldMock
private _shouldMock(from: Config.Path, moduleName: string) {
const mockPath = this._resolver.getModulePath(from, moduleName);
if (mockPath in this._virtualMocks) {
return true;
}
const explicitShouldMock = this._explicitShouldMock;
const moduleID = this._resolver.getModuleID(
this._virtualMocks,
from,
moduleName,
);
const key = from + path.delimiter + moduleID;
if (moduleID in explicitShouldMock) {
return explicitShouldMock[moduleID];
}
if (
!this._shouldAutoMock ||
this._resolver.isCoreModule(moduleName) ||
this._shouldUnmockTransitiveDependenciesCache[key]
) {
return false;
}
if (moduleID in this._shouldMockModuleCache) {
return this._shouldMockModuleCache[moduleID];
}
let modulePath;
try {
modulePath = this._resolveModule(from, moduleName);
} catch (e) {
const manualMock = this._resolver.getMockModule(from, moduleName);
if (manualMock) {
this._shouldMockModuleCache[moduleID] = true;
return true;
}
throw e;
}
if (this._unmockList && this._unmockList.test(modulePath)) {
this._shouldMockModuleCache[moduleID] = false;
return false;
}
// transitive unmocking for package managers that store flat packages (npm3)
const currentModuleID = this._resolver.getModuleID(
this._virtualMocks,
from,
);
if (
this._transitiveShouldMock[currentModuleID] === false ||
(from.includes(NODE_MODULES) &&
modulePath.includes(NODE_MODULES) &&
((this._unmockList && this._unmockList.test(from)) ||
explicitShouldMock[currentModuleID] === false))
) {
this._transitiveShouldMock[moduleID] = false;
this._shouldUnmockTransitiveDependenciesCache[key] = true;
return false;
}
return (this._shouldMockModuleCache[moduleID] = true);
}
示例4: requireModule
requireModule(
from: Config.Path,
moduleName?: string,
options?: InternalModuleOptions,
isRequireActual?: boolean | null,
) {
const moduleID = this._resolver.getModuleID(
this._virtualMocks,
from,
moduleName,
);
let modulePath;
// Some old tests rely on this mocking behavior. Ideally we'll change this
// to be more explicit.
const moduleResource = moduleName && this._resolver.getModule(moduleName);
const manualMock =
moduleName && this._resolver.getMockModule(from, moduleName);
if (
(!options || !options.isInternalModule) &&
!isRequireActual &&
!moduleResource &&
manualMock &&
manualMock !== this._isCurrentlyExecutingManualMock &&
this._explicitShouldMock[moduleID] !== false
) {
modulePath = manualMock;
}
if (moduleName && this._resolver.isCoreModule(moduleName)) {
return this._requireCoreModule(moduleName);
}
if (!modulePath) {
modulePath = this._resolveModule(from, moduleName);
}
let moduleRegistry;
if (!options || !options.isInternalModule) {
if (this._moduleRegistry[modulePath] || !this._isolatedModuleRegistry) {
moduleRegistry = this._moduleRegistry;
} else {
moduleRegistry = this._isolatedModuleRegistry;
}
} else {
moduleRegistry = this._internalModuleRegistry;
}
if (!moduleRegistry[modulePath]) {
// We must register the pre-allocated module object first so that any
// circular dependencies that may arise while evaluating the module can
// be satisfied.
const localModule: InitialModule = {
children: [],
exports: {},
filename: modulePath,
id: modulePath,
loaded: false,
};
moduleRegistry[modulePath] = localModule;
if (path.extname(modulePath) === '.json') {
localModule.exports = this._environment.global.JSON.parse(
stripBOM(fs.readFileSync(modulePath, 'utf8')),
);
} else if (path.extname(modulePath) === '.node') {
localModule.exports = require(modulePath);
} else {
// Only include the fromPath if a moduleName is given. Else treat as root.
const fromPath = moduleName ? from : null;
this._execModule(localModule, options, moduleRegistry, fromPath);
}
localModule.loaded = true;
}
return moduleRegistry[modulePath].exports;
}
示例5: requireModule
requireModule(
from: Config.Path,
moduleName?: string,
options?: InternalModuleOptions,
isRequireActual?: boolean | null,
) {
const moduleID = this._resolver.getModuleID(
this._virtualMocks,
from,
moduleName,
);
let modulePath: string | undefined;
// Some old tests rely on this mocking behavior. Ideally we'll change this
// to be more explicit.
const moduleResource = moduleName && this._resolver.getModule(moduleName);
const manualMock =
moduleName && this._resolver.getMockModule(from, moduleName);
if (
(!options || !options.isInternalModule) &&
!isRequireActual &&
!moduleResource &&
manualMock &&
manualMock !== this._isCurrentlyExecutingManualMock &&
this._explicitShouldMock[moduleID] !== false
) {
modulePath = manualMock;
}
if (moduleName && this._resolver.isCoreModule(moduleName)) {
return this._requireCoreModule(moduleName);
}
if (!modulePath) {
modulePath = this._resolveModule(from, moduleName);
}
let moduleRegistry;
if (!options || !options.isInternalModule) {
if (
this._moduleRegistry.get(modulePath) ||
!this._isolatedModuleRegistry
) {
moduleRegistry = this._moduleRegistry;
} else {
moduleRegistry = this._isolatedModuleRegistry;
}
} else {
moduleRegistry = this._internalModuleRegistry;
}
const module = moduleRegistry.get(modulePath);
if (module) {
return module.exports;
}
// We must register the pre-allocated module object first so that any
// circular dependencies that may arise while evaluating the module can
// be satisfied.
const localModule: InitialModule = {
children: [],
exports: {},
filename: modulePath,
id: modulePath,
loaded: false,
};
moduleRegistry.set(modulePath, localModule);
this._loadModule(
localModule,
from,
moduleName,
modulePath,
options,
moduleRegistry,
);
return localModule.exports;
}