MCPcopy
hub / github.com/vitest-dev/vitest / create

Function create

packages/runner/src/utils/chain.ts:38–64  ·  view source on GitHub ↗
(context: Record<T, any>)

Source from the content-addressed store, hash-verified

36 context?: Record<string, any>,
37): ChainableFunction<T, (...args: Args) => R> {
38 function create(context: Record<T, any>) {
39 const chain = function (this: any, ...args: Args) {
40 return fn.apply(context, args)
41 }
42 Object.assign(chain, fn)
43 Object.defineProperty(chain, kChainableContext, {
44 value: {
45 withContext: () => chain.bind(context),
46 getFixtures: () => (context as any).fixtures,
47 setContext: (key: T, value: any) => {
48 context[key] = value
49 },
50 mergeContext: (ctx: Record<T, any>) => {
51 Object.assign(context, ctx)
52 },
53 },
54 enumerable: false,
55 })
56 for (const key of keys) {
57 Object.defineProperty(chain, key, {
58 get() {
59 return create({ ...context, [key]: true })
60 },
61 })
62 }
63 return chain
64 }
65
66 const chain = create(context ?? {} as any) as any
67 Object.defineProperty(chain, 'fn', {

Callers 2

getFunction · 0.70
createChainableFunction · 0.70

Calls 1

bindMethod · 0.80

Tested by

no test coverage detected