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

Fix package main resolving issue #5344

Merged
merged 5 commits into from
Jan 19, 2018
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## master

### Fixes

* `[jest-resolve]` Add condition to avoid infinite loop when node module package main is ".".
([#5344)](https://github.com/facebook/jest/pull/5344)

### Features
* `[jest-cli]` `--changedSince`: allow selectively running tests for code
changed since arbitrary revisions.
Expand Down
16 changes: 16 additions & 0 deletions integration-tests/__tests__/resolve-node-module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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.
*
* @flow
*/
'use strict';

const runJest = require('../runJest');

test('resolve node module', () => {
const result = runJest('resolve-node-module');
expect(result.status).toBe(0);
});
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 jsx';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "mock-jsx-module",
"main": "."
}
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "mock-module",
"main": "."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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.
*/

'use strict';

jest.mock('mock-module');
jest.mock('mock-jsx-module');

it('should resolve entry as index.js when package main is "."', () => {
const mockModule = require('mock-module');
expect(mockModule).toEqual('test');
});

it('should resolve entry as index with other configured module file extention when package main is "."', () => {
const mockJsxModule = require('mock-jsx-module');
expect(mockJsxModule).toEqual('test jsx');
});
6 changes: 6 additions & 0 deletions integration-tests/resolve-node-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"moduleFileExtensions": ["js", "json", "jsx"],
"testEnvironment": "node"
}
}
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/default_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function resolveSync(target: Path, options: ResolverOptions): Path {
pkgmain = JSON.parse(body).main;
} catch (e) {}

if (pkgmain) {
if (pkgmain && pkgmain !== '.') {
const resolveTarget = path.resolve(name, pkgmain);
const result = tryResolve(resolveTarget);
if (result) {
Expand Down