From 402f4fec7e2b69b6757b81d6fbaff3dca447c82f Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 23 Apr 2023 03:17:49 -0400 Subject: [PATCH] test_runner: support coverage of unnamed functions This commit updates the code coverage logic to skip the first function in a file (which does not correspond to an actual function) instead of skipping all functions without a name. PR-URL: https://github.com/nodejs/node/pull/47652 Reviewed-By: Moshe Atlow Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum --- lib/internal/test_runner/coverage.js | 4 ++-- test/fixtures/test-runner/coverage.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 8bcc053414ca42..12dcb1da9866a4 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -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]; @@ -172,7 +172,7 @@ class TestCoverage { } } - if (functionName.length > 0 && ranges.length > 0) { + if (j > 0 && ranges.length > 0) { const range = ranges[0]; if (range.count !== 0 || range.ignoredLines === range.lines.length) { diff --git a/test/fixtures/test-runner/coverage.js b/test/fixtures/test-runner/coverage.js index 002e295deb99ba..afb26d40412a1c 100644 --- a/test/fixtures/test-runner/coverage.js +++ b/test/fixtures/test-runner/coverage.js @@ -29,7 +29,7 @@ if (false) { require('./invalid-tap.js'); } -test('a test', function testHandler() { +test('a test', () => { const uncalled = () => {}; function fnWithControlFlow(val) {