| 14 | const msg: Record<string, unknown> = { id, method }; |
| 15 | if (params !== undefined) msg.params = params; |
| 16 | return { line: JSON.stringify(msg) + "\n", id }; |
| 17 | } |
| 18 | |
| 19 | async function captureErrorMessage(promise: Promise<unknown>): Promise<string> { |
| 20 | // Workaround: bun test on Windows doesn't flush .rejects properly, so we |
| 21 | // capture the rejection message manually instead of using .rejects.toThrow(). |
| 22 | let resolved = false; |
| 23 | try { |
| 24 | await promise; |
| 25 | resolved = true; |
| 26 | } catch (e) { |
| 27 | return e instanceof Error ? e.message : String(e); |
| 28 | } |
| 29 | if (resolved) throw new Error("Expected promise to reject, but it resolved"); |
| 30 | return ""; // unreachable |
| 31 | } |