(files: string | string[] | File | File[], options?: UserEventUploadOptions)
| 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>( |
nothing calls this directly
no test coverage detected