From 013b87b269f072e704cd4f30a2e04e3b6f4cd450 Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Sat, 3 Nov 2018 01:55:11 +0900 Subject: [PATCH 1/2] fix: get relative path in haste map --- .../jest-haste-map/src/lib/__tests__/fast_path.test.js | 7 +++++++ packages/jest-haste-map/src/lib/fast_path.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/jest-haste-map/src/lib/__tests__/fast_path.test.js b/packages/jest-haste-map/src/lib/__tests__/fast_path.test.js index d6872fec82de..5eaae66edb0d 100644 --- a/packages/jest-haste-map/src/lib/__tests__/fast_path.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/fast_path.test.js @@ -26,6 +26,13 @@ describe('fastPath.relative', () => { const relativeFilename = path.join('..', 'baz', 'foobar'); expect(relative(root, filename)).toBe(relativeFilename); }); + + it('should get relative paths outside the root when start with same word', () => { + const root = path.join(__dirname, 'foo', 'bar'); + const filename = path.join(__dirname, 'foo', 'barbaz', 'foobar'); + const relativeFilename = path.join('..', 'barbaz', 'foobar'); + expect(relative(root, filename)).toBe(relativeFilename); + }); }); describe('fastPath.resolve', () => { diff --git a/packages/jest-haste-map/src/lib/fast_path.js b/packages/jest-haste-map/src/lib/fast_path.js index f161ae48bf9e..1f05b4ffb0cc 100644 --- a/packages/jest-haste-map/src/lib/fast_path.js +++ b/packages/jest-haste-map/src/lib/fast_path.js @@ -11,7 +11,7 @@ import path from 'path'; // rootDir and filename must be absolute paths (resolved) export function relative(rootDir: string, filename: string): string { - return filename.indexOf(rootDir) === 0 + return filename.indexOf(rootDir + path.sep) === 0 ? filename.substr(rootDir.length + 1) : path.relative(rootDir, filename); } From 3c834a5b77afb80c834ca5d42980c5daef297206 Mon Sep 17 00:00:00 2001 From: yamatatsu Date: Sat, 3 Nov 2018 12:27:22 +0900 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9eeb537f3c..e55357d2e62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ - `[expect]` Improves the failing message for `toStrictEqual` matcher. ([#7224](https://github.com/facebook/jest/pull/7224)) - `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381)) - `[jest-resolve]` Fix not being able to resolve path to mapped file with custom platform ([#7312](https://github.com/facebook/jest/pull/7312)) +- `[jest-haste-map]` Fix to resolve path that is start with words same as rootDir ([#7324](https://github.com/facebook/jest/pull/7324)) ### Chore & Maintenance