TestFailureDetails.fromExecutionCode constructor

TestFailureDetails.fromExecutionCode(
  1. String? code,
  2. String text, {
  3. String? phase,
  4. Map<String, dynamic> target = const {},
})

Preserves the execution kernel's machine classification at the report boundary instead of guessing from wording alone.

Implementation

factory TestFailureDetails.fromExecutionCode(
  String? code,
  String text, {
  String? phase,
  Map<String, dynamic> target = const {},
}) {
  final kind = switch (code) {
    'elementNotFound' => TestFailureKind.elementNotFound,
    'ambiguousTarget' => TestFailureKind.ambiguousTarget,
    'unsupportedAction' ||
    'executionUnavailable' ||
    'permissionDenied' =>
      TestFailureKind.unsupportedCapability,
    'actionTimeout' ||
    'cancelled' ||
    'limitExceeded' ||
    'loopLimitExceeded' =>
      TestFailureKind.incompleteExecution,
    'closeFailed' => TestFailureKind.cleanup,
    'internalError' || 'operationException' => TestFailureKind.internal,
    _ => null,
  };
  return kind == null
      ? TestFailureDetails.fromMessage(text, phase: phase, target: target)
      : TestFailureDetails(
          kind: kind,
          message: text,
          phase: phase,
          target: target,
        );
}