From c3c7d862f77412c873073704aced452e4d42c864 Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Fri, 24 Feb 2017 06:56:06 -0700 Subject: [PATCH 1/3] Use `is-builtin-module` instead of `resolve.isCore`. --- packages/jest-resolve/package.json | 1 + .../jest-resolve/src/__test__/resolve-test.js | 44 +++++++++++++++++++ packages/jest-resolve/src/index.js | 6 +-- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 packages/jest-resolve/src/__test__/resolve-test.js 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..4eb23eac6b38 --- /dev/null +++ b/packages/jest-resolve/src/__test__/resolve-test.js @@ -0,0 +1,44 @@ +/** + * 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, { + browser: false, + hasCoreModules: false, + }); + const isCore = resolver.isCoreModule('assert'); + expect(isCore).toEqual(false); + }); + + it('returns true if `hasCoreModules` is false and `moduleName` is a core module.', () => { + const moduleMap = new ModuleMap(); + const resolver = new Resolver(moduleMap, { + browser: false, + }); + const isCore = resolver.isCoreModule('assert'); + expect(isCore).toEqual(true); + }); + + it('returns false if `hasCoreModules` is false and `moduleName` is not a core module.', () => { + const moduleMap = new ModuleMap(); + const resolver = new Resolver(moduleMap, { + browser: false, + }); + 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) ); } From 9c3d714bfb5c03b8fc92d42ba036e001ad8506e4 Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Fri, 24 Feb 2017 07:11:03 -0700 Subject: [PATCH 2/3] Fix typo. --- packages/jest-resolve/src/__test__/resolve-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-resolve/src/__test__/resolve-test.js b/packages/jest-resolve/src/__test__/resolve-test.js index 4eb23eac6b38..1815aadc1c7f 100644 --- a/packages/jest-resolve/src/__test__/resolve-test.js +++ b/packages/jest-resolve/src/__test__/resolve-test.js @@ -24,7 +24,7 @@ describe('isCoreModule', () => { expect(isCore).toEqual(false); }); - it('returns true if `hasCoreModules` is false and `moduleName` is a core module.', () => { + it('returns true if `hasCoreModules` is true and `moduleName` is a core module.', () => { const moduleMap = new ModuleMap(); const resolver = new Resolver(moduleMap, { browser: false, @@ -33,7 +33,7 @@ describe('isCoreModule', () => { expect(isCore).toEqual(true); }); - it('returns false if `hasCoreModules` is false and `moduleName` is not a core module.', () => { + it('returns false if `hasCoreModules` is true and `moduleName` is not a core module.', () => { const moduleMap = new ModuleMap(); const resolver = new Resolver(moduleMap, { browser: false, From df6a46ead1e7e5b7bc2783b43752074c23976a48 Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Fri, 24 Feb 2017 07:34:17 -0700 Subject: [PATCH 3/3] Remove `browser: false`. --- packages/jest-resolve/src/__test__/resolve-test.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/jest-resolve/src/__test__/resolve-test.js b/packages/jest-resolve/src/__test__/resolve-test.js index 1815aadc1c7f..2ee2826fe3eb 100644 --- a/packages/jest-resolve/src/__test__/resolve-test.js +++ b/packages/jest-resolve/src/__test__/resolve-test.js @@ -17,7 +17,6 @@ describe('isCoreModule', () => { it('returns false if `hasCoreModules` is false.', () => { const moduleMap = new ModuleMap(); const resolver = new Resolver(moduleMap, { - browser: false, hasCoreModules: false, }); const isCore = resolver.isCoreModule('assert'); @@ -26,18 +25,14 @@ describe('isCoreModule', () => { it('returns true if `hasCoreModules` is true and `moduleName` is a core module.', () => { const moduleMap = new ModuleMap(); - const resolver = new Resolver(moduleMap, { - browser: false, - }); + 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, { - browser: false, - }); + const resolver = new Resolver(moduleMap, {}); const isCore = resolver.isCoreModule('not-a-core-module'); expect(isCore).toEqual(false); });