captureToolEvents function

void Function() captureToolEvents(
  1. ToolEventPoster heard
)

Sends everything postToolEvent posts to heard instead of the VM service, until the returned function is called, which puts the VM service back.

final posted = <String>[];
addTearDown(captureToolEvents((kind, data) => posted.add(kind)));

Implementation

void Function() captureToolEvents(ToolEventPoster heard) {
  final before = toolEventCapture;
  toolEventCapture = heard;
  return () => toolEventCapture = before;
}