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: calculate highlight offset using stripped paths #48

Merged
merged 10 commits into from
Apr 23, 2021

Conversation

wilsonparson
Copy link
Contributor

This is a potential fix to #46.

I'm working on a way to make the tests more accurate so that they'll actually fail when the highlight placement is incorrect. Even though I've been able to visually confirm that this one-line change seems to resolve the issue, the unit tests I've included pass both with and without the change, so they're not useful until I can pass an ANSI-formatted string (done by chalk) as the filePath parameter to the highlight function. It does work to just console.log an actual filePath that was formatted by chalk, and then use that as the file path in tests, but the hard-coded string is cluttered with ANSI codes and is really confusing 😅

As a side note, I figured out what went wrong with #34. It looks like when I resolved merge conflicts from #41 I missed the name change of rawPath and filePath to strippedRawPath and strippedFilePath. The tests still passed because they were already passing stripped strings as the filePath parameter.

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.
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.
Uses separate test functions and inline snapshots to make tests
easier to reason about.
@jeysal
Copy link
Member

jeysal commented Apr 14, 2021

Thanks, let us know once this is out of draft status

@wilsonparson wilsonparson marked this pull request as ready for review April 23, 2021 05:58
@wilsonparson
Copy link
Contributor Author

@jeysal Ready for review 🙏

@SimenB SimenB requested a review from jeysal April 23, 2021 06:32
Copy link
Member

@jeysal jeysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with the 'repro' from #46 and seems to fix it 👍

@jeysal jeysal requested a review from SimenB April 23, 2021 11:47
@SimenB SimenB merged commit b5dd0f5 into jest-community:master Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants