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 4, 2019
1 parent 8e0786f commit c7cacfb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,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
- `[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.
1 change: 1 addition & 0 deletions packages/jest-resolve/src/__mocks__/foo/foo.js
@@ -0,0 +1 @@
module.exports = require.resolve('./');
Empty file.
18 changes: 15 additions & 3 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
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
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 c7cacfb

Please sign in to comment.