Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest-resolve] Use is-builtin-module instead of resolve.isCore. #2997

Merged
merged 3 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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