diff --git a/CHANGELOG.md b/CHANGELOG.md index e568389dd809..28febfd7b5d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495)) - `[jest-matcher-utils]` Fix diff highlight of symbol-keyed object. ([#9499](https://github.com/facebook/jest/pull/9499)) - `[jest-resolve]` Fix module identity preservation with symlinks and browser field resolution ([#9511](https://github.com/facebook/jest/pull/9511)) +- `[jest-resolve]` Do not confuse directories with files ([#8912](https://github.com/facebook/jest/pull/8912)) - `[jest-snapshot]` Downgrade semver to v6 to support node 8 ([#9451](https://github.com/facebook/jest/pull/9451)) - `[jest-transform]` Correct sourcemap behavior for transformed and instrumented code ([#9460](https://github.com/facebook/jest/pull/9460)) - `[pretty-format]` Export `OldPlugin` type ([#9491](https://github.com/facebook/jest/pull/9491)) diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index c0b9da1a3b92..703f5f4522ed 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -15,7 +15,7 @@ "chalk": "^3.0.0", "jest-pnp-resolver": "^1.2.1", "realpath-native": "^2.0.0", - "resolve": "^1.15.0" + "resolve": "^1.15.1" }, "devDependencies": { "@types/browser-resolve": "^0.0.5", 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..77aec8db294a --- /dev/null +++ b/packages/jest-resolve/src/__mocks__/foo/foo.js @@ -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('./'); 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 077bd6513d8d..4d8d174385a7 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -156,6 +156,20 @@ 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 fooSlashFoo = path.join(mocksDirectory, 'foo/foo.js'); + const fooSlashIndex = path.join(mocksDirectory, 'foo/index.js'); + + const resolvedWithSlash = resolver.resolveModule(fooSlashFoo, './'); + const resolvedWithDot = resolver.resolveModule(fooSlashFoo, '.'); + expect(resolvedWithSlash).toBe(fooSlashIndex); + expect(resolvedWithSlash).toBe(resolvedWithDot); + }); }); describe('getMockModule', () => { diff --git a/yarn.lock b/yarn.lock index ea4eabb91a2b..a919a89f2ffd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12567,10 +12567,10 @@ resolve@1.1.7: resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= -resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.15.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.8.1: - version "1.15.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.0.tgz#1b7ca96073ebb52e741ffd799f6b39ea462c67f5" - integrity sha512-+hTmAldEGE80U2wJJDC1lebb5jWqvTYAfm3YZ1ckk1gBr0MnCqUKlwK1e+anaFljIl+F5tR5IoZcm4ZDA1zMQw== +resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.15.0, resolve@^1.15.1, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.8.1: + version "1.15.1" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8" + integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w== dependencies: path-parse "^1.0.6"