Skip to content

Commit

Permalink
tests(client): add test for custom engine binary path (prisma#9844)
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln authored Oct 20, 2021
1 parent 38883a8 commit 455074a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ tmp
pnpm-debug.log
sandbox
.DS_Store

query-engine*
libquery_engine*

*tmp.db
dist/
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
}

generator client {
provider = "prisma-client-js"
}

model User {
id String @id @default(uuid())
email String @unique
name String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getNodeAPIName, getPlatform } from '@prisma/get-platform'
import fs from 'fs'
import path from 'path'
import { ClientEngineType, getClientEngineType } from '../../../../runtime/utils/getClientEngineType'
import { generateTestClient } from '../../../../utils/getTestClient'

if (getClientEngineType() === ClientEngineType.DataProxy) {
// eslint-disable-next-line no-global-assign
test = test.skip
}

test('custom engine binary path (internal API)', async () => {
await generateTestClient()

const platform = await getPlatform()

const binaryFileName =
getClientEngineType() === ClientEngineType.Library ? getNodeAPIName(platform, 'fs') : `query-engine-${platform}`

const defaultBinaryPath = path.join(__dirname, 'node_modules/.prisma/client', binaryFileName)
const customBinaryPath = path.join(__dirname, binaryFileName)

fs.copyFileSync(defaultBinaryPath, customBinaryPath)
fs.unlinkSync(defaultBinaryPath)

const { PrismaClient } = require('./node_modules/@prisma/client')

const prisma = new PrismaClient({
__internal: {
engine: {
binaryPath: customBinaryPath,
},
},
})

expect(prisma._engineConfig.prismaPath).toBe(customBinaryPath)

if (getClientEngineType() === ClientEngineType.Binary) {
expect(prisma._engine.prismaPath).toBe(customBinaryPath)
expect(await prisma._engine.getPrismaPath()).toBe(customBinaryPath)
}

const users = await prisma.user.findMany()
expect(users).toEqual([])

prisma.$disconnect()
})

0 comments on commit 455074a

Please sign in to comment.