forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion.test.ts
More file actions
137 lines (115 loc) · 5.58 KB
/
Copy pathVersion.test.ts
File metadata and controls
137 lines (115 loc) · 5.58 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { enginesVersion, getCliQueryEngineBinaryType } from '@prisma/engines'
import { BinaryType, download } from '@prisma/fetch-engine'
import { getBinaryTargetForCurrentPlatform, jestConsoleContext, jestContext } from '@prisma/get-platform'
import { engineEnvVarMap } from '@prisma/internals'
import { ensureDir } from 'fs-extra'
import path from 'path'
import packageJson from '../../../package.json'
const ctx = jestContext.new().add(jestConsoleContext()).assemble()
const testIf = (condition: boolean) => (condition ? test : test.skip)
const runLibraryTest =
getCliQueryEngineBinaryType() === BinaryType.QueryEngineLibrary && !process.env.PRISMA_QUERY_ENGINE_LIBRARY
const runBinaryTest =
getCliQueryEngineBinaryType() === BinaryType.QueryEngineBinary && !process.env.PRISMA_QUERY_ENGINE_BINARY
describe('version', () => {
// Node-API Tests
testIf(runLibraryTest)('basic version (Node-API)', async () => {
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
})
testIf(runLibraryTest)(
'version with custom binaries (Node-API)',
async () => {
const enginesDir = path.join(__dirname, 'version-test-engines')
await ensureDir(enginesDir)
const binaryPaths = await download({
binaries: {
'schema-engine': enginesDir,
'libquery-engine': enginesDir,
},
version: enginesVersion,
failSilent: false,
})
// This Omits query-engine from the map
const { ['query-engine']: qe, ...envVarMap } = engineEnvVarMap
const binaryTarget = await getBinaryTargetForCurrentPlatform()
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
process.env[envVar] = binaryPaths[engine][binaryTarget]
}
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout, enginesVersion)).toMatchSnapshot()
// cleanup
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
delete process[envVar]
}
},
50_000,
)
// Binary Tests
testIf(runBinaryTest)(
'basic version',
async () => {
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout)).toMatchSnapshot()
},
10_000,
)
testIf(runBinaryTest)(
'version with custom binaries',
async () => {
const enginesDir = path.join(__dirname, 'version-test-engines')
await ensureDir(enginesDir)
const binaryPaths = await download({
binaries: {
'schema-engine': enginesDir,
'query-engine': enginesDir,
},
version: enginesVersion,
failSilent: false,
})
const binaryTarget = await getBinaryTargetForCurrentPlatform()
const { ['libquery-engine']: qe, ...envVarMap } = engineEnvVarMap
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
process.env[envVar] = binaryPaths[engine][binaryTarget]
}
const data = await ctx.cli('--version')
expect(cleanSnapshot(data.stdout, enginesVersion)).toMatchSnapshot()
// cleanup
for (const engine in envVarMap) {
const envVar = envVarMap[engine]
delete process[envVar]
}
},
50_000,
)
})
function cleanSnapshot(str: string, versionOverride?: string): string {
// sanitize engine path
// Query Engine (Node-API) : libquery-engine e996df5d66a2314d1da15d31047f9777fc2fbdd9 (at ../../home/runner/work/prisma/prisma/node_modules/.pnpm/@prisma+engines@3.11.0-41.e996df5d66a2314d1da15d31047f9777fc2fbdd9/node_modules/@prisma/engines/libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node)
// + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Query Engine (Node-API) : libquery-engine 5a2e5869b69a983e279380ec68596b71beae9eff (at ../../cli/src/__tests__/commands/version-test-engines/libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node, resolved by PRISMA_QUERY_ENGINE_LIBRARY)
// => ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Query Engine (Node-API) : libquery-engine e996df5d66a2314d1da15d31047f9777fc2fbdd9 (at sanitized_path/libquery_engine-TEST_PLATFORM.LIBRARY_TYPE.node)
// ^^^^^^^^^^^^^^^^^^^
str = str.replace(/\(at (.*engines)(\/|\\)/g, '(at sanitized_path/')
// TODO: replace '[a-z0-9]{40}' with 'ENGINE_VERSION'.
// Currently, the engine version of @prisma/prisma-schema-wasm isn't necessarily the same as the enginesVersion
str = str.replace(/([0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.)([a-z0-9-]+)/g, 'CLI_VERSION.ENGINE_VERSION')
// replace engine version hash
const defaultEngineVersion = enginesVersion
const currentEngineVersion = versionOverride ?? enginesVersion
str = str.replace(new RegExp(currentEngineVersion, 'g'), 'ENGINE_VERSION')
str = str.replace(new RegExp(defaultEngineVersion, 'g'), 'ENGINE_VERSION')
str = str.replace(new RegExp('(Operating System\\s+:).*', 'g'), '$1 OS')
str = str.replace(new RegExp('(Architecture\\s+:).*', 'g'), '$1 ARCHITECTURE')
str = str.replace(new RegExp('workspace:\\*', 'g'), 'ENGINE_VERSION')
str = str.replace(new RegExp(process.version, 'g'), 'NODEJS_VERSION')
// replace studio version
str = str.replace(packageJson.devDependencies['@prisma/studio-server'], 'STUDIO_VERSION')
// sanitize windows specific engine names
str = str.replace(/\.exe/g, '')
return str
}