run method
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();
final packageRoot = getPackageRoot();
final repository = ReportRepository(packageRoot);
final hasReports = await repository.hasReports();
if (!hasReports) {
print('''
⚠️ No test report found at .testRocket/report.csv!
To generate reports and track trends over time, run your tests with:
testRocket run
(or 'testRocket run --coverage' to include code coverage)
''');
return 0;
}
final records = await repository.getAllRecords();
if (records.isEmpty) {
print('''
⚠️ No test runs recorded in .testRocket/report.csv!
To record test runs, run your tests with:
testRocket run
(or 'testRocket run --coverage' to include code coverage)
''');
return 0;
}
final limit = int.tryParse(argResults?['limit'] ?? '10') ?? 10;
final config = await RocketConfig.fromPackageRoot(packageRoot);
final cliMinCoverage = argResults?['min-coverage'] != null
? double.tryParse(argResults?['min-coverage'])
: null;
final targetCoverage = cliMinCoverage ?? config.minCoverage;
final chart = TrendChart(records, targetCoverage: targetCoverage);
print(chart.renderTerminalView(limit: limit));
final exportHtml = argResults?['html'] ?? true;
final shouldOpen = argResults?['open'] ?? true;
if (exportHtml) {
final htmlContent = chart.generateHtmlDashboard();
final htmlFile =
File(path.join(packageRoot, '.testRocket', 'trends.html'));
await htmlFile.create(recursive: true);
await htmlFile.writeAsString(htmlContent);
print('📊 HTML dashboard generated at ${htmlFile.path}');
if (shouldOpen) {
print('🌐 Opening trends dashboard in your browser...');
await _openInBrowser(htmlFile.path);
}
}
return 0;
}