runJuiceFlow function
The body of juiceFlowTest, callable directly — from a test with its
own setup, or inside testWidgets through tester.runAsync (a flow
waits on the real clock, which testWidgets replaces).
Implementation
Future<void> runJuiceFlow(
FutureOr<void> Function(JuiceFlow flow) body, {
bool virtualTime = false,
}) async {
final flow = JuiceFlow._start(virtualTime);
// Whatever stops this test — a timeout, a driver that throws — the
// global state the flow took is handed back and BlocScope reset, so the
// tests after it start clean. Idempotent: a flow that ended normally has
// handed everything back already.
scaffolding.addTearDown(flow._abandon);
if (!virtualTime) return _run(flow, body);
// The whole flow — body, end checks, closing — runs on the virtual
// clock; what it ended with is reported out here, on the real one.
final time = _VirtualTime(FakeAsync(), flow);
try {
await _runVirtual(flow, body, time);
} finally {
flow._handBack();
}
}