-
You have to set up a nodejs project (Recommended version v22.18.0 to use typescript)
yarn init
-
Create the file tsconfig.json in the root Documentation
{
"compilerOptions": {
"noEmit": true, // Optional - see note below
"target": "esnext",
"module": "nodenext",
"rewriteRelativeImportExtensions": true,
"erasableSyntaxOnly": true,
"verbatimModuleSyntax": true
}
}- You have to install the following packages
yarn add vitest supertest -D
NOTE: There will be another packages wich the project will require to install in the process such as jsdom and coverage
-
Actualizar los scripts del package.json
"scripts": { ... "test": "vitest", "test:coverage": "vitest --coverage" },
-
Crear la configuración de babel vite.config.ts and vitest.setup.ts
- vite.config.ts
/// <reference types="vitest" /> import { defineConfig } from 'vite' // https://vite.dev/config/ export default defineConfig({ test: { // Use jsdom for maximum compatibility and realism; use happy-dom for faster, simpler tests where full browser accuracy is not required. environment: "node", setupFiles: "./vitest-setup.ts", coverage: { provider: "v8", reporter: ["text", "json", "html"], reportsDirectory: './coverage' } } })
- vitest-setup.ts
-
And you are ready to begin with your first test case
import {describe, test, expect} from "vitest"; describe('Tests', () => { test('Prueba', () => { expect(1).toBe(1); }); });