diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index a9fd1123419e..86886d05adbb 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -9,6 +9,7 @@ "main": "build/index.js", "dependencies": { "browser-resolve": "^1.11.2", + "is-builtin-module": "^1.0.0", "jest-haste-map": "^19.0.0", "resolve": "^1.2.0" } diff --git a/packages/jest-resolve/src/__test__/resolve-test.js b/packages/jest-resolve/src/__test__/resolve-test.js new file mode 100644 index 000000000000..2ee2826fe3eb --- /dev/null +++ b/packages/jest-resolve/src/__test__/resolve-test.js @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra + */ + +'use strict'; + +const ModuleMap = require('jest-haste-map').ModuleMap; +const Resolver = require('../'); + +describe('isCoreModule', () => { + it('returns false if `hasCoreModules` is false.', () => { + const moduleMap = new ModuleMap(); + const resolver = new Resolver(moduleMap, { + hasCoreModules: false, + }); + const isCore = resolver.isCoreModule('assert'); + expect(isCore).toEqual(false); + }); + + it('returns true if `hasCoreModules` is true and `moduleName` is a core module.', () => { + const moduleMap = new ModuleMap(); + const resolver = new Resolver(moduleMap, {}); + const isCore = resolver.isCoreModule('assert'); + expect(isCore).toEqual(true); + }); + + it('returns false if `hasCoreModules` is true and `moduleName` is not a core module.', () => { + const moduleMap = new ModuleMap(); + const resolver = new Resolver(moduleMap, {}); + const isCore = resolver.isCoreModule('not-a-core-module'); + expect(isCore).toEqual(false); + }); +}); diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 49dd8971eb5e..730b1e087104 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -17,6 +17,7 @@ const nodeModulesPaths = require('resolve/lib/node-modules-paths'); const path = require('path'); const resolve = require('resolve'); const browserResolve = require('browser-resolve'); +const isBuiltinModule = require('is-builtin-module'); type ResolverConfig = {| browser?: boolean, @@ -177,10 +178,7 @@ class Resolver { isCoreModule(moduleName: string): boolean { return ( this._options.hasCoreModules && - ( - resolve.isCore(moduleName) || - moduleName === 'v8' - ) + isBuiltinModule(moduleName) ); }