Using MailFlat with TestCafe
TestCafe fixtures map cleanly onto inbox lifecycle: beforeEach opens one, afterEach deletes it.
How it fits together
TestCafe test code runs in Node, so the client can be called directly — no task bridge needed.
The test
// tests/signup.js
import { Selector } from "testcafe";
import { MailFlat } from "@mailflat/sdk";
const mf = new MailFlat({ apiKey: process.env.MAILFLAT_API_KEY });
let inbox;
fixture("signup")
.page("https://staging.example.com/signup")
.beforeEach(async () => {
inbox = await mf.create({
prefix: `tc-${Date.now().toString(36)}`,
retentionHours: 2,
});
})
.afterEach(async () => {
await inbox.delete();
});
test("accepts a real verification code", async (t) => {
await t
.typeText("#email", inbox.address)
.click("#submit")
.typeText("#code", await inbox.waitForOtp({ timeout: 60000 }))
.expect(Selector("h1").innerText).contains("Dashboard");
});
Worth knowing
Run TestCafe with --test-execution-timeout high enough to cover the wait, or the runner stops the test mid-poll.