Skip to content

Commit 499e10a

Browse files
committed
fix(jest-resolve): don't confuse directories with files
1 parent 0935f7c commit 499e10a

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- `[jest-fake-timers]` `getTimerCount` will not include cancelled immediates ([#8764](https://github.com/facebook/jest/pull/8764))
2929
- `[jest-leak-detector]` [**BREAKING**] Use `weak-napi` instead of `weak` package ([#8686](https://github.com/facebook/jest/pull/8686))
3030
- `[jest-mock]` Fix for mockReturnValue overriding mockImplementationOnce ([#8398](https://github.com/facebook/jest/pull/8398))
31+
- `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912))
3132
- `[jest-snapshot]` Remove only the added newlines in multiline snapshots ([#8859](https://github.com/facebook/jest/pull/8859))
3233
- `[jest-snapshot]` Distinguish empty string from external snapshot not written ([#8880](https://github.com/facebook/jest/pull/8880))
3334
- `[jest-snapshot]` [**BREAKING**] Distinguish empty string from internal snapshot not written ([#8898](https://github.com/facebook/jest/pull/8898))

packages/jest-resolve/src/__mocks__/foo.js

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
module.exports = require.resolve('./');

packages/jest-resolve/src/__mocks__/foo/index.js

Whitespace-only changes.

packages/jest-resolve/src/__mocks__/userResolver.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
76
*/
87

98
'use strict';

packages/jest-resolve/src/__tests__/resolve.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import * as fs from 'fs';
1010
import * as path from 'path';
1111
import {ModuleMap} from 'jest-haste-map';
12-
import Resolver from '../';
12+
import Resolver = require('../');
1313
// @ts-ignore: js file
1414
import userResolver from '../__mocks__/userResolver';
1515
import nodeModulesPaths from '../nodeModulesPaths';
@@ -83,7 +83,7 @@ describe('findNodeModule', () => {
8383
});
8484

8585
describe('resolveModule', () => {
86-
let moduleMap: typeof ModuleMap;
86+
let moduleMap: ModuleMap;
8787
beforeEach(() => {
8888
moduleMap = ModuleMap.create('/');
8989
});
@@ -156,6 +156,18 @@ describe('resolveModule', () => {
156156
});
157157
expect(resolved).toBe(require.resolve('../__mocks__/mockJsDependency.js'));
158158
});
159+
160+
it('does not confuse directories with files', () => {
161+
const resolver = new Resolver(moduleMap, {
162+
extensions: ['.js'],
163+
} as ResolverConfig);
164+
const mocksDirectory = path.resolve(__dirname, '../__mocks__');
165+
const resolved = resolver.resolveModule(
166+
path.join(mocksDirectory, 'foo/foo.js'),
167+
'./',
168+
);
169+
expect(resolved).toBe(path.join(mocksDirectory, 'foo/index.js'));
170+
});
159171
});
160172

161173
describe('getMockModule', () => {
@@ -195,7 +207,7 @@ describe('nodeModulesPaths', () => {
195207

196208
describe('Resolver.getModulePaths() -> nodeModulesPaths()', () => {
197209
const _path = path;
198-
let moduleMap: typeof ModuleMap;
210+
let moduleMap: ModuleMap;
199211

200212
beforeEach(() => {
201213
jest.resetModules();

packages/jest-resolve/src/defaultResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function resolveSync(
9797
const dir = path.dirname(name);
9898
let result;
9999
if (isDirectory(dir)) {
100-
result = resolveAsFile(name) || resolveAsDirectory(name);
100+
result = resolveAsDirectory(name) || resolveAsFile(name);
101101
}
102102
if (result) {
103103
// Dereference symlinks to ensure we don't create a separate

0 commit comments

Comments
 (0)