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: get relative path in haste map #7324

Merged
merged 3 commits into from
Nov 3, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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