sodatea / vite-jest

First-class Vite integration for Jest
MIT License
401 stars 51 forks source link

Issues with running tests that import ES modules #11

Open bstro opened 2 years ago

bstro commented 2 years ago

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:

image

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 2 years ago

same issue, I thought I configured it wrong.

sven-ahrens commented 2 years ago

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