emitMachineTestReport function

void emitMachineTestReport(
  1. EnsembleTestRunResult result
)

Emits the machine-readable report using the launch environment contract.

Implementation

void emitMachineTestReport(EnsembleTestRunResult result) {
  final reportMode =
      RunnerRuntimeConfiguration.current.string('ensembleTestReport');
  final reportFile =
      RunnerRuntimeConfiguration.current.string('ensembleTestReportFile');
  const emitJsonReport = bool.fromEnvironment('ensembleTestEmitJsonReport');
  // Most widget runs only use the normal boxed reporter. Keep the machine
  // encodings lazy so that an unused JSON or JUnit representation does not
  // allocate a second result tree on every attempt.
  String? encoded;
  String machineJson() => encoded ??= json.encode(result.toJson());
  String? junit;
  String junitXml() => junit ??= JunitTestReport.build(result);
  if (reportFile.isNotEmpty) {
    final file = File(reportFile);
    file.parent.createSync(recursive: true);
    file.writeAsStringSync(
      reportMode == 'junit' ? junitXml() : machineJson(),
    );
  }
  if (usesDeviceArtifactTransport) {
    emitEnsembleTestMachineReport(machineJson());
  } else if (reportMode == 'json' || emitJsonReport) {
    print('ENSEMBLE_TEST_JSON_REPORT:${machineJson()}');
  }
  if (reportMode == 'junit') {
    print(
      'ENSEMBLE_TEST_JUNIT_REPORT:${junitXml().replaceAll('\n', r'\n')}',
    );
  }
}