diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b54edd13c71..c5744f75cd03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ - `[jest-resolve]` Fix not being able to resolve path to mapped file with custom platform ([#7312](https://github.com/facebook/jest/pull/7312)) - `[jest-message-util]` Improve parsing of error messages for unusually formatted stack traces ([#7319](https://github.com/facebook/jest/pull/7319)) - `[jest-runtime]` Ensure error message text is not lost on errors with code frames ([#7319](https://github.com/facebook/jest/pull/7319)) +- `[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 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); }