forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preinstall.test.ts
55 lines (39 loc) · 2.45 KB
/
preinstall.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
47
48
49
50
51
52
53
54
55
import { jestConsoleContext, jestContext } from '@prisma/get-platform'
import { printMessageAndExitIfUnsupportedNodeVersion } from '../../scripts/preinstall'
const ctx = jestContext.new().add(jestConsoleContext()).assemble()
it('should exit 1 and print a message when Node.js version is lower than minimum - 16.0', () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation()
printMessageAndExitIfUnsupportedNodeVersion('v16.0.0')
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`
"┌──────────────────────────────────────────────┐
│ Prisma only supports Node.js >= 16.13. │
│ Please upgrade your Node.js version. │
└──────────────────────────────────────────────┘"
`)
expect(mockExit).toHaveBeenCalledWith(1)
mockExit.mockRestore()
})
it('should exit 1 and print a message when Node.js version is lower than minimum - 14.13', () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation()
printMessageAndExitIfUnsupportedNodeVersion('v14.13.0')
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`
"┌──────────────────────────────────────────────┐
│ Prisma only supports Node.js >= 16.13. │
│ Please upgrade your Node.js version. │
└──────────────────────────────────────────────┘"
`)
expect(mockExit).toHaveBeenCalledWith(1)
mockExit.mockRestore()
})
it('should do nothing when Node.js version is supported - 16.13', () => {
printMessageAndExitIfUnsupportedNodeVersion('v16.13.0')
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})
it('should do nothing when Node.js version is supported - current', () => {
printMessageAndExitIfUnsupportedNodeVersion(process.version)
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})
it('should do nothing when Node.js version is supported - 20.0', () => {
printMessageAndExitIfUnsupportedNodeVersion('v20.0.0')
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})