(payload: Record<string, string>)
| 54 | } |
| 55 | |
| 56 | async function simulateBrowserCallback(payload: Record<string, string>) { |
| 57 | if (!currentServerHandler) { |
| 58 | throw new Error("missing loopback server handler"); |
| 59 | } |
| 60 | |
| 61 | const req = new EventEmitter() as EventEmitter & { |
| 62 | method: string; |
| 63 | setEncoding: (encoding: string) => void; |
| 64 | }; |
| 65 | req.method = "POST"; |
| 66 | req.setEncoding = vi.fn(); |
| 67 | |
| 68 | const res = { |
| 69 | statusCode: 200, |
| 70 | headers: {} as Record<string, string>, |
| 71 | setHeader: vi.fn((name: string, value: string) => { |
| 72 | res.headers[name] = value; |
| 73 | }), |
| 74 | end: vi.fn(), |
| 75 | }; |
| 76 | |
| 77 | const body = new URLSearchParams(payload).toString(); |
| 78 | const handlerPromise = Promise.resolve(currentServerHandler(req, res)); |
| 79 | |
| 80 | queueMicrotask(() => { |
| 81 | req.emit("data", body); |
| 82 | req.emit("end"); |
| 83 | }); |
| 84 | |
| 85 | await handlerPromise; |
| 86 | expect(res.end).toHaveBeenCalled(); |
| 87 | } |
| 88 | |
| 89 | describe("login", () => { |
| 90 | let mockStdout: ReturnType<typeof vi.spyOn>; |
no test coverage detected