Skip to content

Commit

Permalink
[jest-resolve] Use is-builtin-module instead of resolve.isCore. (j…
Browse files Browse the repository at this point in the history
…estjs#2997)

* Use `is-builtin-module` instead of `resolve.isCore`.

* Fix typo.

* Remove `browser: false`.
  • Loading branch information
wtgtybhertgeghgtwtg authored and cpojer committed Feb 24, 2017
1 parent 36fddb6 commit 37a36ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/jest-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
39 changes: 39 additions & 0 deletions packages/jest-resolve/src/__test__/resolve-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 2 additions & 4 deletions packages/jest-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -177,10 +178,7 @@ class Resolver {
isCoreModule(moduleName: string): boolean {
return (
this._options.hasCoreModules &&
(
resolve.isCore(moduleName) ||
moduleName === 'v8'
)
isBuiltinModule(moduleName)
);
}

Expand Down

0 comments on commit 37a36ea

Please sign in to comment.