| 15 | * Returns an in-memory client for testing |
| 16 | */ |
| 17 | export 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. |