镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

--experimental-test-coverage throws error: "TypeError: Cannot read properties of undefined (reading 'line')" #51552

Description

@nicusorflorin

Version

v20.11.0

Platform

Linux MyPC 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

  1. Create a few basic tests
  2. Run them with the command NODE_V8_COVERAGE=./coverage node --test --test-reporter=junit --test-reporter-destination=results.xml --experimental-test-coverage -r ts-node/register test/**/*.spec.ts

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

Should generate proper coverage

What do you see instead?

content of results.xml:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
	<testsuite name="TestSuite1Name" time="0.016595" disabled="0" errors="0" tests="3" failures="0" skipped="0" hostname="MyPC">
		<testcase name="test name 1" time="0.007770" classname="test"/>
		<testcase name="test name 2" time="0.002685" classname="test"/>
		<testcase name="test name 3" time="0.001173" classname="test"/>
	</testsuite>
	<testsuite name="TestSuite2Name" time="0.013062" disabled="0" errors="0" tests="1" failures="0" skipped="0" hostname="MyPC">
		<testcase name="test name 1" time="0.007652" classname="test"/>
	</testsuite>
	<!-- Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading 'line') -->
	<!-- tests 4 -->
	<!-- suites 2 -->
	<!-- pass 4 -->
	<!-- fail 0 -->
	<!-- cancelled 0 -->
	<!-- skipped 0 -->
	<!-- todo 0 -->
	<!-- duration_ms 4851.507124 -->
</testsuites>

Additional information

No response

Activity

  1. MoLow commented on Jan 23, 2024

    @MoLow
    Member

    Unfortunately, this is a known limitation, and source maps are not currently supported: https://nodejs.org/api/test.html#limitations
    PR's fixing this are more than welcome

  2. MoLow commented on Jan 23, 2024

    @MoLow
    Member

    closed as duplicate of #51392

  3. added
    test_runnerIssues and PRs related to the test runner subsystem.
    on Jan 23, 2024
  4. ddurschlag commented on Apr 12, 2024

    @ddurschlag

    @MoLow Are you sure this is a sourcemap issue? I've run into the same thing, and it's fixed by putting an arbitrary import at the top of the file. It seems like the test runner (or coverage collector?) is failing in some way when a module has exports but no imports. Sourcemapping doesn't seem to be involved.

    Edit: I've investigated further, and this seems to be file-length related. Adding meaningless comments to the file can make it work/not work. In my testing, I hit upon a 113/114 border: if the file is 113 bytes or fewer, it appears to fail, while 114 bytes or greater seems to succeed. I can make coverage succeed/fail by removing/re-adding a leading newline in the file. Here is a 114 byte file that coverage works for, but removing any single byte will cause it to fail in my testing:

    export function sayHello () {
      console.log('Hello, Console!');
    }
    // These chars are here to get to 114 bytesxxxxx
    

    Note there can be no trailing newline and this will work. Removing an x (or any other character) will make it fail.

    Replacing one of the final xes with a trailing newline oddly doesn't work -- but replacing it with 2 newlines does, making the minimum size 115 bytes at that point. I do not know what influences the byte-floor.

    Node version is v20.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions