Open Jason3S opened 1 year ago
Start a new pull request in StackBlitz Codeflow.
Interesting. Vite doesn't process .cts
files at all. I guess we should provide our own plugin to transform this?
I am not sure if we should even support generated CJS, since we cannot process require
calls there (if in your example you had import test from './test.cts'
it would've been transformed into a require('./test.cjs')
, and Vitest doesn't intercept require
at all because Vite's plugin system is asynchronous, so it would try to run TypeScript file as a JavaScript file and we wouldn't be able to do anything.
I would recommend running tests on already transformed files in your case.
Note: One workaround I found was to compile the .cts
files in place (into the same dir) to .cjs
file. But this breaks down when trying to generate a coverage report.
Example Setup: https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell/src/lib
Note: One workaround I found was to compile the
.cts
files in place (into the same dir) to.cjs
file. But this breaks down when trying to generate a coverage report.Example Setup: https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell/src/lib
Here is a library that may help you to intercept and mock require calls: vitest-mock-require
Is there a workaround for supporting ".cts"?
In case this is useful to someone, here is a simple Stackblitz example: https://stackblitz.com/edit/vitest-dev-vitest-zbjtkh?file=src%2Fbasic.cts
Any update regarding parsing .cts source files? (couldn't work around getting RollupError from parsing typescript syntax in .cts file...)
There are no plans to support .cts
files out of the box.
Describe the bug
While working with an application with a mix of
.mts
and.cts
files, vitest fails to correctly parse the.cts
source files. It seems to be treating them as.cjs
files.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-xrug9w?file=README.md
System Info
Used Package Manager
npm
Validations