question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature: first class Jest integration

See original GitHub issue

(previously…)

Making an issue to track work on the Jest experience with vite.

Jest is a very popular JavaScript testing framework. Some standout features:

  • Support for mocking functions and modules
  • Parallelisation and prioritisation of tests
  • Snapshot tests
  • Running only changed tests between 2 revisions (or based on a set of files)

It would be worthy to provide some form of blessed integration to use with vite.

(If you don’t need these features, you may be better off using a testing framework like uvu, which should be much simpler to setup.)

@yyx990803 mentioned spinning up a ViteDevServer and using vite.transformRequest() as the transform. One problem here is that the jest transform is expected to be synchronous. Jest’s likely going to fix this as part of the ES module work, tracking here. (Further, it’s not clear to me what the devx would be? Should we run a vite server in a seaparate process/terminal tab? Or should we introduce a vite test command that wraps jest?


Let me propose a first step: in my own repo I’m going to do the bare minimum: esbuild-jest (possibly modified) + babel-plugin-transform-import-meta + babel-plugin-jest-hoist + babel-plugin-istanbul. Anything I’m missing? What are the vite specific bits to inject into the environment? Discuss!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:141
  • Comments:56 (20 by maintainers)

github_iconTop GitHub Comments

82reactions
sodateacommented, Jun 16, 2021

Seems --experimental-loader is useless here.

But I have successfully worked around the async resolver issue, by moving the module resolution logic into the transformer (with the help of es-module-lexer). And some other small hacks can be wrapped in a custom vite-jest command.

So here it is: a very early-stage proof-of-concept implementation: https://github.com/sodatea/vite-jest Available on NPM https://www.npmjs.com/package/vite-jest

(I’ve accidentally made @vue/test-utils@next a hard dependency in v0.0.1. Anyway, I’ll continue working on this tomorrow. Time to go to bed now)

45reactions
schalk-bcommented, Jun 17, 2021

Thank you for your hard work on this issue @sodatea. I’ve setup a small monthly contribution of appreciation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - Jest
Jest supports TypeScript, via Babel. First, make sure you followed the instructions on using Babel above. Next, install the @babel/preset- ...
Read more >
#FeatureFriday: Integration Testing with Jest - YouTube
Continuing our series on testing, this week we're focused on integration testing: the process of writing tests that test code that integrate ......
Read more >
Mocking a JavaScript Class with Jest, two ways to make it easier
Jest is the most popular automated testing framework for JavaScript. It can be used both on the front end and back end with...
Read more >
Continuous integration for React applications using Jest and ...
I will show you how to configure continuous integration with CircleCI to ... The first thing you need to do is to export...
Read more >
Comparisons with Other Test Runners | Guide - Vitest
It is possible to use Jest in Vite setups. @sodatea is building vite-jest, which aims to provide first-class Vite integration for Jest. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found