Skip to content

Commit

Permalink
test: unuse bun-specific apis
Browse files Browse the repository at this point in the history
  • Loading branch information
farreldarian committed Jun 24, 2024
1 parent 17381f5 commit 315165e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"start": "bun run src/index.ts",
"test": "bun test --preload tests/setup.ts",
"test": "bun vitest run",
"generate": "prisma generate",
"pushreset:postgres": "bun prisma db push --schema prisma/schema.prisma --force-reset --accept-data-loss",
"pushreset:mysql": "bun prisma db push --schema prisma/mysql/schema.prisma --force-reset --accept-data-loss",
Expand All @@ -17,7 +17,7 @@
"dependencies": {
"@paralleldrive/cuid2": "^2.2.2",
"@prisma/client": "5.15.0",
"better-sqlite3": "^9.4.3",
"better-sqlite3": "^11.0.0",
"date-fns": "^3.3.1",
"decimal.js": "^10.4.3",
"drizzle-orm": "^0.30.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/usage/src/lib/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Database } from 'bun:sqlite'
import { drizzle } from 'drizzle-orm/bun-sqlite'
import Database from 'better-sqlite3'
import { drizzle } from 'drizzle-orm/better-sqlite3'
import { schema } from 'prisma/sqlite/drizzle/schema'

const sqlite = new Database('./prisma/sqlite/test.db')
Expand Down
15 changes: 8 additions & 7 deletions packages/usage/tests/configure-date-mode.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $ } from 'bun'
import { execSync } from 'node:child_process'
import * as fs from 'node:fs'
import { type TempDirectory, createTempHandler } from './utils/temp'

const tempHandler = createTempHandler()
Expand All @@ -10,7 +11,7 @@ afterAll(async () => {
test('global config', async () => {
const temp = await tempHandler.prepare()

await Bun.write(
fs.writeFileSync(
getSchemaPath(temp),
`datasource db {
provider = "postgresql"
Expand All @@ -28,9 +29,9 @@ test('global config', async () => {
date DateTime
}`
)
await $`bun prisma generate --schema ${getSchemaPath(temp)}`.quiet()
execSync(`bun prisma generate --schema ${getSchemaPath(temp)}`)

const output = await Bun.file(`${temp.basePath}/drizzle.ts`).text()
const output = fs.readFileSync(`${temp.basePath}/drizzle.ts`, 'utf-8')
expect(output).toContain(
"date: timestamp('date', { mode: 'string', precision: 3 })"
)
Expand All @@ -39,7 +40,7 @@ test('global config', async () => {
test('field-level config', async () => {
const temp = await tempHandler.prepare()

await Bun.write(
fs.writeFileSync(
getSchemaPath(temp),
`datasource db {
provider = "postgresql"
Expand All @@ -58,9 +59,9 @@ test('field-level config', async () => {
stringDate DateTime
}`
)
await $`bun prisma generate --schema ${getSchemaPath(temp)}`.quiet()
execSync(`bun prisma generate --schema ${getSchemaPath(temp)}`)

const output = await Bun.file(`${temp.basePath}/drizzle.ts`).text()
const output = await fs.readFileSync(`${temp.basePath}/drizzle.ts`, 'utf-8')
expect(output).toContain(
"normalDate: timestamp('normalDate', { mode: 'date', precision: 3 })"
)
Expand Down
12 changes: 6 additions & 6 deletions packages/usage/tests/single-file-output.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import { $ } from 'bun'
import { createTempHandler } from './utils/temp'

const tempHandler = createTempHandler()
Expand All @@ -11,39 +11,39 @@ afterAll(() => {
test('generates drizzle.ts', async () => {
const temp = await tempHandler.prepare()
writeSchemaWithOutput(temp.name, 'drizzle.ts')
await $`bun prisma generate --schema .temp/${temp.name}/schema.prisma`.quiet()
execSync(`bun prisma generate --schema .temp/${temp.name}/schema.prisma`)

expect(fs.existsSync(`.temp/${temp.name}/drizzle.ts`)).toBe(true)
})

test('generates ./drizzle.ts', async () => {
const temp = await tempHandler.prepare()
writeSchemaWithOutput(temp.name, './drizzle.ts')
await $`bun prisma generate --schema .temp/${temp.name}/schema.prisma`.quiet()
execSync(`bun prisma generate --schema .temp/${temp.name}/schema.prisma`)

expect(fs.existsSync(`.temp/${temp.name}/drizzle.ts`)).toBe(true)
})

test('generates sub/drizzle.ts', async () => {
const temp = await tempHandler.prepare()
writeSchemaWithOutput(temp.name, 'sub/drizzle.ts')
await $`bun prisma generate --schema .temp/${temp.name}/schema.prisma`.quiet()
execSync(`bun prisma generate --schema .temp/${temp.name}/schema.prisma`)

expect(fs.existsSync(`.temp/${temp.name}/sub/drizzle.ts`)).toBe(true)
})

test('generates ./sub/drizzle.ts', async () => {
const temp = await tempHandler.prepare()
writeSchemaWithOutput(temp.name, './sub/drizzle.ts')
await $`bun prisma generate --schema .temp/${temp.name}/schema.prisma`.quiet()
execSync(`bun prisma generate --schema .temp/${temp.name}/schema.prisma`)

expect(fs.existsSync(`.temp/${temp.name}/sub/drizzle.ts`)).toBe(true)
})

test('generates ./sub/multi/drizzle.ts', async () => {
const temp = await tempHandler.prepare()
writeSchemaWithOutput(temp.name, './sub/multi/drizzle.ts')
await $`bun prisma generate --schema .temp/${temp.name}/schema.prisma`.quiet()
execSync(`bun prisma generate --schema .temp/${temp.name}/schema.prisma`)

expect(fs.existsSync(`.temp/${temp.name}/sub/multi/drizzle.ts`)).toBe(true)
})
Expand Down

0 comments on commit 315165e

Please sign in to comment.