MCPcopy
hub / github.com/Comfy-Org/ComfyUI_frontend / mock

Method mock

browser_tests/fixtures/helpers/AssetHelper.ts:111–155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

109 this.uploadResponse = config.uploadResponse
110 }
111 async mock(): Promise<void> {
112 const handler = async (route: Route) => {
113 const url = new URL(route.request().url())
114 const method = route.request().method()
115 const path = url.pathname
116 const isMutation = ['POST', 'PUT', 'DELETE'].includes(method)
117 let body: Record<string, unknown> | null = null
118 if (isMutation) {
119 try {
120 body = route.request().postDataJSON()
121 } catch {
122 body = null
123 }
124 }
125
126 if (isMutation) {
127 this.mutations.push({
128 endpoint: path,
129 method,
130 url: route.request().url(),
131 body,
132 timestamp: Date.now()
133 })
134 }
135
136 if (method === 'GET' && /\/assets\/?$/.test(path))
137 return this.handleListAssets(route, url)
138 if (method === 'GET' && /\/assets\/[^/]+$/.test(path))
139 return this.handleGetAsset(route, path)
140 if (method === 'PUT' && /\/assets\/[^/]+$/.test(path))
141 return this.handleUpdateAsset(route, path, body)
142 if (method === 'DELETE' && /\/assets\/[^/]+$/.test(path))
143 return this.handleDeleteAsset(route, path)
144 if (method === 'POST' && /\/assets\/?$/.test(path))
145 return this.handleUploadAsset(route)
146 if (method === 'POST' && path.endsWith('/assets/download'))
147 return this.handleDownloadAsset(route)
148
149 return route.fallback()
150 }
151
152 const pattern = '**/assets**'
153 this.routeHandlers.push({ pattern, handler })
154 await this.page.route(pattern, handler)
155 }
156
157 async mockError(
158 statusCode: number,

Calls

no outgoing calls

Tested by

no test coverage detected