MCPcopy
hub / github.com/prisma/prisma / getTestClient

Function getTestClient

packages/client/src/utils/getTestClient.ts:17–59  ·  packages/client/src/utils/getTestClient.ts::getTestClient
(schemaDir?: string, printWarnings?: boolean)

Source from the content-addressed store, hash-verified

15 * Returns an in-memory client for testing
16 */
17export async function getTestClient(schemaDir?: string, printWarnings?: boolean): Promise<any> {
18 const callSite = path.dirname(require.main?.filename ?? class="st">'')
19 const absSchemaDir = path.resolve(callSite, schemaDir ?? class="st">'')
20
21 const { schemas: datamodel } = (await getSchemaWithPath({
22 schemaPath: { baseDir: absSchemaDir },
23 cwd: absSchemaDir,
24 }))!
25
26 const config = await getConfig({ datamodel })
27 if (printWarnings) {
28 printConfigWarnings(config.warnings)
29 }
30
31 const generator = config.generators.find((g) => parseEnvValue(g.provider) === BuiltInProvider.PrismaClientJs)
32 ;(global as any).TARGET_BUILD_TYPE = class="st">'client'
33
34 const document = await getDMMF({ datamodel })
35 const activeProvider = config.datasources[0].activeProvider
36 const options: GetPrismaClientConfig = {
37 runtimeDataModel: dmmfToRuntimeDataModel(document.datamodel),
38 previewFeatures: generator?.previewFeatures ?? [],
39 clientVersion: class="st">'0.0.0',
40 engineVersion: class="st">'0000000000000000000000000000000000000000',
41 activeProvider,
42 inlineSchema: datamodel[0][1], class="cm">// TODO: merge schemas
43 compilerWasm: {
44 getRuntime: () => Promise.resolve(require(path.join(runtimeBase, `query_compiler_fast_bg.${activeProvider}.js`))),
45 getQueryCompilerWasmModule: () => {
46 const queryCompilerWasmFilePath = path.join(
47 runtimeBase,
48 `query_compiler_fast_bg.${activeProvider}.wasm-base64.js`,
49 )
50 const wasmBase64: string = require(queryCompilerWasmFilePath).wasm
51 return Promise.resolve(new WebAssembly.Module(Buffer.from(wasmBase64, class="st">'base64')))
52 },
53 importName: class="st">'./query_compiler_fast_bg.js',
54 },
55 parameterizationSchema: buildAndSerializeParamGraph(document),
56 }
57
58 return getPrismaClient(options)
59}
60
61/**
62 * Options of `generateTestClient` function.

Callers 15

runtimeIntegrationTestFunction · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90

Calls 9

getSchemaWithPathFunction · 0.90
getConfigFunction · 0.90
printConfigWarningsFunction · 0.90
parseEnvValueFunction · 0.90
dmmfToRuntimeDataModelFunction · 0.90
getPrismaClientFunction · 0.90
fromMethod · 0.80
getDMMFFunction · 0.50

Tested by 1

runtimeIntegrationTestFunction · 0.72