createTestCommand method

CommandToRun createTestCommand({
  1. required String projectRoot,
  2. required String relativeProjectRoot,
  3. required DetermineFlutterOrDart tool,
  4. required List<String> flutterArgs,
  5. required List<String> dartArgs,
  6. required List<String> tests,
})

Implementation

CommandToRun createTestCommand({
  required String projectRoot,
  required String relativeProjectRoot,
  required DetermineFlutterOrDart tool,
  required List<String> flutterArgs,
  required List<String> dartArgs,
  required List<String> tests,
}) {
  if (tests.isEmpty) {
    throw Exception('Cannot create a command without tests');
  }

  final toolArgs = tool.isFlutter ? flutterArgs : dartArgs;

  final command = tool.tool();

  final script = '$command test ${tests.join(' ')} ${toolArgs.join(' ')}';

  logger.detail('Test command: $script');

  var label = darkGray.wrap('Running (')!;
  label += cyan.wrap(command)!;
  if (tool.testType != null) {
    label += darkGray.wrap(' | ')!;
    label += magenta.wrap(tool.testType!.toUpperCase())!;
  }
  if (tests.length == 1) {
    label += darkGray.wrap(') tests in ')!;

    label += yellow.wrap(relativeProjectRoot)!;
  } else {
    label += darkGray.wrap(') tests for ')!;

    label += yellow.wrap(tests.join(', '))!;
  }

  return CommandToRun(
    command: script,
    workingDirectory: projectRoot,
    keys: ['dart', 'test', ...tests, ...toolArgs],
    label: label,
  );
}