forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
46 lines (37 loc) · 1.23 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { ClientEngineType, getClientEngineType } from '@prisma/internals'
import { getTestClient } from '../../../../utils/getTestClient'
const testIf = (condition: boolean) => (condition ? test : test.skip)
testIf(getClientEngineType() === ClientEngineType.Binary)('exit-hook for sigint', async () => {
expect.assertions(2)
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
// set up beforeExit hook and make sure we have the result available outside
let beforeExitResult
prisma.$on('beforeExit', () => {
beforeExitResult = doWork(prisma)
})
// set up our own additional handler for SIGINT
let processHookCalled = false
process.on('SIGINT', () => {
processHookCalled = true
})
// trigger via: emit SIGINT
process.emit('SIGINT', 'SIGINT')
// expectations
expect(processHookCalled).toBe(true)
beforeExitResult = await beforeExitResult
expect(beforeExitResult).toMatchInlineSnapshot(`
[
{
email: [email protected],
id: 576eddf9-2434-421f-9a86-58bede16fd95,
name: Alice,
},
]
`)
await prisma.$disconnect()
})
async function doWork(prisma: Awaited<ReturnType<typeof getTestClient>>) {
const users = await prisma.user.findMany()
return users
}