0

i'm trying to use vite in my existing React application. so i followed this document https://www.darraghoriordan.com/2021/05/16/migrating-from-create-react-app-to-vite

here, my application is working as i expected, but when i try to run the test case yarn test i'm getting this message the test case haven't started the testing. i've tried this but no luck. enter image description here

this what i've kept in the package.json's script:{ "test": "vite test"}

in my vite.config.ts

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import svgrPlugin from "vite-plugin-svgr";
import envCompatible from 'vite-plugin-env-compatible';
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  // This changes the out put dir from dist to build
  build: {
    outDir: "build",
  },
  resolve: {
    alias: {
        "@src": path.resolve(__dirname, "src"),
    }
},
  envPrefix: 'REACT_APP_',
  plugins: [
    react(),
    envCompatible(),
    svgrPlugin({
      svgrOptions: {
        icon: true,
        // ...svgr options (https://react-svgr.com/docs/options/)
      },
    }),
  ],
});

can anyone helpme to solve this

Vinoth
  • 972
  • 1
  • 16
  • 47

1 Answers1

0

I'm guessing here but probably before there was something like

"test": "react-scripts test",

in your package.json file.

When you were running npm test in the terminal it would execute this react-scripts test. This was created by Create React App and it would run your tests using jest as test runner.

Now that you replaced CRA with Vite, you might need to set up jest or use something similar like vitest to run your tests.

After that has been set up you can change the script to "test": "jest ..." or "test": "vitest ...".

Right now you are trying to run tests using Vite, but Vite is a bundler, not a test runner.

Job Ouddeken
  • 183
  • 1
  • 8