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

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

Open
4 of 6 tasks
gjuchault opened this issue Dec 13, 2023 · 7 comments
Open
4 of 6 tasks

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

gjuchault opened this issue Dec 13, 2023 · 7 comments
Labels
bug Something isn't working pending triage pr welcome

Comments

@gjuchault
Copy link

gjuchault commented Dec 13, 2023

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
@gjuchault gjuchault added bug Something isn't working pending triage labels Dec 13, 2023
@privatenumber
Copy link
Owner

Is this a duplicate of #433?

@gjuchault
Copy link
Author

gjuchault commented Dec 14, 2023

Sorry for not spotting this issue earlier, I might have added a comment on it.
However, I tried with tsx@4.2.1 (pinned) as suggested by the author of #433 and I still get the same ℹ Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading 'line') and no coverage, so I'm not sure it's exactly the same error

@jbergstroem

This comment has been minimized.

@gjuchault
Copy link
Author

gjuchault commented Jan 31, 2024

@privatenumber I tried the solution you suggested in #433 locally and ran npm link to try on my reproduction case. It still didn't run

Edit: also I've been running the code with Node v21.x where the condition is supposed to be true (process.setSourceMapsEnabled is defined and Error.prepareStackTrace is undefined)

@gjuchault
Copy link
Author

Should be fixed by Node 22 since they merged this

@SuperchupuDev
Copy link

SuperchupuDev commented Apr 24, 2024

updating to node 22 doesn't solve the issue for me
image

@gjuchault

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage pr welcome
Projects
None yet
Development

No branches or pull requests

4 participants