writeOptimizedFile method
The files
param's key is the value of the type of test
The base values for this are dart
for dart tests and flutter
for flutter tests.
When these values are different, it is because flutter has specific
tests to be run. Such as LiveTestWidgetsFlutterBinding
, the value would
be live
Implementation
String writeOptimizedFile(
Iterable<String> files, {
required String testDir,
}) {
({String packageName, String barrelFile})? exportFile;
if (PubspecYamlImpl(fs: fs).parse()?['name']
case final String packageName) {
final possibleNames = [
packageName,
fs.currentDirectory.basename,
];
for (final name in possibleNames) {
if (path.join('lib', '$name.dart') case final path
when fs.file(path).existsSync()) {
exportFile = (packageName: packageName, barrelFile: '$name.dart');
}
}
}
final optimizedPath = path.join(testDir, '$optimizedTestBasename.dart');
fs.file(optimizedPath).createSync(recursive: true);
final testDirs = files.map(
(e) => Testable(
absolute: e,
optimizedPath: optimizedPath,
),
);
final content = writeOptimizedTestFile(
testDirs,
barrelFile: exportFile,
);
fs.file(optimizedPath).writeAsStringSync(content);
return optimizedPath;
}