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 1 commit
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
Next Next commit
fix: get relative path in haste map
  • Loading branch information
yamatatsu committed Nov 2, 2018
commit 013b87b269f072e704cd4f30a2e04e3b6f4cd450
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