Skip to content

Can't use with --experimental-test-coverage --test #437

@gjuchault

Description

@gjuchault

Acknowledgements

  • I searched existing issues before opening this one to avoid duplicates
  • I understand this is not a place for seek help, but to report a bug
  • I understand that the bug must be proven first with a minimal reproduction
  • I will be polite, respectful, and considerate of people's time and effort

Minimal reproduction URL

https://codesandbox.io/p/devbox/tsx-import-coverage-dkkgs3

I had to use codesandbox to have recent node version, you need local reproduction:

package.json
{
  "name": "nodejs-sandbox",
  "scripts": {
    "start": "npm run test-a || npm run test-b || npm run test-c || npm run test-d",
    "test-a": "tsx --experimental-test-coverage --test index.test.ts",
    "test-b": "NODE_OPTIONS='--import tsx' node --experimental-test-coverage --test index.test.ts",
    "test-c": "NODE_V8_COVERAGE=./coverage c8 -r html tsx --experimental-test-coverage --test index.test.ts",
    "test-d": "NODE_OPTIONS='--import tsx' NODE_V8_COVERAGE=./coverage c8 -r html node --experimental-test-coverage --test index.test.ts"
  },
  "devDependencies": {
    "c8": "^8.0.1",
    "tsx": "^4.6.2"
  }
}
index.test.ts
import { describe, it } from "node:test";
import * as assert from "node:assert/strict";

describe("case", () => {
  it("works", () => {
    assert.equal(1, 1);
  });
});

Version

4.6.2

Node.js version

v20+

Package manager

npm

Operating system

Linux

Problem & Expected behavior

I'm trying to get tsx to work with the native test runner, coverage included
It seems to be failing with the following warning:

ℹ Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading 'line')

Also, c8 is not able to generate any report:

Unknown%

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions