Skip to content

Commit

Permalink
run prisma reset via spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
devneill committed Sep 23, 2024
1 parent 0fa8a20 commit ee9ec4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions tests/db-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { spawnSync } from 'node:child_process'
import fs from 'node:fs'
import { faker } from '@faker-js/faker'
import { type PrismaClient } from '@prisma/client'
import bcrypt from 'bcryptjs'
import { UniqueEnforcer } from 'enforce-unique'
import { execaCommand } from 'execa'

const uniqueUsernameEnforcer = new UniqueEnforcer()

Expand Down Expand Up @@ -119,10 +118,10 @@ export async function img({
export async function resetDb(dbPath?: string) {
const databaseUrl = dbPath ? { DATABASE_URL: `file:${dbPath}` } : {}

await execaCommand(
'npx prisma migrate reset --force --skip-seed --skip-generate',
spawnSync(
'npx',
['prisma', 'migrate', 'reset', '--force', '--skip-seed', '--skip-generate'],
{
stdio: 'inherit',
env: {
...process.env,
...databaseUrl,
Expand Down
5 changes: 3 additions & 2 deletions tests/setup/db-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'node:path'
import fsExtra from 'fs-extra'
import { afterAll, afterEach, beforeAll } from 'vitest'
import { BASE_DATABASE_PATH, setup } from './global-setup.ts'
import { resetDb } from '#tests/db-utils.js'
import { BASE_DATABASE_PATH } from './global-setup.ts'

const databaseFile = `./tests/prisma/data.${process.env.VITEST_POOL_ID || 0}.db`
const databasePath = path.join(process.cwd(), databaseFile)
Expand All @@ -12,7 +13,7 @@ beforeAll(async () => {
})

afterEach(async () => {
await setup()
await resetDb()
})

afterAll(async () => {
Expand Down

0 comments on commit ee9ec4e

Please sign in to comment.