UNPKG

systelab-components-wdio-test

Version:
26 lines (25 loc) 975 B
import { HttpStatus } from '../server/http-status.js'; export class TauriDriverRemote { static async start(remoteHost) { await this.executeEndpoint(remoteHost, 'POST', 'start'); } static async stop(remoteHost) { await this.executeEndpoint(remoteHost, 'POST', 'stop'); } static async executeEndpoint(remoteHost, method, route) { const hostname = remoteHost.name; const port = remoteHost.port; const apiPrefix = remoteHost.apiPrefix; const baseURL = `http://${hostname}:${port}/${apiPrefix}`; const endpointURL = `${baseURL}/${route}`; const response = await fetch(endpointURL, { method, headers: { 'content-type': 'application/json' }, }); if (response.status === HttpStatus.INTERNAL_SERVER_ERROR) { const errorMessage = response.body.error; throw new Error('Error: ' + errorMessage); } return response; } }