Skip to content

Commit

Permalink
fix: get relative path in haste map (#7324)
Browse files Browse the repository at this point in the history
* fix: get relative path in haste map

* CHANGELOG
  • Loading branch information
yamatatsu authored and SimenB committed Nov 3, 2018
1 parent f2b51c1 commit 9812e1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions packages/jest-haste-map/src/lib/__tests__/fast_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/lib/fast_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9812e1b

Please sign in to comment.