How to use the jest-haste-map.ModuleMap function in jest-haste-map

To help you get started, we’ve selected a few jest-haste-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookarchive / atom-ide-ui / modules / jest-atom-runner / src / atomTestRunner.js View on Github external
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];
  }
};
github facebook / metro / packages / metro / src / ModuleGraph / node-haste / node-haste.js View on Github external
const filesByDirNameIndex = new FilesByDirNameIndex(files);
  const assetResolutionCache = new AssetResolutionCache({
    assetExtensions: new Set(assetExts),
    getDirFiles: (dirPath: string): $ReadOnlyArray =>
      filesByDirNameIndex.getAllFiles(dirPath),
    platforms,
  });
  const moduleResolver = new ModuleResolver({
    dirExists: (filePath: string): boolean => hasteFS.dirExists(filePath),
    doesFileExist: (filePath: string): boolean => hasteFS.exists(filePath),
    extraNodeModules,
    isAssetFile: (filePath: string): boolean => helpers.isAssetFile(filePath),
    mainFields: options.mainFields,
    // $FlowFixMe -- error revealed by types-first codemod
    moduleCache,
    moduleMap: new ModuleMap({
      duplicates: new Map(),
      map: createModuleMap({files, helpers, moduleCache, sourceExts}),
      mocks: new Map(),
      rootDir: '',
    }),
    preferNativePlatform: true,
    projectRoot: '',
    resolveAsset: (
      dirPath: string,
      assetName: string,
      platform: null | string,
    ): ?$ReadOnlyArray =>
      assetResolutionCache.resolve(dirPath, assetName, platform),
    resolveRequest: options.resolveRequest,
    sourceExts,
  });
github facebook-atom / jest-electron-runner / packages / electron / src / utils / resolver.js View on Github external
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];
  }
};
github facebook / metro / packages / metro / src / ModuleGraph / node-haste / node-haste.js View on Github external
const filesByDirNameIndex = new FilesByDirNameIndex(files);
  const assetResolutionCache = new AssetResolutionCache({
    assetExtensions: new Set(assetExts),
    getDirFiles: (dirPath: string): $ReadOnlyArray =>
      filesByDirNameIndex.getAllFiles(dirPath),
    platforms,
  });
  const moduleResolver = new ModuleResolver({
    dirExists: (filePath: string): boolean => hasteFS.dirExists(filePath),
    doesFileExist: (filePath: string): boolean => hasteFS.exists(filePath),
    extraNodeModules,
    isAssetFile: (filePath: string): boolean => helpers.isAssetFile(filePath),
    mainFields: options.mainFields,
    moduleCache,
    moduleMap: new ModuleMap({
      duplicates: new Map(),
      map: createModuleMap({files, helpers, moduleCache, sourceExts}),
      mocks: new Map(),
      rootDir: '',
    }),
    preferNativePlatform: true,
    projectRoot: '',
    resolveAsset: (
      dirPath: string,
      assetName: string,
      platform: null | string,
    ): ?$ReadOnlyArray =>
      assetResolutionCache.resolve(dirPath, assetName, platform),
    resolveRequest: options.resolveRequest,
    sourceExts,
  });
github facebook / metro / packages / metro-bundler / src / ModuleGraph / node-haste / node-haste.js View on Github external
);

  const resolutionRequests = {};
  const filesByDirNameIndex = new FilesByDirNameIndex(files);
  const assetResolutionCache = new AssetResolutionCache({
    assetExtensions: new Set(assetExts),
    getDirFiles: dirPath => filesByDirNameIndex.getAllFiles(dirPath),
    platforms,
  });
  const moduleResolver = new ModuleResolver({
    dirExists: filePath => hasteFS.dirExists(filePath),
    doesFileExist: filePath => hasteFS.exists(filePath),
    extraNodeModules,
    helpers,
    moduleCache,
    moduleMap: new ModuleMap({
      duplicates: Object.create(null),
      map: createModuleMap({files, helpers, moduleCache, sourceExts}),
      mocks: Object.create(null),
    }),
    preferNativePlatform: true,
    resolveAsset: (dirPath, assetName, platform) =>
      assetResolutionCache.resolve(dirPath, assetName, platform),
    sourceExts,
  });

  return (id, sourcePath, platform, _, callback) => {
    let resolutionRequest = resolutionRequests[platform];
    if (!resolutionRequest) {
      resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
        moduleResolver,
        entryPath: '',

jest-haste-map

MIT
Latest version published 10 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages