Example of SPA using MSW for unit and E2E testing
The project was created with the initial guide
You need to have installed pnpm
then you can just run pnpm i
to install all dependencies for each project.
Install vitest and React Testing Library
npm add -D @testing-library/react @vitest/ui jsdom @vitest/coverage-v8
Add the following properties to vite.config.ts
/// <reference types="vitest" />
/// <reference types="vite/client" />
Add types to tsconfig.json
"types": [ "vitest/globals" ]
And the following section to define config
test: {
globals: true,
environment: 'jsdom',
coverage: {
provider: "v8",
reporter: ["json", "html"]
}
}
Add the following scripts for testing
"test": "vitest --run",
"test:ci": "vitest run --coverage",
"test:ui": "vitest --ui --coverage"
Install the following
npm add lowdb express express-jwt cors
npm add lowdb fastify @fastify/auth @fastify/bearer-auth @fastify/cors @fastify/jwt