(bodies: ReadonlyArray<string>, init: ResponseInit = { headers: SSE_HEADERS })
| 83 | * array is reused if the test makes more requests than scripted. |
| 84 | */ |
| 85 | export const scriptedResponses = (bodies: ReadonlyArray<string>, init: ResponseInit = { headers: SSE_HEADERS }) => { |
| 86 | if (bodies.length === 0) throw new Error("scriptedResponses requires at least one body") |
| 87 | return Layer.unwrap( |
| 88 | Effect.gen(function* () { |
| 89 | const cursor = yield* Ref.make(0) |
| 90 | return dynamicResponse((input) => |
| 91 | Effect.gen(function* () { |
| 92 | const index = yield* Ref.getAndUpdate(cursor, (n) => n + 1) |
| 93 | return input.respond(bodies[index] ?? bodies[bodies.length - 1], init) |
| 94 | }), |
| 95 | ) |
| 96 | }), |
| 97 | ) |
| 98 | } |
no test coverage detected