Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-resolve): don't confuse directories with files #8912

Merged
merged 5 commits into from Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/package.json
Expand Up @@ -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",
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions 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('./');
Empty file.
14 changes: 14 additions & 0 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Expand Up @@ -156,6 +156,20 @@ describe('resolveModule', () => {
});
expect(resolved).toBe(require.resolve('../__mocks__/mockJsDependency.js'));
});

it('does not confuse directories with files', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests for '..'?

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', () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -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"

Expand Down