-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
test_runner: use source maps when reporting coverage #52060
test_runner: use source maps when reporting coverage #52060
Conversation
Review requested:
|
e0d502c
to
326f7a0
Compare
326f7a0
to
e9dcde5
Compare
.findEntry(lines[lines.length - 1].line - 1, (endOffset - lines[lines.length - 1].startOffset) - 1); | ||
if (!startEntry.originalSource && endEntry.originalSource && | ||
lines[0].line === 1 && startOffset === 0 && lines[0].startOffset === 0) { | ||
// Edge case when the first line is not mappable |
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.
Why is the first line not mappable? It looks like there are a couple more "not mappable" comments. Do you know why they aren't mappable? If so, can it be included in the comments.
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.
what findEntry
does is a binary search for the first entry that appears in the source map after the line/column you request.
there are many cases where such an entry cannot be found (generated code doesn't always point to a source for various reasons - it might be a comment added by the build tool source maps exclude node_modules
, etc)
this specific edge case is important since v8 coverage will almost always have a range starting at the beginning of generating code ({line:0,col:0}
) until the end of the end of the file. since this range marks the count of for all top-level lines outside of a functions it is very important so I added a specific handling for it
node/lib/internal/source_map/source_map.js
Lines 190 to 220 in 1abff07
findEntry(lineOffset, columnOffset) { | |
let first = 0; | |
let count = this.#mappings.length; | |
while (count > 1) { | |
const step = count >> 1; | |
const middle = first + step; | |
const mapping = this.#mappings[middle]; | |
if (lineOffset < mapping[0] || | |
(lineOffset === mapping[0] && columnOffset < mapping[1])) { | |
count = step; | |
} else { | |
first = middle; | |
count -= step; | |
} | |
} | |
const entry = this.#mappings[first]; | |
if (!first && entry && (lineOffset < entry[0] || | |
(lineOffset === entry[0] && columnOffset < entry[1]))) { | |
return {}; | |
} else if (!entry) { | |
return {}; | |
} | |
return { | |
generatedLine: entry[0], | |
generatedColumn: entry[1], | |
originalSource: entry[2], | |
originalLine: entry[3], | |
originalColumn: entry[4], | |
name: entry[5], | |
}; | |
} |
Commit Queue failed- Loading data for nodejs/node/pull/52060 ✔ Done loading data for nodejs/node/pull/52060 ----------------------------------- PR info ------------------------------------ Title test_runner: use source maps when reporting coverage (#52060) Author Moshe Atlow (@MoLow) Branch MoLow:test-runner-coverage-use-source-maps -> nodejs:main Labels needs-ci, commit-queue-rebase, test_runner Commits 2 - test_runner: use source maps when reporting coverage - CR Committers 1 - Moshe Atlow PR-URL: https://github.com/nodejs/node/pull/52060 Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: Chemi Atlow ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/52060 Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: Chemi Atlow -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 12 Mar 2024 19:35:56 GMT ✔ Approvals: 3 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/52060#pullrequestreview-1932962596 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/52060#pullrequestreview-1935039694 ✔ - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/52060#pullrequestreview-1935240850 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-03-13T22:31:45Z: https://ci.nodejs.org/job/node-test-pull-request/57738/ - Querying data for job/node-test-pull-request/57738/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 52060 From https://github.com/nodejs/node * branch refs/pull/52060/merge -> FETCH_HEAD ✔ Fetched commits as b360532f1a38..9902bc5a26e5 -------------------------------------------------------------------------------- [main d74f9351de] test_runner: use source maps when reporting coverage Author: Moshe Atlow Date: Mon Mar 11 22:44:25 2024 +0200 11 files changed, 302 insertions(+), 118 deletions(-) create mode 100644 test/fixtures/test-runner/coverage/README.md create mode 100644 test/fixtures/test-runner/coverage/a.test.mjs create mode 100644 test/fixtures/test-runner/coverage/a.test.mjs.map create mode 100644 test/fixtures/test-runner/coverage/a.test.ts create mode 100644 test/fixtures/test-runner/coverage/b.test.ts create mode 100644 test/fixtures/test-runner/coverage/index.test.js create mode 100644 test/fixtures/test-runner/coverage/stdin.test.js create mode 100644 test/fixtures/test-runner/coverage/stdin.test.js.map [main 0c669f7030] CR Author: Moshe Atlow Date: Wed Mar 13 21:17:38 2024 +0200 3 files changed, 3 insertions(+), 5 deletions(-) ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. Rebasing (2/4)https://github.com/nodejs/node/actions/runs/8286634396 |
Landed in 814fa1a |
PR-URL: nodejs#52060 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
@MoLow should the source map limitation in the docs be removed after this change? |
PR-URL: #52060 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
PR-URL: #52060 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
PR-URL: nodejs#52060 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
No description provided.