MCPcopy Index your code
hub / github.com/simstudioai/sim / createFakeClient

Function createFakeClient

packages/db/tx-tripwire.test.ts:24–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22}
23
24function createFakeClient() {
25 const rootQueries: string[] = []
26 const reservedQueries: string[] = []
27
28 const client = instrumentPoolClient(
29 {
30 unsafe(query: string) {
31 rootQueries.push(query)
32 return Promise.resolve([])
33 },
34 // Mirrors postgres-js: begin issues its internal BEGIN through the root
35 // client's unsafe (the instrumented one) before running the callback on
36 // a reserved connection.
37 begin(...args: unknown[]) {
38 const callback = args[args.length - 1] as (reserved: FakeReserved) => unknown
39 const reserved: FakeReserved = {
40 unsafe: (query: string) => {
41 reservedQueries.push(query)
42 return Promise.resolve([])
43 },
44 }
45 return Promise.resolve(this.unsafe('begin')).then(() => callback(reserved))
46 },
47 },
48 'test-pool'
49 )
50
51 return { client, rootQueries, reservedQueries }
52}
53
54afterEach(() => {
55 vi.unstubAllEnvs()

Callers 1

Calls 1

instrumentPoolClientFunction · 0.90

Tested by

no test coverage detected