Skip to content

Commit 11fd5f1

Browse files
add vitest
1 parent d597bff commit 11fd5f1

File tree

8 files changed

+48
-6
lines changed

8 files changed

+48
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14+
coverage
1415

1516
# Editor directories and files
1617
.vscode/*

bun.lockb

50.9 KB
Binary file not shown.

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"build": "tsc -b && vite build",
99
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1010
"preview": "vite preview",
11-
"prod": "serve -s dist"
11+
"prod": "serve -s dist",
12+
"test": "vitest",
13+
"test:ui": "vitest --ui",
14+
"coverage": "vitest run --coverage"
1215
},
1316
"dependencies": {
1417
"@radix-ui/react-dropdown-menu": "^2.1.1",
@@ -22,24 +25,32 @@
2225
"tailwindcss-animate": "^1.0.7"
2326
},
2427
"devDependencies": {
28+
"@testing-library/jest-dom": "^6.4.6",
29+
"@testing-library/react": "^16.0.0",
30+
"@testing-library/user-event": "^14.5.2",
2531
"@types/node": "^20.14.9",
2632
"@types/react": "^18.3.3",
2733
"@types/react-dom": "^18.3.0",
2834
"@typescript-eslint/eslint-plugin": "^7.13.1",
2935
"@typescript-eslint/parser": "^7.13.1",
3036
"@vitejs/plugin-react-swc": "^3.5.0",
37+
"@vitest/coverage-v8": "^2.0.2",
38+
"@vitest/ui": "^2.0.2",
3139
"autoprefixer": "^10.4.19",
3240
"eslint": "^8.57.0",
3341
"eslint-config-prettier": "^9.1.0",
3442
"eslint-plugin-import": "^2.29.1",
3543
"eslint-plugin-prettier": "^5.1.3",
3644
"eslint-plugin-react-hooks": "^4.6.2",
3745
"eslint-plugin-react-refresh": "^0.4.7",
46+
"jsdom": "^24.1.0",
3847
"postcss": "^8.4.39",
3948
"prettier": "^3.3.2",
4049
"prettier-plugin-tailwindcss": "^0.6.5",
4150
"tailwindcss": "^3.4.4",
4251
"typescript": "^5.2.2",
43-
"vite": "^5.3.1"
52+
"vite": "^5.3.1",
53+
"vite-tsconfig-paths": "^4.3.2",
54+
"vitest": "^2.0.2"
4455
}
4556
}

src/App.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import '@testing-library/jest-dom'
2+
import { render, screen, waitFor } from '@testing-library/react'
3+
import { expect } from 'vitest'
4+
import App from '@/App.tsx'
5+
6+
describe('Page', () => {
7+
it('renders', async () => {
8+
render(<App />)
9+
10+
await waitFor(() => {
11+
expect(screen.getByText(/test-softeno/i)).toBeInTheDocument()
12+
})
13+
})
14+
it('some logic', () => {
15+
expect(1).toEqual(1)
16+
})
17+
})

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function App() {
2727
</div>
2828
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
2929
<ModeToggle />
30+
<p>test-softeno</p>
3031
</>
3132
)
3233
}

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"path": "./tsconfig.node.json"
99
}
1010
],
11+
"include": ["./vitest.setup.ts"],
1112
"compilerOptions": {
1213
"baseUrl": ".",
1314
"paths": {
1415
"@/*": [
1516
"./src/*"
1617
]
17-
}
18+
},
19+
"types": ["vitest/globals"]
1820
}
1921
}

vite.config.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
/// <reference types="vitest" />
2+
/// <reference types="vitest" />
13
import { defineConfig } from 'vite'
24
import react from '@vitejs/plugin-react-swc'
3-
import path from "path";
5+
import path from 'path'
6+
import tsconfigPaths from 'vite-tsconfig-paths'
47

58
// https://vitejs.dev/config/
69
export default defineConfig({
7-
plugins: [react()],
10+
plugins: [react(), tsconfigPaths()],
11+
test: {
12+
globals: true,
13+
environment: 'jsdom',
14+
css: true,
15+
setupFiles: ['./vitest.setup.ts'],
16+
},
817
resolve: {
918
alias: {
10-
"@": path.resolve(__dirname, "./src"),
19+
'@': path.resolve(__dirname, './src'),
1120
},
1221
},
1322
})

vitest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom'

0 commit comments

Comments
 (0)