-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
(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.)
- Files could be transformed with
esbuildto make jest tests startup and run faster (prior art:esbuild-jest,esbuild-jest-transform). - Files could share the same transforms that
vitealready uses for newer syntax (for example, support forimport.metaviababel-plugin-transform-import-meta) untiljestships full support for ES modules. - Files could have
jest.mock()calls hoisted above imports withbabel-plugin-jest-hoist(explanation) until top-levelawaitlands fully inesbuild, at which point you could codemod all tests to use tla imports, and remove thebabelplugin. (This still requires support fromjestfor ES modules, or else it won't detect tests defined after a couple of ticks have passed.)- This exists as an
swcpackage too, which is very appealing (via vite#788).
- This exists as an
- I think
jestusesbabel-plugin-istanbulfor coverage. This may never land inesbuild.
@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!