-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add D1 + Cloudflare Pages + Nuxt 3 (#5040)
Co-authored-by: Joël Galeran <[email protected]>
- Loading branch information
Showing
22 changed files
with
9,277 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Nuxt dev/build outputs | ||
.output | ||
.data | ||
.nuxt | ||
.nitro | ||
.cache | ||
dist | ||
|
||
# Node dependencies | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Misc | ||
.DS_Store | ||
.fleet | ||
.idea | ||
|
||
# Local env files | ||
.env | ||
.env.* | ||
!.env.example | ||
|
||
.wrangler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Prisma Driver Adapters Nuxt | ||
|
||
This is a Nuxt 3 project that demonstrates how to use Prisma with Driver Adapters. | ||
This project uses: | ||
- Cloudflare Pages as the web platform | ||
- Cloudflare D1 as a database | ||
|
||
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. | ||
|
||
## Setup | ||
|
||
Make sure to install the dependencies: | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
Create a local Cloudflare D1 database: | ||
|
||
```bash | ||
pnpm wrangler d1 migrations apply nuxt-db --local | ||
``` | ||
|
||
## Development Server | ||
|
||
Start the development server on `http://localhost:3000`: | ||
|
||
```bash | ||
pnpm run dev | ||
``` | ||
|
||
Go to `http://localhost:3000/api` to see an example Prisma query. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
<NuxtWelcome /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CfProperties, Request, ExecutionContext, KVNamespace } from '@cloudflare/workers-types'; | ||
|
||
declare module 'h3' { | ||
interface H3EventContext { | ||
cf: CfProperties, | ||
cloudflare: { | ||
request: Request, | ||
env: Env, | ||
context: ExecutionContext, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
cat deployment-logs.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// @ts-check | ||
const { test, expect } = require('@jest/globals') | ||
const { dependencies } = require('./package.json') | ||
const fetch = require('node-fetch').default | ||
|
||
jest.setTimeout(30_000) | ||
|
||
test('prisma version and output', async () => { | ||
const response = await fetch(process.env.DEPLOYMENT_URL + '/api', { | ||
headers: { | ||
'user-agent': 'ecosystem-tests', | ||
}, | ||
}) | ||
const { regResult } = await response.json() | ||
|
||
expect(regResult.prismaVersion).toMatch(dependencies['@prisma/client']) | ||
expect(regResult.deleteMany.count).toBe(0) | ||
expect(regResult.create).toMatchInlineSnapshot(` | ||
{ | ||
"age": 27, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
} | ||
`) | ||
expect(regResult.createMany.count).toBe(2) | ||
expect(regResult.createManyAndReturn).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 4", | ||
}, | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 5", | ||
}, | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 6", | ||
}, | ||
] | ||
`) | ||
expect(regResult.findMany).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"age": 27, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
}, | ||
{ | ||
"age": 29, | ||
"email": "[email protected]", | ||
"name": "Test 2", | ||
}, | ||
{ | ||
"age": 29, | ||
"email": "[email protected]", | ||
"name": "Test 3", | ||
}, | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 4", | ||
}, | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 5", | ||
}, | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test 6", | ||
}, | ||
] | ||
`) | ||
expect(regResult.findUnique).toMatchInlineSnapshot(` | ||
{ | ||
"age": 27, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
} | ||
`) | ||
expect(regResult.update).toMatchInlineSnapshot(` | ||
{ | ||
"age": 26, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
} | ||
`) | ||
expect(regResult.updateMany.count).toBe(1) | ||
expect(regResult.findFirst).toMatchInlineSnapshot(` | ||
{ | ||
"age": 27, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
} | ||
`) | ||
expect(regResult.delete).toMatchInlineSnapshot(` | ||
{ | ||
"age": 27, | ||
"email": "[email protected]", | ||
"name": "Test 1", | ||
} | ||
`) | ||
expect(regResult.count).toBe(5) | ||
expect(regResult.aggregate).toMatchInlineSnapshot(` | ||
{ | ||
"age": 29, | ||
} | ||
`) | ||
expect(regResult.groupBy).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"_count": { | ||
"age": 2, | ||
}, | ||
"age": 29, | ||
}, | ||
{ | ||
"_count": { | ||
"age": 3, | ||
}, | ||
"age": 30, | ||
}, | ||
] | ||
`) | ||
expect(regResult.findFirstOrThrow).toMatchInlineSnapshot(` | ||
{ | ||
"age": 29, | ||
"email": "[email protected]", | ||
"name": "Test 2", | ||
} | ||
`) | ||
expect(regResult.findUniqueOrThrow).toMatchInlineSnapshot(` | ||
{ | ||
"age": 29, | ||
"email": "[email protected]", | ||
"name": "Test 2", | ||
} | ||
`) | ||
expect(regResult.upsert).toMatchInlineSnapshot(` | ||
{ | ||
"age": 30, | ||
"email": "[email protected]", | ||
"name": "Test upsert", | ||
} | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import nitroCloudflareBindings from 'nitro-cloudflare-dev' | ||
|
||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
modules: [nitroCloudflareBindings], | ||
nitro: { | ||
preset: 'cloudflare-pages', | ||
experimental: { | ||
wasm: true, | ||
}, | ||
esbuild: { | ||
options: { | ||
target: 'esnext', | ||
}, | ||
}, | ||
}, | ||
devtools: { enabled: true }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "d1-cfpages-nuxt", | ||
"author": { | ||
"name": "Alberto Schiabel", | ||
"email": "[email protected]" | ||
}, | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "nuxt build", | ||
"dev": "nuxt dev", | ||
"generate": "nuxt generate", | ||
"preview": "nuxt preview", | ||
"postinstall": "nuxt prepare", | ||
"test": "jest index.test.js" | ||
}, | ||
"dependencies": { | ||
"@prisma/adapter-d1": "5.16.0-dev.4", | ||
"@prisma/client": "5.16.0-dev.4", | ||
"nuxt": "^3.11.2", | ||
"vue": "^3.4.27", | ||
"vue-router": "^4.3.2" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20240524.0", | ||
"@jest/globals": "29.7.0", | ||
"jest": "29.7.0", | ||
"nitro-cloudflare-dev": "^0.1.4", | ||
"prisma": "5.16.0-dev.4", | ||
"wrangler": "^3.57.1" | ||
} | ||
} |
Oops, something went wrong.