Skip to content

Commit

Permalink
test: update to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
farreldarian committed Jun 24, 2024
1 parent 717915b commit 70a09cd
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
runs-on: ubuntu-latest

env:
PG_DATABASE_URL: postgres://postgres:[email protected]:5432/testdb
MYSQL_DATABASE_URL: mysql://root:[email protected]:3306/testdb
VITE_PG_DATABASE_URL: postgres://postgres:[email protected]:5432/testdb
VITE_MYSQL_DATABASE_URL: mysql://root:[email protected]:3306/testdb

services:
mysql:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/usage/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: this will also be used for running test,
# make sure that the db has no sensitive data
PG_DATABASE_URL=postgres://<username>:<password>@localhost:5432/<db>
MYSQL_DATABASE_URL=mysql://<username>:<password>@localhost:3306/<db>
VITE_PG_DATABASE_URL=postgres://<username>:<password>@localhost:5432/<db>
VITE_MYSQL_DATABASE_URL=mysql://<username>:<password>@localhost:3306/<db>
3 changes: 2 additions & 1 deletion packages/usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bun-types": "^1.0.30",
"prisma": "5.15.0",
"prisma-generator-drizzle": "workspace:*",
"typescript": "5.4.2"
"typescript": "5.4.2",
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/usage/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ generator drizzle {

datasource db {
provider = "postgresql"
url = env("PG_DATABASE_URL")
url = env("VITE_PG_DATABASE_URL")
}

model SelfReference {
Expand Down
2 changes: 1 addition & 1 deletion packages/usage/scripts/cloneMysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TARGET_PATH = './prisma/mysql/schema.prisma'

const schema = (await Bun.file(BASE_PATH).text())
.replace('postgresql', 'mysql')
.replace('PG_DATABASE_URL', 'MYSQL_DATABASE_URL')
.replace('VITE_PG_DATABASE_URL', 'VITE_MYSQL_DATABASE_URL')
.replace(/(\/\/ start -mysql\n)[\s\S]*?(\n\/\/ end -mysql)/g, '')
.replace(/^.*-mysql.*/gm, '')

Expand Down
2 changes: 1 addition & 1 deletion packages/usage/scripts/cloneSqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TARGET_PATH = './prisma/sqlite/schema.prisma'

const schema = (await Bun.file(BASE_PATH).text())
.replace('postgresql', 'sqlite')
.replace('env("PG_DATABASE_URL")', '"file:./test.db"')
.replace('env("VITE_PG_DATABASE_URL")', '"file:./test.db"')
.replace(/(\/\/ start -sqlite\n)[\s\S]*?(\n\/\/ end -sqlite)/g, '')
.replace(/^.*-sqlite.*/gm, '')

Expand Down
4 changes: 2 additions & 2 deletions packages/usage/src/lib/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { url, object, parse, pipe, string } from 'valibot'

const env = parse(
object({
MYSQL_DATABASE_URL: pipe(string(), url()),
VITE_MYSQL_DATABASE_URL: pipe(string(), url()),
}),
process.env
)

const connection = await mysql.createConnection(env.MYSQL_DATABASE_URL)
const connection = await mysql.createConnection(env.VITE_MYSQL_DATABASE_URL)

export const db = drizzle(connection, { schema, mode: 'default' })
4 changes: 2 additions & 2 deletions packages/usage/src/lib/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { url, object, parse, pipe, string } from 'valibot'

const env = parse(
object({
PG_DATABASE_URL: pipe(string(), url()),
VITE_PG_DATABASE_URL: pipe(string(), url()),
}),
process.env
)

const queryClient = postgres(env.PG_DATABASE_URL)
const queryClient = postgres(env.VITE_PG_DATABASE_URL)
export const db = drizzle(queryClient, { schema })
4 changes: 2 additions & 2 deletions packages/usage/tests/configure-date-mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('global config', async () => {
getSchemaPath(temp),
`datasource db {
provider = "postgresql"
url = env("PG_DATABASE_URL")
url = env("VITE_PG_DATABASE_URL")
}
generator drizzle {
Expand Down Expand Up @@ -43,7 +43,7 @@ test('field-level config', async () => {
getSchemaPath(temp),
`datasource db {
provider = "postgresql"
url = env("PG_DATABASE_URL")
url = env("VITE_PG_DATABASE_URL")
}
generator drizzle {
Expand Down
6 changes: 3 additions & 3 deletions packages/usage/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
"tasks": {
"pushreset:postgres": {
"cache": false,
"env": ["PG_DATABASE_URL"]
"env": ["VITE_PG_DATABASE_URL"]
},
"pushreset:mysql": {
"cache": false,
"dependsOn": ["clone:mysql"],
"env": ["MYSQL_DATABASE_URL"]
"env": ["VITE_MYSQL_DATABASE_URL"]
},
"pushreset:sqlite": {
"cache": false,
"dependsOn": ["clone:sqlite"]
},
"test": {
"cache": false,
"env": ["PG_DATABASE_URL", "MYSQL_DATABASE_URL"],
"env": ["VITE_PG_DATABASE_URL", "VITE_MYSQL_DATABASE_URL"],
"dependsOn": [
"^build",
"pushreset:postgres",
Expand Down
7 changes: 7 additions & 0 deletions packages/usage/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
globals: true,
},
})

0 comments on commit 70a09cd

Please sign in to comment.