findTestFiles function

List<File> findTestFiles (
  1. Directory packageRoot,
  2. {Glob excludeGlob}
)

Implementation

List<File> findTestFiles(Directory packageRoot, {Glob excludeGlob}) {
  final testsPath = path.join(packageRoot.absolute.path, 'test');
  final testsRoot = Directory(testsPath);
  final contents = testsRoot.listSync(recursive: true);
  final result = <File>[];
  for (final item in contents) {
    if (item is! File) continue;
    if (!item.path.endsWith('_test.dart')) continue;
    final relativePath = item.path.substring(packageRoot.path.length + 1);
    if (excludeGlob != null && excludeGlob.matches(relativePath)) {
      continue;
    }
    result.add(item);
  }
  return result;
}