generateWidget method
Implementation
Future<void> generateWidget({String? filePath}) async {
wtLog.info("Generating widget test");
final dartServerRepository = DartServerRepository();
await dartServerRepository.initialize();
Iterable<FileSystemEntity> fileList = filePath != null
? [File(filePath)]
: (Directory(PathUtils.libPath).listSync(recursive: true))
.where((element) => element.path.endsWith(".dart"));
AnalysisContextCollection collection = AnalysisContextCollection(
includedPaths: [PathUtils.libPath],
resourceProvider: PhysicalResourceProvider.INSTANCE,
);
final testRunInfo = TestRunInfo.newRun();
List<Future> generationFutures = [];
for (FileSystemEntity file in fileList) {
generationFutures.add(
runWidget(
file,
collection,
dartServerRepository,
testRunInfo,
),
);
}
wtLog.startSpinner("Generating Widget Tests");
await Future.wait(generationFutures);
wtLog.stopSpinner(
message:
'✅ Succeeded. Please find the generated tests in `/test` folder.\nCreated: ${testRunInfo.created}\nUpdated:${testRunInfo.updated}\nFailed:${testRunInfo.failed}');
dartServerRepository.dispose();
if (testRunInfo.created > 0 || testRunInfo.updated > 0)
await runMockitoCommand();
}