Issues with running tests that import ES modules
Opened this issue · 2 comments
bstro commented
I am using vite-jest 0.0.3
, running my tests with vite-jest
. I am seeing failures across all my tests for essentially the same reason. Here is a screenshot of the first failure that looks like an esm
syntax issue:
jest config looks like this:
const config = {
preset: 'vite-jest',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testMatch: ['<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
testEnvironment: 'jest-environment-jsdom',
}
vite config looks like this:
import {defineConfig} from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
export default defineConfig({
build: {
outDir: 'build',
},
plugins: [...(process.env.NODE_ENV !== 'test' ? [reactRefresh()] : [])],
})
viztor commented
same issue, I thought I configured it wrong.
sven-ahrens commented
Same error with vue
jest.config.js
const config = {
preset: 'vite-jest'
}
module.exports = config
Scripts (package.json
)
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"test": "vite-jest"
},
Using vite-jest version 0.0.3