(config: CallbackServerConfig = {})
| 103 | } |
| 104 | |
| 105 | async waitForCallback(config: CallbackServerConfig = {}): Promise<CallbackResponse> { |
| 106 | const { timeout = 600000 } = config; |
| 107 | |
| 108 | try { |
| 109 | this.port = await this.findAvailablePort(this.port); |
| 110 | |
| 111 | this.server = createServer(this.handleRequest); |
| 112 | this.server.listen(this.port, "127.0.0.1"); |
| 113 | |
| 114 | return new Promise<CallbackResponse>((resolve, reject) => { |
| 115 | this.promiseResolve = resolve; |
| 116 | this.promiseReject = reject; |
| 117 | |
| 118 | if (!this.server) { |
| 119 | reject(new Error("Failed to start server")); |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | this.server.on("error", (error) => { |
| 124 | if (this.promiseReject) this.promiseReject(error); |
| 125 | }); |
| 126 | |
| 127 | this.timeoutId = setTimeout(() => { |
| 128 | resolve({ data: { timedOut: true } }); |
| 129 | this.shutdown(); |
| 130 | }, timeout); |
| 131 | |
| 132 | console.log(`Callback server listening on http://127.0.0.1:${this.port}/data`); |
| 133 | }); |
| 134 | } catch (error) { |
| 135 | await this.shutdown(); |
| 136 | throw error; |
| 137 | } |
| 138 | } |
| 139 | } |
no test coverage detected