diff --git a/CHANGELOG.md b/CHANGELOG.md index fc78d401485a..a6b02d41c295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/packages/jest-resolve/src/__mocks__/foo.js b/packages/jest-resolve/src/__mocks__/foo.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-resolve/src/__mocks__/foo/foo.js b/packages/jest-resolve/src/__mocks__/foo/foo.js new file mode 100644 index 000000000000..a00eaefb11b2 --- /dev/null +++ b/packages/jest-resolve/src/__mocks__/foo/foo.js @@ -0,0 +1 @@ +module.exports = require.resolve('./'); diff --git a/packages/jest-resolve/src/__mocks__/foo/index.js b/packages/jest-resolve/src/__mocks__/foo/index.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index c136ba0e5c6d..35893cf512ab 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -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'; @@ -83,7 +83,7 @@ describe('findNodeModule', () => { }); describe('resolveModule', () => { - let moduleMap: typeof ModuleMap; + let moduleMap: ModuleMap; beforeEach(() => { moduleMap = ModuleMap.create('/'); }); @@ -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', () => { @@ -195,7 +207,7 @@ describe('nodeModulesPaths', () => { describe('Resolver.getModulePaths() -> nodeModulesPaths()', () => { const _path = path; - let moduleMap: typeof ModuleMap; + let moduleMap: ModuleMap; beforeEach(() => { jest.resetModules(); diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index 44f66d6e8ee6..131234b8ca10 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -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