-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
version.test.ts
106 lines (91 loc) · 3.25 KB
/
version.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { getCliQueryEngineBinaryType } from '@prisma/engines'
import { BinaryType, download } from '@prisma/fetch-engine'
import { getPlatform } from '@prisma/get-platform'
import { engineEnvVarMap } from '@prisma/sdk'
import makeDir from 'make-dir'
import path from 'path'
import { consoleContext, Context } from './__helpers__/context'
const ctx = Context.new().add(consoleContext()).assemble()
const testIf = (condition: boolean) => (condition ? test : test.skip)
const useNodeAPI = getCliQueryEngineBinaryType() === BinaryType.libqueryEngine
const version = 'e6bd3dc12d849124a04c3a8e6bd9c194381afda3'
describe('version', () => {
// Node-API Tests
testIf(useNodeAPI)('basic version (Node-API)', async () => {
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
})
testIf(useNodeAPI)(
'version with custom binaries (Node-API)',
async () => {
const enginesDir = path.join(__dirname, 'version-test-engines')
await makeDir(enginesDir)
const binaryPaths = await download({
binaries: {
'introspection-engine': enginesDir,
'migration-engine': enginesDir,
'prisma-fmt': enginesDir,
'libquery-engine': enginesDir,
},
version,
failSilent: false,
})
// This Omits query-engine from the map
const { ['query-engine']: qe, ...envVarMap } = engineEnvVarMap
const platform = await getPlatform()
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
process.env[envVar] = binaryPaths[engine][platform]
// console.debug(`Setting ${envVar} to ${binaryPaths[engine][platform]}`)
}
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
// cleanup
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
delete process[envVar]
}
},
20000,
)
// Binary Tests
testIf(!useNodeAPI)('basic version', async () => {
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
})
testIf(!useNodeAPI)(
'version with custom binaries',
async () => {
const enginesDir = path.join(__dirname, 'version-test-engines')
await makeDir(enginesDir)
const binaryPaths = await download({
binaries: {
'introspection-engine': enginesDir,
'migration-engine': enginesDir,
'prisma-fmt': enginesDir,
'query-engine': enginesDir,
},
version,
failSilent: false,
})
const platform = await getPlatform()
const { ['libquery-engine']: qe, ...envVarMap } = engineEnvVarMap
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
process.env[envVar] = binaryPaths[engine][platform]
// console.debug(`Setting ${envVar} to ${binaryPaths[engine][platform]}`)
}
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
// cleanup
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
delete process[envVar]
}
},
20000,
)
})
function cleanSnapshot(str: string): string {
return str.replace(/:(.*)/g, ': placeholder')
}