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

vitest support for CI #2366

Closed
nertzy opened this issue Sep 12, 2022 · 18 comments · Fixed by #4415
Closed

vitest support for CI #2366

nertzy opened this issue Sep 12, 2022 · 18 comments · Fixed by #4415

Comments

@nertzy
Copy link

nertzy commented Sep 12, 2022

vitest is a new test framework similar to Jest that runs on top of Vite.

It would be great if dd-trace-js could instrument vitest similar to how the Jest integration works.

@andrei-ivanov-pie
Copy link

+1 on the request please.

@paulvidal
Copy link

👍 on this one

@tainmar
Copy link

tainmar commented Jul 4, 2023

🙏

@Cellule
Copy link

Cellule commented Nov 9, 2023

👍 vitest is gaining more and more traction as a replacement of jest.
We recently-ish had to switch away from jest because of performance issues and vitest was the easiest/simplest switch.
Now that we're starting to look into datadog CI integration, I really wished there was native support for vitest

@nullfame
Copy link

Today I was wondering "why did my tests stop showing up in Datadog" and I realized it is because I haven't published a repo that uses jest in several weeks. All my most recent code is using vitest. It is basically a must for the Vue framework and the support for module syntax is superior. And performance. So fast

I am an every day Datadog user. This will not stop me from using Datadog but I will not be able to make full use of CI. Using vitest is more necessary to my workflow than seeing it in Datadog

@opeologist
Copy link

opeologist commented Jun 18, 2024

adding another comment here to request support. is there any traction on this front that can be surfaced here?

@juan-fernandez
Copy link
Collaborator

hi everyone! Good news: this is currently being worked on in #4415. It's still going to take a bit but vitest support is coming 😄

@juan-fernandez
Copy link
Collaborator

🎉 🚢 vitest support is now released in

@juan-fernandez
Copy link
Collaborator

until we update the docs with the instructions, here's how you can try the vitest integration:

npm install --save-dev dd-trace

Make sure the dd-trace installed version is >=5.18.0 or >=4.42.0.

Then run your vitest tests passing NODE_OPTIONS='--import dd-trace/register.js -r dd-trace/ci/init'.

⚠️ Important:

  • It needs an extra parameter when compared to running tests with mocha, jest or other supported test frameworks: --import dd-trace/register.js
  • The minimum supported Node.js versions are >=18.19 and >=20.6

For example, if your package.json looks like:

"scripts": {
  "test": "vitest run"
}

Run

NODE_OPTIONS='--import dd-trace/register.js -r dd-trace/ci/init' DD_SERVICE=your-javascript-app-tests npm run test 

Take into account that you'll still need an API key or a running agent (see docs for more info)

@thuringia
Copy link

@juan-fernandez Thanks for the amazing work getting this done! Does this mean, we can also use vitest to report code coverage now as well?

I doesn't look like it works, at least running vitest with the istanbul coverage provider, or via nyc doesn't show something in the details for a test session. Uploading a junit report works as expected, unfortunately it's not possible to annotate an existing test session, so that's not an alternative.

@juan-fernandez
Copy link
Collaborator

@juan-fernandez Thanks for the amazing work getting this done! Does this mean, we can also use vitest to report code coverage now as well?

I doesn't look like it works, at least running vitest with the istanbul coverage provider, or via nyc doesn't show something in the details for a test session. Uploading a junit report works as expected, unfortunately it's not possible to annotate an existing test session, so that's not an alternative.

thanks for the feedback @thuringia ! It's indeed impossible at the moment to report code coverage to datadog if you're using vitest. I'll make sure this is reflected in the docs. It's in our roadmap to support it though, so expect it to happen. I'll announce it in this thread as well 😄

@karrui
Copy link

karrui commented Sep 20, 2024

Is there an open issue to track code coverage through vitest? When will it be supported?

@juan-fernandez
Copy link
Collaborator

@karrui total code coverage for vitest is available since https://github.com/DataDog/dd-trace-js/releases/tag/v5.21.0 and https://github.com/DataDog/dd-trace-js/releases/tag/v4.45.0. My bad for not announcing it here as I promised 😅

@juan-fernandez
Copy link
Collaborator

@karrui
Copy link

karrui commented Sep 24, 2024

Thx! does v8 coverage (vitest) work? does not seem to pipe coverage to datadog. (nor for istanbul). Unsure if it's a user error on my end?

@juan-fernandez
Copy link
Collaborator

juan-fernandez commented Sep 24, 2024

yeah, it should work. Feel free to open an issue. It'll be much easier to fix a potential bug with a reproducible case 😄

@karrui
Copy link

karrui commented Sep 24, 2024

This is the PR, I'm able to share it since it's open sourced!

@juan-fernandez
Copy link
Collaborator

This is the PR, I'm able to share it since it's open sourced!

thanks! That's helpful

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

Successfully merging a pull request may close this issue.