runSaveWidget static method
Future<void>
runSaveWidget(
- FileSystemEntity file,
- AnalysisContextCollection collection,
- PubspecData pubspecData,
- DartServerRepository dartServerRepository,
- TestRunInfo testRunInfo,
Implementation
static Future<void> runSaveWidget(
FileSystemEntity file,
AnalysisContextCollection collection,
PubspecData pubspecData,
DartServerRepository dartServerRepository,
TestRunInfo testRunInfo,
) async {
try {
final resolvedUnit = await file.resolveFile(collection);
CompilationUnit unit = resolvedUnit.unit;
final cacheManager = CacheManager();
final saver = WidgetSaver(
dartServerRepository: dartServerRepository,
cacheManager: cacheManager);
saver.init();
final widgets = unit.declarations
.whereType<ClassDeclaration>()
.where((element) => element.declaredElement!.checkIfAWidgetOrState);
for (final widget in widgets) {
final element = widget.declaredElement!;
final fileImport =
'package:${pubspecData.packageName}/${PathUtils.relatetiveLibFilePath(file.path)}';
if (!isAnnotationPresent(element)) continue;
await saver.saveTestsForWidget(
widget: widget,
widgetName: element.name,
compilationUnit: unit,
fileImport: fileImport,
subjectFile: File(file.path),
testRunInfo: testRunInfo,
);
}
} catch (e, stackTrace) {
wtTelemetry.trackError(
severity: Severity.error, error: e, stackTrace: stackTrace);
wtLog.error('Unable to resolve file ${file.path}', verbose: true);
}
}