Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 2x 8x 8x 8x 4x 4x | /**
* Make a test stream.
*
* @param statements - The statements to yield.
* @param transform - A function to transform the statements.
* @returns A stream of statements.
* @example
* const stream = makeTestStream(['console.log("hello");', 'console.log("world");']);
* for await (const statement of stream) {
* console.log(statement);
* }
*/
export const makeTestStream = <Yield>(
statements: string[],
transform = (statement: string): Yield => statement as Yield,
): { stream: AsyncIterable<Yield>; abort: () => Promise<void> } => {
let shouldAbort = false;
return {
abort: async () => {
shouldAbort = true;
},
stream: (async function* () {
for (const statement of statements) {
Iif (shouldAbort) {
break;
}
yield transform(statement);
}
})(),
};
};
|