Skip to content

Commit eafc86c

Browse files
committed
Adding vitest to the template
1 parent fb4b469 commit eafc86c

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
- [x] Check to make sure it works on Windows
55
- [ ] Error handling
66
- [ ] Add tests
7-
- [ ] Better project README
7+
- [x] Add vitest to the projects
8+
- [x] Better project README

project-template/README.md.ejs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ To build this application for production:
1717
<%= packageManager %> run build
1818
```
1919

20+
## Testing
21+
22+
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
23+
24+
```bash
25+
<%= packageManager %> run test
26+
```
27+
2028
## Styling
2129
<% if (tailwind) { %>
2230
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
@@ -136,14 +144,16 @@ From there you need to update your `vite.config.js` file to use the plugin:
136144
```ts
137145
import { defineConfig } from "vite";
138146
import viteReact from "@vitejs/plugin-react";
139-
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
140-
147+
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";<% if (tailwind) { %>
148+
import tailwindcss from "@tailwindcss/vite";
149+
<% } %>
150+
141151
// https://vitejs.dev/config/
142152
export default defineConfig({
143153
plugins: [
144154
TanStackRouterVite(),
145-
viteReact(),
146-
// ...
155+
viteReact()<% if (tailwind) { %>,
156+
tailwindcss()<% } %>
147157
],
148158
});
149159
```

project-template/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"start": "vite --port 3000",
77
"build": "vite build && tsc --noEmit",
8-
"serve": "vite preview"
8+
"serve": "vite preview",
9+
"test": "vitest"
910
},
1011
"dependencies": {
1112
"@tanstack/react-router": "^1.104.1",
@@ -14,11 +15,14 @@
1415
"react-dom": "^19.0.0"
1516
},
1617
"devDependencies": {
18+
"@testing-library/react": "^16.2.0",
1719
"@types/react": "^19.0.8",
1820
"@types/react-dom": "^19.0.3",
1921
"@vitejs/plugin-react": "^4.3.4",
22+
"jsdom": "^26.0.0",
2023
"typescript": "^5.7.2",
2124
"vite": "^6.1.0",
25+
"vitest": "^3.0.5",
2226
"web-vitals": "^4.2.4"
2327
}
2428
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, expect, test } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import App from "./App";
4+
5+
describe("App", () => {
6+
test("renders", () => {
7+
render(<App />);
8+
expect(screen.getByText("Learn React")).toBeDefined();
9+
});
10+
});

project-template/vite.config.js.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ import tailwindcss from "@tailwindcss/vite";
77
// https://vitejs.dev/config/
88
export default defineConfig({
99
plugins: [viteReact()<% if (tailwind) { %>, tailwindcss()<% } %>],
10+
test: {
11+
globals: true,
12+
environment: "jsdom",
13+
},
1014
});

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ async function createApp(projectName: string, options: Required<Options>) {
148148
"./src/App.tsx.ejs",
149149
options.typescript ? undefined : "./src/App.jsx"
150150
);
151+
await templateFile(
152+
"./src/App.test.tsx.ejs",
153+
options.typescript ? undefined : "./src/App.test.jsx"
154+
);
151155

152156
// Setup the main, reportWebVitals and index.html files
153157
if (options.typescript) {

0 commit comments

Comments
 (0)