import { createServer } from "node:http";
import { once } from "node:events";
import { Firedrill } from "@firedrill-run/sdk";
import { withBrowserEvidence } from "@firedrill-run/sdk/browser";
const server = createServer((_request, response) => {
response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
response.end('<!doctype html><html><head><title>Confirmation example</title></head>' +
'<body><h1>Confirmation</h1><p id="status">Waiting</p>' +
'<button onclick="document.querySelector(\'#status\').textContent=\'Confirmed\'">' +
'Confirm</button></body></html>');
});
server.listen(0, "127.0.0.1");
await once(server, "listening");
const url = "http://127.0.0.1:" + server.address().port;
try {
const client = Firedrill.fromConfig();
const result = await client.simulate({
name: "Observe a confirmation workflow",
scenarios: [{ id: "confirm", name: "Confirm once", input: null }],
limits: { timeoutMs: 30000, maxRuns: 1, maxOutputBytes: 4096 },
}, async (_input, context) => {
const capture = await withBrowserEvidence(context, {
url,
allowedOrigins: [url],
screenshot: true,
trace: false,
video: false,
sink: context.attach,
}, async ({ page }) => {
await page.getByRole("button", { name: "Confirm", exact: true }).click();
return { status: await page.locator("#status").innerText() };
});
return capture.value;
});
console.log(result.reportUrl);
} finally {
server.close();
}