( appPath: string, options: BrowserStackUploadOptions, )
| 158 | }; |
| 159 | |
| 160 | export async function uploadBrowserStackApp( |
| 161 | appPath: string, |
| 162 | options: BrowserStackUploadOptions, |
| 163 | ): Promise<string> { |
| 164 | const file = await fs.readFile(appPath); |
| 165 | const form = new FormData(); |
| 166 | form.set('file', new Blob([file]), path.basename(appPath)); |
| 167 | const response = await fetch(options.endpoint ?? BROWSERSTACK_APP_UPLOAD_ENDPOINT, { |
| 168 | method: 'POST', |
| 169 | headers: { |
| 170 | ...agentDeviceRequestHeaders(), |
| 171 | Authorization: basicAuthHeader(options), |
| 172 | }, |
| 173 | body: form, |
| 174 | }); |
| 175 | const json = (await response.json()) as unknown; |
| 176 | const appUrl = readBrowserStackAppUrl(json); |
| 177 | if (!response.ok || !appUrl) { |
| 178 | throw new AppError('COMMAND_FAILED', 'BrowserStack app upload failed.', { |
| 179 | status: response.status, |
| 180 | response: json, |
| 181 | }); |
| 182 | } |
| 183 | return appUrl; |
| 184 | } |
| 185 | |
| 186 | export function createBrowserStackUploadApp( |
| 187 | options: Required<BrowserStackUploadOptions>, |
no test coverage detected