-
Notifications
You must be signed in to change notification settings - Fork 17
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: use correct highlight offset even when rootDir is not root package directory #34
Conversation
When the Jest rootDir is not the same as the package's root directory (i.e., a monorepo scenario with multiple local Jest configs) the highlight function incorrectly calculates the offset for highlighting file name matches, resulting in a highlight in the wrong place. This only occurs when filePath is not truncated.
This change fixes the failing test by moving the offset calculation out of the conditional and calculating it the same way in all scenarios using rawPath and filePath.
Since highlight no longer needs rootDir to calculate the highlight offset, this change removes rootDir from highlight's parameters. It also updates tests to use inline snapshots now that there are fewer scenarios to account for.
Do we do any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very sorry this was lying around so long, just came across it deep in my inbox.
Tried this on a random workspace project I have, seems to work. Code also LGTM. Another review, perhaps from @rogeliog, would be nice though to maybe understand why this was there in the first place.
Just commenting to see if we can keep things moving on this! |
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. If it breaks a use case we're not aware of, we can then add another test and make it work for both cases
@wilsonparson I ran into this same issue while attempting to add |
@joshdegouveia thanks for the nudge! I just resolved the conflicts. Hopefully this fix resolves the issue you're having as well! |
The changes in this PR allow us to remove the rootDir param from the highlight function. I forgot to remove it from the function declaration and it was causing type checking to fail.
@wilsonparson thank you! I appreciate it 😄 Yeah it looks like it's the same issue - thanks for putting this fix together! @thymikee If this PR looks good - could you merge it? |
This may have caused #46 |
When a Jest config's
rootDir
is not the same directory as the root package directory (e.g., a monorepo with local Jest configs for each library or app), the highlight offset is calculated incorrectly because it assumesrootDir
is the root directory of the package. This only occurs when thefilePath
is not truncated (i.e., does not have a leading'...'
):This PR updates the offset calculation to rely on
rawPath
andfilePath
instead ofrootDir
to provide a consistent highlight offset regardless ofrootDir
's location:The PR includes three commits:
highlight
function, removing therootDir
parameter since it is no longer being used