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

Coverage with c8 and tsx reporting as 100% since version 4.3.0 #433

Closed
4 of 6 tasks
OscarBarrett opened this issue Dec 8, 2023 · 8 comments
Closed
4 of 6 tasks
Labels
bug Something isn't working pr welcome

Comments

@OscarBarrett
Copy link

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://github.com/OscarBarrett/tsx-coverage-issue

Version

v4.6.2

Node.js version

v20.10.0

Package manager

yarn

Operating system

Linux

Problem & Expected behavior

We use c8 and tsx together when running our test suites, and since tsx version 4.3.0 any file that is imported in our tests gets 100% coverage.
Locking to tsx 4.2.1, we get the expected coverage.

Assuming this is related to #405

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@andreashuber69
Copy link

I have the same issue. FWIW, you can work around this by running tests on the built js output. If you have TypeScript generate .map files, then the CC output should look the same as before (i.e. reported on ts files rather than js files). Here's an example of the changes necessary (besides building with tsc):

andreashuber69/verify-coldcard-dice-seed@35b72b9

@jbergstroem

This comment has been minimized.

@privatenumber
Copy link
Owner

I haven't investigated this but I'm thinking this is as simple as removing this check so sourcemaps are always inlined:

if (hasNativeSourceMapSupport) {

There will need to be tests though. PR welcome if anyone wants to tackle.

@cenfun

This comment was marked as off-topic.

@privatenumber
Copy link
Owner

privatenumber commented Apr 4, 2024

Sorry, I'm going to hide your comment because it doesn't lead to a solution in tsx.

Seems like both versions of tsx in the reproduction doesn't work in the latest version of Node, but the reproduction still works fine with Node v20.10.0.

I'm curious what happened between tsx v4.2.1 and v4.6.2 that broke c8 in Node v20.10.0.

@cenfun
Copy link
Contributor

cenfun commented Apr 4, 2024

@privatenumber the generated sourcemap content could be different
could be caused by this

/**
	 * Improve performance by generating smaller source maps
	 * that doesn't include the original source code
	 *
	 * https://esbuild.github.io/api/#sources-content
	 */
	sourcesContent: false,

@privatenumber
Copy link
Owner

privatenumber commented Apr 4, 2024

@cenfun

You're right!

I tested removing sourcesContent (https://github.com/privatenumber/tsx/compare/esbuild-sourcesContent?expand=1) in the reproduction and the coverage is working again in Node 20.10.0 and v20.12.1 (latest LTS):

pnpm i 'privatenumber/tsx#npm/esbuild-sourcesContent'

(Here's how to make a installable branch, if you're interested)

I'll need to look into a way to add tests for this.

@privatenumber
Copy link
Owner

This has been completed in the development repo.

sverweij added a commit to sverweij/watskeburt that referenced this issue May 12, 2024
## Description

- replaces c8 with node 'native' --experimental-test-coverage

## Motivation and Context

c8 in our setup always returned 100% coverage for all things - which
might have to do with an issue in tsx (see [tsx
#433](privatenumber/tsx#433) ), but might just
as well be caused by something unexpectedly breaking in de nodejs / v8
w.r.t. loader coverage.

`--experimental-test-coverage` is not perfect either (i.c.w. tsx it's
unstable on node > 20.12.2, and line numbers are off), but at least the
coverage data we get is more realistic.

## How Has This Been Tested?

- [x] green ci

## Screenshots

```
> tsx --experimental-test-coverage --test-reporter ./tools/dot-with-summary.reporter.js --test src/*.spec.ts src/**/*.spec.ts

.................................................

49 passing (1.420 ms)

=============================== Coverage summary ===============================
Branches     : 97,89 % (93/95) NOK
Functions    : 100 % (38/38)
Lines        : 99,76 % (422/423)
================================================================================

Uncovered lines:
  /Users/sander/prg/js/watskeburt/src/git-primitives.ts:80

Uncovered branches:
  /Users/sander/prg/js/watskeburt/src/git-primitives.ts:79
  /Users/sander/prg/js/watskeburt/src/main.ts:22
```

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Chore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants