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

Function upload

packages/browser/src/client/tester/locators/index.ts:139–165  ·  view source on GitHub ↗
(files: string | string[] | File | File[], options?: UserEventUploadOptions)

Source from the content-addressed store, hash-verified

137 }
138
139 public upload(files: string | string[] | File | File[], options?: UserEventUploadOptions): Promise<void> {
140 return ensureAwaited(async (error) => {
141 const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
142 if (typeof file === 'string') {
143 return file
144 }
145 const bas64String = await new Promise<string>((resolve, reject) => {
146 const reader = new FileReader()
147 reader.onload = () => resolve(reader.result as string)
148 reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`))
149 reader.readAsDataURL(file)
150 })
151
152 return {
153 name: file.name,
154 mimeType: file.type,
155 // strip prefix `data:[<media-type>][;base64],`
156 base64: bas64String.slice(bas64String.indexOf(',') + 1),
157 }
158 })
159 return getBrowserState().commands.triggerCommand<void>(
160 '__vitest_upload',
161 [this.selector, await Promise.all(filesPromise), options],
162 error,
163 )
164 })
165 }
166
167 public dropTo(target: Locator, options: UserEventDragAndDropOptions = {}): Promise<void> {
168 return this.triggerCommand<void>(

Callers

nothing calls this directly

Calls 7

ensureAwaitedFunction · 0.90
getBrowserStateFunction · 0.90
triggerCommandMethod · 0.80
allMethod · 0.80
resolveFunction · 0.50
rejectFunction · 0.50
indexOfMethod · 0.45

Tested by

no test coverage detected