Skip to content

Commit

Permalink
Properly resolve mocked node modules without package.json defined (#6232
Browse files Browse the repository at this point in the history
)

* Properly resolve mocked node modules without package.json defined

* update changelog

* lint md
  • Loading branch information
thymikee authored and cpojer committed May 24, 2018
1 parent 8c71f9d commit 73a656d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
regardless of order ([#6150](https://github.com/facebook/jest/pull/6150))
* `[pretty-format]` [**BREAKING**] Remove undefined props from React elements
([#6162](https://github.com/facebook/jest/pull/6162))
* `[jest-haste-map]` Properly resolve mocked node modules without package.json
defined ([#6232](https://github.com/facebook/jest/pull/6232))

### Chore & Maintenance

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = 'test mock-module-without-pkg';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
jest.mock('mock-module');
jest.mock('mock-module-alt');
jest.mock('mock-jsx-module');
jest.mock('mock-module-without-pkg');

it('should resolve entry as index.js when package main is "."', () => {
const mockModule = require('mock-module');
Expand All @@ -25,3 +26,8 @@ it('should resolve entry as index with other configured module file extension wh
const mockJsxModule = require('mock-jsx-module');
expect(mockJsxModule).toEqual('test jsx');
});

it('should resolve entry as index without package.json', () => {
const mockModuleWithoutPkg = require('mock-module-without-pkg');
expect(mockModuleWithoutPkg).toEqual('test mock-module-without-pkg');
});
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/module_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class ModuleMap {
}

getMockModule(name: string): ?Path {
return this._raw.mocks[name];
return this._raw.mocks[name] || this._raw.mocks[name + '/index'];
}

getRawModuleMap(): RawModuleMap {
Expand Down

0 comments on commit 73a656d

Please sign in to comment.