cancelRunningTests method

Future<void> cancelRunningTests([
  1. Duration timeout = const Duration(minutes: 5)
])

Canceles any currently running test. The current step will be the last to execute, but this may still take a while as the current second could be a long running step.

If no test is currently running, this does nothing.

Implementation

Future<void> cancelRunningTests([
  Duration timeout = const Duration(minutes: 5),
]) async {
  _cancelController.add(null);

  final startTime = DateTime.now();
  while (_testControllerState.runningTest == true) {
    await Future.delayed(const Duration(seconds: 1));
    if (DateTime.now().millisecondsSinceEpoch -
            startTime.millisecondsSinceEpoch >=
        timeout.inMilliseconds) {
      throw Exception(
          '[TIMEOUT]: A timeout has occurred while waiting for the tests to complete.');
    }
  }
}