Skip to content

Commit

Permalink
Reland "Add missing TimelineMode.off checks (#88)"
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Jan 3, 2025
1 parent d5aa0f8 commit ebebbeb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
8 changes: 8 additions & 0 deletions lib/src/screenshot/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ extension TimelineSyncScreenshot on Timeline {
List<ScreenshotAnnotator>? annotators,
}) {
final Frame? frame = _caller();

if (timeline.mode == TimelineMode.off) {
// ignore: avoid_print
print(
'Warning: The timeline is off, do not take screenshots for the timeline\n'
' at ${frame?.member} ${frame?.uri}:${frame?.line}:${frame?.column}',
);
}
final liveElement = _findSingleElement(
element: element,
snapshot: snapshot,
Expand Down
70 changes: 38 additions & 32 deletions lib/src/spot/snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,18 @@ extension MultiWidgetSelectorMatcher<W extends Widget> on WidgetSnapshot<W> {
final errorBuilder = StringBuffer();
errorBuilder.writeln('Could not find $selector in widget tree');
_dumpWidgetTree(errorBuilder);
timeline.addEvent(
eventType: 'Assertion Failed',
details: errorBuilder.toString(),
color: Colors.red,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
if (timeline.mode != TimelineMode.off) {
timeline.addEvent(
eventType: 'Assertion Failed',
details: errorBuilder.toString(),
color: Colors.red,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
}
fail('Could not find $selector in widget tree');
}
}
Expand All @@ -470,32 +472,36 @@ extension MultiWidgetSelectorMatcher<W extends Widget> on WidgetSnapshot<W> {
});

final tree = findCommonAncestor(discoveredElements).toStringDeep();
timeline.addEvent(
eventType: 'Assertion Failed',
details: '$errorBuilder\n'
'$tree',
color: Colors.red,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
if (timeline.mode != TimelineMode.off) {
timeline.addEvent(
eventType: 'Assertion Failed',
details: '$errorBuilder\n'
'$tree',
color: Colors.red,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
}
fail(errorBuilder.toString());
}
}

timeline.addEvent(
eventType: 'Assertion',
details:
'Found ${discovered.length} widgets matching $selector.\nExpected: ${min != null ? "min:$min," : ''}${max != null ? "max:$max," : ''}',
color: Colors.grey,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
if (timeline.mode != TimelineMode.off) {
timeline.addEvent(
eventType: 'Assertion',
details:
'Found ${discovered.length} widgets matching $selector.\nExpected: ${min != null ? "min:$min," : ''}${max != null ? "max:$max," : ''}',
color: Colors.grey,
screenshot: timeline.takeScreenshotSync(
annotators: [
HighlightAnnotator.elements(discoveredElements),
],
),
);
}
return this;
}
}
Expand Down

0 comments on commit ebebbeb

Please sign in to comment.