writeOptimizedTestFile function

String writeOptimizedTestFile(
  1. Iterable<Testable> testables, {
  2. required ({String barrelFile, String packageName})? barrelFile,
})

Implementation

String writeOptimizedTestFile(
  Iterable<Testable> testables, {
  required ({String packageName, String barrelFile})? barrelFile,
}) {
  var barrel = '';

  if (barrelFile != null) {
    final (:packageName, barrelFile: file) = barrelFile;
    barrel = "import 'package:$packageName/$file';\n";
  }

  var count = 0;
  final indexedTestables = testables.map((e) => (count++, e)).toList();
  return '''
import 'dart:async';
$barrel
import 'package:test/test.dart';
${indexedTestables.map((e) => _writeImport(e.$1, e.$2)).join('\n')}

void main() {
  ${indexedTestables.map((e) => _writeTest(e.$1, e.$2)).join('\n  ')}
}
''';
}