done method

  1. @override
void done(
  1. Object? status
)
override

Implementation

@override
void done(Object? status) {
  if (status is FeatureStatus) {
    buffer.writeln("-------------------");
    buffer.writeln("Scenarios passed: ${status.passedScenariosCount}",
        color: 'green');

    if (status.skippedScenariosCount > 0) {
      buffer.writeln("Scenarios skipped: ${status.skippedScenariosCount}",
          color: 'gray');
    }

    if (status.failedScenariosCount > 0) {
      buffer.writeln("Scenarios failed: ${status.failedScenariosCount}",
          color: 'red');
    }

    buffer.write("Feature time: ${status.duration.inMilliseconds} ms");
  } else if (status is ScenarioStatus) {
    // only write for the whole scenario - background will be reflected in the scenario status
    if (!(status.scenario is _Background)) {
      if ((status.failed || status.undefinedStepsCount > 0)) {
        buffer.writeln("Scenario failed!", color: 'red');
      } else {
        buffer.writeln("Scenario passed!", color: 'green');
      }

      buffer.write("Scenario time: ${status.duration.inMilliseconds} ms");
    }
  } else if (status is StepStatus) {
    var color = 'green';
    var failureMessage = "";

    // set the color based on status or type
    if (status.step!.hook) {
      color = 'blue';
      buffer.write("\t");
    }

    if (status.skipped) {
      color = 'gray';
    }

    if (!status.defined) {
      color = 'yellow';
    }

    if (status.failed) {
      color = "red";
      failureMessage = "\n${status.failure!.error}\n${status.failure!.trace}";
    }

    // always write out the verbiage - this will be the step text
    buffer.write("\t\t${status.decodedVerbiage}", color: color);

    if (status.step!.pyString != null) {
      buffer.writeln("\n\"\"\n${status.step!.pyString}\"\"\"");
    } else {
      buffer.write("\t${status.step!.location}", color: 'gray');
    }

    // write out the table to match irrespective of status
    // don't write a newline after the last row to keep inline with the steps
    if (status.step!.table.isNotEmpty) {
      var counter = 0;
      buffer.write("\n");
      var rows = status.step!.table.gherkinRows();
      rows.forEach((row) {
        buffer.write(row, color: counter == 0 ? 'magenta' : 'cyan');
        counter < rows.length - 1 ? buffer.write("\n") : null;
        counter++;
      });
    }

    if (failureMessage.isNotEmpty) {
      buffer.writeln(failureMessage);
    }

    // need to write out when it's done, or it won't have anything
    // because fmt.step writes before execution
    if (status.out.isNotEmpty) {
      buffer.write("\n");
      buffer.write(status.out.toString());
    }
  }

  buffer.flush();
}