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

test_runner: use source maps when reporting coverage #52060

Merged

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Mar 12, 2024

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Mar 12, 2024
@MoLow MoLow force-pushed the test-runner-coverage-use-source-maps branch from e0d502c to 326f7a0 Compare March 12, 2024 19:36
@MoLow MoLow changed the title test_runner: use report coverage with source maps test_runner: use source maps when reporting coverage Mar 12, 2024
@MoLow MoLow force-pushed the test-runner-coverage-use-source-maps branch from 326f7a0 to e9dcde5 Compare March 12, 2024 19:42
test/parallel/test-runner-coverage.js Outdated Show resolved Hide resolved
test/parallel/test-runner-coverage.js Outdated Show resolved Hide resolved
test/parallel/test-runner-coverage.js Outdated Show resolved Hide resolved
test/fixtures/test-runner/coverage/README.md Outdated Show resolved Hide resolved
lib/internal/test_runner/coverage.js Outdated Show resolved Hide resolved
.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
Copy link
Contributor

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.

Copy link
Member Author

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

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],
};
}

@MoLow MoLow added the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Mar 13, 2024
@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 13, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 13, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@MoLow MoLow added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 13, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 14, 2024
@nodejs-github-bot
Copy link
Collaborator

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)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
test_runner: use source maps when reporting coverage

PR-URL: #52060
Reviewed-By: Colin Ihrig [email protected]
Reviewed-By: Benjamin Gruenbaum [email protected]
Reviewed-By: Chemi Atlow [email protected]

[detached HEAD 35522c3a19] test_runner: use source maps when reporting coverage
Author: Moshe Atlow [email protected]
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
Rebasing (3/4)
Rebasing (4/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
CR

PR-URL: #52060
Reviewed-By: Colin Ihrig [email protected]
Reviewed-By: Benjamin Gruenbaum [email protected]
Reviewed-By: Chemi Atlow [email protected]

[detached HEAD fd85539ccb] CR
Author: Moshe Atlow [email protected]
Date: Wed Mar 13 21:17:38 2024 +0200
3 files changed, 3 insertions(+), 5 deletions(-)

Successfully rebased and updated refs/heads/main.

✔ 35522c3a19f76b26b91d85d41b1f5779ecef0686
✔ 0:0 no Co-authored-by metadata co-authored-by-is-trailer
✔ 0:0 skipping fixes-url fixes-url
✔ 0:0 blank line after title line-after-title
✔ 0:0 line-lengths are valid line-length
✔ 0:0 metadata is at end of message metadata-end
✔ 1:8 PR-URL is valid. pr-url
✔ 0:0 reviewers are valid reviewers
✔ 0:0 valid subsystems subsystem
✔ 0:0 Title is formatted correctly. title-format
⚠ 0:50 Title should be <= 50 columns. title-length
✖ fd85539ccb3aae21a0de6a17d42c11a62ab7f557
✔ 0:0 no Co-authored-by metadata co-authored-by-is-trailer
✔ 0:0 skipping fixes-url fixes-url
✔ 0:0 blank line after title line-after-title
✔ 0:0 line-lengths are valid line-length
✔ 0:0 metadata is at end of message metadata-end
✔ 1:8 PR-URL is valid. pr-url
✔ 0:0 reviewers are valid reviewers
✖ 0:0 Missing subsystem. subsystem
✔ 0:0 Title is formatted correctly. title-format
✔ 0:0 Title is <= 50 columns. title-length

ℹ Please fix the commit message and try again.
Please manually ammend the commit message, by running
git commit --amend
Once commit message is fixed, finish the landing command running
git node land --continue

https://github.com/nodejs/node/actions/runs/8286634396

@MoLow MoLow added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Mar 15, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 15, 2024
@nodejs-github-bot nodejs-github-bot merged commit 814fa1a into nodejs:main Mar 15, 2024
67 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 814fa1a

@MoLow MoLow deleted the test-runner-coverage-use-source-maps branch March 15, 2024 06:36
rdw-msft pushed a commit to rdw-msft/node that referenced this pull request Mar 26, 2024
PR-URL: nodejs#52060
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
@cjihrig
Copy link
Contributor

cjihrig commented Apr 12, 2024

@MoLow should the source map limitation in the docs be removed after this change?

marco-ippolito pushed a commit that referenced this pull request May 2, 2024
PR-URL: #52060
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
marco-ippolito pushed a commit that referenced this pull request May 3, 2024
PR-URL: #52060
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
jcbhmr pushed a commit to jcbhmr/node that referenced this pull request May 15, 2024
PR-URL: nodejs#52060
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants