run method

  1. @override
FutureOr<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
FutureOr<int> run() async {
  exitIfNotValidDartPackage();
  print(
    'āš ļø "testRocket doctor" is experimental! We are working to make this accurate!',
  );
  final packageRoot = getPackageRoot();
  final suspects = (argResults?['suspect'] as List<String>?) ?? const [];
  final maxVictims =
      int.tryParse(argResults?['max-victims'] as String? ?? '5') ?? 5;
  final emitJson = argResults?['json'] as bool? ?? false;
  final outputPath = argResults?['output'] as String?;

  final writtenBundles = <File>[];

  try {
    final runner = DoctorRunner(
      testRepository: TestRepository(packageRoot),
      runBundle: _makeBundleRunner(packageRoot, writtenBundles),
      packageRoot: packageRoot,
      maxVictims: maxVictims,
      onProgress: (msg) => stdout.writeln(msg),
    );

    final report = await runner.diagnose(
      suspectPaths: suspects.isEmpty ? null : suspects,
    );

    final writer = DoctorReportWriter(
      packageRoot,
      markdownOutputPath: outputPath,
    );
    stdout.write(writer.renderStdout(report));
    final markdownFile = writer.writeMarkdown(report);
    stdout.writeln('\nšŸ“„ Report written to ${markdownFile.path}');
    if (emitJson) {
      final jsonFile = writer.writeJson(report);
      stdout.writeln('šŸ“„ JSON written to ${jsonFile.path}');
    }
    return report.exitCode;
  } finally {
    for (final f in writtenBundles) {
      if (f.existsSync()) f.deleteSync();
    }
  }
}