Skip to content

Commit

Permalink
Do not print the partial widget tree to console, only to timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Nov 12, 2024
1 parent 6da4051 commit d48d098
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 42 deletions.
29 changes: 17 additions & 12 deletions lib/src/spot/snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Could not find ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected at least $minimumConstraint',
'expected at least $minimumConstraint.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand All @@ -278,7 +279,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Found $count elements matching ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected at least $minimumConstraint',
'expected at least $minimumConstraint.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand All @@ -290,7 +292,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Found $count elements matching ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected at most $maximumConstraint',
'expected at most $maximumConstraint.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand All @@ -309,7 +312,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Could not find ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected exactly $exactCount',
'expected exactly $exactCount.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand All @@ -318,7 +322,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Found $count elements matching ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected exactly $exactCount',
'expected exactly $exactCount.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand All @@ -329,7 +334,8 @@ extension ValidateQuantity<W extends Widget> on WidgetSnapshot<W> {
throw QuantityTestFailure(
message:
'Found $count elements matching ${unconstrainedSelector.toStringBreadcrumb()} in widget tree, '
'expected between $minimumConstraint and $maximumConstraint',
'expected between $minimumConstraint and $maximumConstraint.\n'
'Check the timeline at the very bottom for more information.',
significantWidgetTree: significantWidgetTree(),
snapshot: this,
);
Expand Down Expand Up @@ -377,9 +383,10 @@ class QuantityTestFailure implements TestFailure {

@override
String toString() {
return '$message\n'
'$significantWidgetTree\n'
'$message';
return '$message';
// return '$message\n'
// '$significantWidgetTree\n'
// '$message';
}
}

Expand Down Expand Up @@ -438,7 +445,6 @@ extension MultiWidgetSelectorMatcher<W extends Widget> on WidgetSnapshot<W> {
final errorBuilder = StringBuffer();
errorBuilder.writeln('Could not find $selector in widget tree');
_dumpWidgetTree(errorBuilder);
errorBuilder.writeln('Could not find $selector in widget tree');
timeline.addEvent(
eventType: 'Assertion Failed',
details: errorBuilder.toString(),
Expand All @@ -449,7 +455,7 @@ extension MultiWidgetSelectorMatcher<W extends Widget> on WidgetSnapshot<W> {
],
),
);
fail(errorBuilder.toString());
fail('Could not find $selector in widget tree');
}
}

Expand Down Expand Up @@ -602,7 +608,6 @@ void _tryMatchingLessSpecificCriteria(WidgetSnapshot snapshot) {
details: '$errorBuilder\nFound in widget Tree:\n$significantTree',
);
}
errorBuilder.writeln('\nFound in widget Tree:\n$significantTree');
fail(errorBuilder.toString());
}
}
Expand Down
8 changes: 7 additions & 1 deletion test/spot/existence_comparison_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,13 @@ void main() {
.whereText((text) => text.startsWith('a'))
.existsExactlyNTimes(3),
throwsSpotErrorContaining([
'Found 4 elements matching Text with prop "data" starts with \'a\' in widget tree, expected exactly 3',
'Found 4 elements matching Text with prop "data" starts with \'a\' in widget tree, expected exactly 3.',
'Check the timeline at the very bottom for more information.',
]),
);
expect(
timeline.events.last.details,
stringContainsInOrder([
'Text("aa"',
'Text("ab"',
'Text("ac"',
Expand Down
72 changes: 43 additions & 29 deletions test/spot/exists_once_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,58 @@ void main() {
);
expect(
() => spot<Text>().existsOnce(),
throwsSpotErrorContaining(
[
'Found 2 elements',
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("World"',
'Text("Hello"',
],
not: ['root'],
),
throwsSpotErrorContaining([
'Found 2 elements',
'expected exactly 1',
]),
);
expect(
timeline.events.last.details,
stringContainsInOrder([
'Found 2 elements',
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("Hello"',
'Text("World"',
]),
);
expect(timeline.events.last.details, isNot(contains('root')));
expect(
() => spot<Text>().amount(1).existsOnce(),
throwsSpotErrorContaining(
[
'Found 2 elements',
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("World"',
'Text("Hello"',
],
not: ['root'],
),
throwsSpotErrorContaining([
'Found 2 elements',
'expected exactly 1',
]),
);
expect(
timeline.events.last.details,
stringContainsInOrder([
'Found 2 elements',
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("Hello"',
'Text("World"',
]),
);
expect(timeline.events.last.details, isNot(contains('root')));
expect(
() => spot<Text>(parents: [spot<Wrap>()]).amount(1).existsOnce(),
throwsSpotErrorContaining(
[
'Found 2 elements',
"Wrap ᗕ Text",
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("World"',
'Text("Hello"',
],
not: ['root'],
['Found 2 elements', "Wrap ᗕ Text", 'expected exactly 1'],
),
);
expect(
timeline.events.last.details,
stringContainsInOrder([
'Found 2 elements',
"Wrap ᗕ Text",
'expected exactly 1',
'\nWrap(', // at the beginning of the line, common ancestor
'Text("Hello"',
'Text("World"',
]),
);
expect(timeline.events.last.details, isNot(contains('root')));
});
testWidgets('existsOnce() finds the correct widget differentiating by props',
(tester) async {
Expand Down

0 comments on commit d48d098

Please sign in to comment.