Vitest CLI not recognized
Asked Answered
C

3

7

installed pnpm add -D vitest and pnpm add -D @vitest/ui in my project dir, when i try vitest --ui, I get this error

vitest : The term 'vitest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try 
again.
Cedeno answered 19/5, 2023 at 7:11 Comment(0)
G
2

Ensure that your dependencies are installed by running pnpm install, and then try adding a new script to your package.json file for running your tests. For example:

  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "test": "vitest --ui",
  },

Enter the pnpm run test command in your terminal to run the script.

Generative answered 19/5, 2023 at 11:10 Comment(1)
without install to global , this is the best wayCedeno
P
6

You should install the package globally using npm or yarn. Don't forget to use sudo if you are in Mac or Linux.

npm install -g vitest
Priedieu answered 19/5, 2023 at 11:43 Comment(0)
G
2

Ensure that your dependencies are installed by running pnpm install, and then try adding a new script to your package.json file for running your tests. For example:

  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "test": "vitest --ui",
  },

Enter the pnpm run test command in your terminal to run the script.

Generative answered 19/5, 2023 at 11:10 Comment(1)
without install to global , this is the best wayCedeno
C
0

Run npx vitest from command line.

The above will work if you have Node installed. npx (node package executor) will automatically search for vitest and execute it or even download it and run it from cache.

Here is a good explanation on how npx works.

Cyrilcyrill answered 11/9 at 6:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.