Skip to content

Commit ee9ec4e

Browse files
committed
run prisma reset via spawn
1 parent 0fa8a20 commit ee9ec4e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tests/db-utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { spawnSync } from 'node:child_process'
12
import fs from 'node:fs'
23
import { faker } from '@faker-js/faker'
3-
import { type PrismaClient } from '@prisma/client'
44
import bcrypt from 'bcryptjs'
55
import { UniqueEnforcer } from 'enforce-unique'
6-
import { execaCommand } from 'execa'
76

87
const uniqueUsernameEnforcer = new UniqueEnforcer()
98

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

122-
await execaCommand(
123-
'npx prisma migrate reset --force --skip-seed --skip-generate',
121+
spawnSync(
122+
'npx',
123+
['prisma', 'migrate', 'reset', '--force', '--skip-seed', '--skip-generate'],
124124
{
125-
stdio: 'inherit',
126125
env: {
127126
...process.env,
128127
...databaseUrl,

tests/setup/db-setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import path from 'node:path'
22
import fsExtra from 'fs-extra'
33
import { afterAll, afterEach, beforeAll } from 'vitest'
4-
import { BASE_DATABASE_PATH, setup } from './global-setup.ts'
4+
import { resetDb } from '#tests/db-utils.js'
5+
import { BASE_DATABASE_PATH } from './global-setup.ts'
56

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

1415
afterEach(async () => {
15-
await setup()
16+
await resetDb()
1617
})
1718

1819
afterAll(async () => {

0 commit comments

Comments
 (0)