import { readAll } from "../streams/conversion.ts";import { assert, assertStringIncludes } from "../testing/asserts.ts";
export async function assertCallbackErrorUncaught( { prelude, invocation, cleanup }: { prelude?: string; invocation: string; cleanup?: () => Promise<void> | void; },) { const p = Deno.run({ cmd: [ Deno.execPath(), "eval", "--unstable", `${prelude ?? ""} ${invocation}(err) => { // If the bug is present and the callback is called again with an error, // don't throw another error, so if the subprocess fails we know it had the correct behaviour. if (!err) throw new Error("success"); });`, ], stderr: "piped", }); const status = await p.status(); const stderr = new TextDecoder().decode(await readAll(p.stderr)); p.close(); p.stderr.close(); await cleanup?.(); assert(!status.success); assertStringIncludes(stderr, "Error: success");}