Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test_runner: support coverage of unnamed functions #47652

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestCoverage {
});

for (let j = 0; j < functions.length; ++j) {
const { functionName, isBlockCoverage, ranges } = functions[j];
const { isBlockCoverage, ranges } = functions[j];

for (let k = 0; k < ranges.length; ++k) {
const range = ranges[k];
Expand All @@ -172,7 +172,7 @@ class TestCoverage {
}
}

if (functionName.length > 0 && ranges.length > 0) {
if (j > 0 && ranges.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

is this also correct in the case of ESM?

Copy link
Member

Choose a reason for hiding this comment

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

i have the same question; CJS is wrapped in a function but i don't expect ESM to be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I thought maybe it was a CJS specific thing, but it's not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    {
      "scriptId": "422",
      "url": "file:///Users/cjihrig/iojs/node/test.mjs",
      "functions": [
        {
          "functionName": "",
          "ranges": [
            {
              "startOffset": 0,
              "endOffset": 4462,
              "count": 1
            }
          ],
          "isBlockCoverage": true
        },
        {
          "functionName": "chickenSandwich",
          "ranges": [
            {
              "startOffset": 49,
              "endOffset": 80,
              "count": 1
            }
          ],
          "isBlockCoverage": true
        }
      ]
    },

Copy link
Member

Choose a reason for hiding this comment

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

weird, is that something added by v8, or by node's esm implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That part is unclear to me.

const range = ranges[0];

if (range.count !== 0 || range.ignoredLines === range.lines.length) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (false) {
require('./invalid-tap.js');
}

test('a test', function testHandler() {
test('a test', () => {
const uncalled = () => {};

function fnWithControlFlow(val) {
Expand Down