Skip to content

Commit

Permalink
fix(jest-resolve): don't confuse directories with files
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 8, 2019
1 parent 0935f7c commit 499e10a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- `[jest-fake-timers]` `getTimerCount` will not include cancelled immediates ([#8764](https://github.com/facebook/jest/pull/8764))
- `[jest-leak-detector]` [**BREAKING**] Use `weak-napi` instead of `weak` package ([#8686](https://github.com/facebook/jest/pull/8686))
- `[jest-mock]` Fix for mockReturnValue overriding mockImplementationOnce ([#8398](https://github.com/facebook/jest/pull/8398))
- `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912))
- `[jest-snapshot]` Remove only the added newlines in multiline snapshots ([#8859](https://github.com/facebook/jest/pull/8859))
- `[jest-snapshot]` Distinguish empty string from external snapshot not written ([#8880](https://github.com/facebook/jest/pull/8880))
- `[jest-snapshot]` [**BREAKING**] Distinguish empty string from internal snapshot not written ([#8898](https://github.com/facebook/jest/pull/8898))
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions packages/jest-resolve/src/__mocks__/foo/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. 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 = require.resolve('./');
Empty file.
1 change: 0 additions & 1 deletion packages/jest-resolve/src/__mocks__/userResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';
Expand Down
18 changes: 15 additions & 3 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as fs from 'fs';
import * as path from 'path';
import {ModuleMap} from 'jest-haste-map';
import Resolver from '../';
import Resolver = require('../');
// @ts-ignore: js file
import userResolver from '../__mocks__/userResolver';
import nodeModulesPaths from '../nodeModulesPaths';
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('findNodeModule', () => {
});

describe('resolveModule', () => {
let moduleMap: typeof ModuleMap;
let moduleMap: ModuleMap;
beforeEach(() => {
moduleMap = ModuleMap.create('/');
});
Expand Down Expand Up @@ -156,6 +156,18 @@ describe('resolveModule', () => {
});
expect(resolved).toBe(require.resolve('../__mocks__/mockJsDependency.js'));
});

it('does not confuse directories with files', () => {
const resolver = new Resolver(moduleMap, {
extensions: ['.js'],
} as ResolverConfig);
const mocksDirectory = path.resolve(__dirname, '../__mocks__');
const resolved = resolver.resolveModule(
path.join(mocksDirectory, 'foo/foo.js'),
'./',
);
expect(resolved).toBe(path.join(mocksDirectory, 'foo/index.js'));
});
});

describe('getMockModule', () => {
Expand Down Expand Up @@ -195,7 +207,7 @@ describe('nodeModulesPaths', () => {

describe('Resolver.getModulePaths() -> nodeModulesPaths()', () => {
const _path = path;
let moduleMap: typeof ModuleMap;
let moduleMap: ModuleMap;

beforeEach(() => {
jest.resetModules();
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/defaultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function resolveSync(
const dir = path.dirname(name);
let result;
if (isDirectory(dir)) {
result = resolveAsFile(name) || resolveAsDirectory(name);
result = resolveAsDirectory(name) || resolveAsFile(name);
}
if (result) {
// Dereference symlinks to ensure we don't create a separate
Expand Down

0 comments on commit 499e10a

Please sign in to comment.