From fb1298db630d7654710426c8e253059b3c4bd0d1 Mon Sep 17 00:00:00 2001 From: Aliaksei Sapach Date: Thu, 30 Aug 2018 20:46:01 +0300 Subject: [PATCH 1/2] jest-resolve - only resolve realpath once in try-catch fixes #6880 --- .../jest-resolve/src/__tests__/resolve.test.js | 5 +++-- .../jest-resolve/src/node_modules_paths.js | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/jest-resolve/src/__tests__/resolve.test.js b/packages/jest-resolve/src/__tests__/resolve.test.js index acb73929ef9a..05586429d763 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.js +++ b/packages/jest-resolve/src/__tests__/resolve.test.js @@ -134,8 +134,9 @@ describe('resolveModule', () => { const resolver = new Resolver(moduleMap, { extensions: ['.js'], }); - const src = require.resolve( - '../../src/__mocks__/bar/node_modules/foo/index.js', + const src = path.join( + path.resolve(__dirname, '../../src/__mocks__/bar/node_modules/'), + 'foo/index.js', ); const resolved = resolver.resolveModule(src, 'dep'); expect(resolved).toBe( diff --git a/packages/jest-resolve/src/node_modules_paths.js b/packages/jest-resolve/src/node_modules_paths.js index 88654b0a970e..84cb68a2c3fb 100644 --- a/packages/jest-resolve/src/node_modules_paths.js +++ b/packages/jest-resolve/src/node_modules_paths.js @@ -38,17 +38,21 @@ export default function nodeModulesPaths( prefix = '\\\\'; } - // The node resolution algorithm (as implemented by NodeJS - // and TypeScript) traverses parents of the physical path, - // not the symlinked path - const physicalBasedir = realpath(basedirAbs); + // The node resolution algorithm (as implemented by NodeJS and TypeScript) + // traverses parents of the physical path, not the symlinked path + let physicalBasedir; + try { + physicalBasedir = realpath(basedirAbs); + } catch (err) { + // realpath can throw, e.g. on mapped drives + physicalBasedir = basedirAbs; + } const paths = [physicalBasedir]; let parsed = path.parse(physicalBasedir); while (parsed.dir !== paths[paths.length - 1]) { - const realParsedDir = realpath(parsed.dir); - paths.push(realParsedDir); - parsed = path.parse(realParsedDir); + paths.push(parsed.dir); + parsed = path.parse(parsed.dir); } const dirs = paths From ed56111dc21b03c7269a4c7c62c3f073f9694f78 Mon Sep 17 00:00:00 2001 From: Aliaksei Sapach Date: Thu, 30 Aug 2018 21:18:29 +0300 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d9634cf995f..53c3b50f6658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes +- `[jest-resolve]` Only resolve realpath once in try-catch ([#6925](https://github.com/facebook/jest/pull/6925)) - `[expect]` Fix TypeError in `toBeInstanceOf` on `null` or `undefined` ([#6912](https://github.com/facebook/jest/pull/6912)) - `[jest-jasmine2]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917)) - `[jest-circus]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917))