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 1 commit
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
44 changes: 44 additions & 0 deletions packages/jest-resolve/src/__test__/resolve-test.js
Original file line number Diff line number Diff line change
@@ -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.', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this doesn't make sense.

  • If hasCoreModules is true, it should return true if you pass in a core module. If it is false, it should return false when passing in a core module.
  • If hasCoreModule is true, it should return false if you pass in a non-core module. If it is false, it should always return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what it is doing? Should I have a test for hasCoreModule: false and isCore('non-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);
});
});
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