fix: add missing code coverage ranges that span only a single character #8911
+19
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bugfix
Summary
This change fixes an issue in the JavaScript code coverage collection algorithm that, under specific circumstances, can lead to incomplete coverage data.
The existing algorithm filtered out code coverage range results that spanned a single character, perhaps in the assumption that such characters could only represent trivia tokens. This is safe when such tokens represented whitespace, or newline trivia, but unfortunately it also had the effect of filtering out valid semantic tokens as well, such as the ternary operators
?
/:
.Furthermore, this particular implementation meant that the resulting output of an otherwise repeatable code-coverage run would differ between manual collection via Chrome Dev Tools, and automated collection via Puppeteer, since the former would correctly include such single-character tokens, and the latter would not.
Links/Issues
While this fix was not introduced explicitly to solve for the following issue, a quick search yielded this existing report, and I believe that this may solve for the reported issue (or perhaps at least inform anybody following the issue for a thread to pull on):
Does this PR introduce a breaking change?
This fix introduces a change in behavior to how we collect coverage ranges. Previously, coverage ranges of a single character length were elided entirely from the coverage output. With this change, those ranges are not ignored, and are included in the resulting coverage output.
From the perspective of consumers, anybody relying on consistent output of coverage ranges from this algorithm (ex. unit tests that rely upon cached or saved copies of coverage data) will need to update their expectations to match these changes accordingly - in essence, consumers should now expect that trivia tokens (like newlines), or more importantly single-token operators (like the ternary false operator
:
) will be included as part of the coverage output. This aligns with the expected output of Chrome's code coverage tooling in Dev Tools.Other information
Please feel free to reach out if there are any questions, and I'll be happy to provide further help or input as needed; I really appreciate all the hard work this team does in providing such an invaluable product!