Skip to content

Commit 71827a2

Browse files
authored
feat(generator-prisma-client): add Vitest + ESM example (#8285)
* feat(generator-prisma-client): add Vitest + ESM example * feat(generator-prisma-client): minor fixes --------- Co-authored-by: jkomyno <12381818+jkomyno@users.noreply.github.com>
1 parent 236acc7 commit 71827a2

10 files changed

Lines changed: 1954 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
src/generated
3+
prisma/dev.db
4+
dist
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Prisma Client Example: Vitest + Node.js + ESM
2+
3+
This project showcases how to use the Prisma ORM with the `prisma-client` generator in an TypeScript test suite using [Vitest 3](https://vitest.dev/) in an ESM Node.js environment.
4+
5+
## Tech Stack
6+
7+
- Next.js 15
8+
- Runtime: Node.js 20.19.0
9+
- Test runner: Vitest 3
10+
- `package.json` contains `{ "type": "module" }`
11+
- Prisma Client with the `prisma-client` generator
12+
See the [Prisma schema file](./prisma/schema.prisma) for details.
13+
14+
```prisma
15+
generator client {
16+
provider = "prisma-client"
17+
output = "../src/generated/prisma"
18+
previewFeatures = ["driverAdapters", "queryCompiler"]
19+
}
20+
21+
datasource db {
22+
provider = "sqlite"
23+
url = "file:./dev.db"
24+
}
25+
```
26+
27+
## Getting started
28+
29+
### 1. Clone the repository
30+
31+
Clone the repository, navigate into it and install dependencies:
32+
33+
```
34+
git clone git@github.com:prisma/prisma-examples.git --depth=1
35+
cd prisma-examples/generator-prisma-client/vitest-esm-nodejs
36+
pnpm install
37+
```
38+
39+
### 2. Generate Prisma Client
40+
41+
Run:
42+
43+
```
44+
pnpm prisma generate
45+
```
46+
47+
### 3. Test the project
48+
49+
Run
50+
51+
```
52+
pnpm test
53+
```
54+
55+
Your output should look similar to the following:
56+
57+
```sh
58+
Prisma schema loaded from prisma/schema.prisma
59+
Datasource "db": SQLite database "dev.db" at "file:./dev.db"
60+
Running Prisma DB push...
61+
62+
Test Files 0 passed (1)
63+
Tests 0 passed (0)
64+
Start at 14:38:33
65+
Duration 910ms
66+
Test database setup completed
67+
✓ test/quotes.test.ts (3 tests) 63ms
68+
✓ Quotes > should create a quote 50ms
69+
✓ Quotes > should find quotes by kind 9ms
70+
✓ Quotes > should count total quotes 4ms
71+
72+
Test Files 1 passed (1)
73+
Tests 3 passed (3)
74+
```
75+
76+
## Resources
77+
78+
- Check out the [Prisma docs](https://www.prisma.io/docs)
79+
- [Join our community on Discord](https://pris.ly/discord?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) to share feedback and interact with other users.
80+
- [Subscribe to our YouTube channel](https://pris.ly/youtube?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for live demos and video tutorials.
81+
- [Follow us on X](https://pris.ly/x?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for the latest updates.
82+
- Report issues or ask [questions on GitHub](https://pris.ly/github?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "vitest-esm-nodejs",
3+
"type": "module",
4+
"scripts": {
5+
"prisma:generate": "prisma generate",
6+
"clean": "rimraf ./src/generated ./dist",
7+
"test": "vitest run",
8+
"test:watch": "vitest"
9+
},
10+
"license": "MIT",
11+
"packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81",
12+
"dependencies": {
13+
"@prisma/adapter-better-sqlite3": "6.14.0",
14+
"@prisma/client": "6.14.0"
15+
},
16+
"devDependencies": {
17+
"@types/node": "18.19.117",
18+
"execa": "^9.6.0",
19+
"prisma": "6.14.0",
20+
"rimraf": "6.0.1",
21+
"typescript": "5.8.3",
22+
"vitest": "^3.2.4"
23+
}
24+
}

0 commit comments

Comments
 (0)