Make pumpWidget's arguments named (#141728)

Much nicer calling API and simplifies evolving this API in the future.

I wish we could write a dart fix for this, but that's blocked on https://github.com/dart-lang/sdk/issues/54668.
This commit is contained in:
Michael Goderbauer
2024-01-19 10:29:07 -08:00
committed by GitHub
parent 9e024fdf31
commit cc544169be
20 changed files with 80 additions and 97 deletions

View File

@@ -1106,7 +1106,7 @@ void main() {
);
},
),
const Duration(milliseconds: 40),
duration: const Duration(milliseconds: 40),
);
expect(getBackgroundColor(tester, 0), const Color(0xff3d9aff));
expect(getBackgroundColor(tester, 1), const Color(0x64007aff));
@@ -1127,7 +1127,7 @@ void main() {
);
},
),
const Duration(milliseconds: 40),
duration: const Duration(milliseconds: 40),
);
expect(getBackgroundColor(tester, 0), const Color(0xff7bbaff));
expect(getBackgroundColor(tester, 1), const Color(0x95007aff));
@@ -1148,7 +1148,7 @@ void main() {
);
},
),
const Duration(milliseconds: 40),
duration: const Duration(milliseconds: 40),
);
expect(getBackgroundColor(tester, 0), const Color(0xffb9daff));
expect(getBackgroundColor(tester, 1), const Color(0xc7007aff));
@@ -1169,7 +1169,7 @@ void main() {
);
},
),
const Duration(milliseconds: 40),
duration: const Duration(milliseconds: 40),
);
expect(getBackgroundColor(tester, 0), const Color(0xfff7faff));
expect(getBackgroundColor(tester, 1), const Color(0xf8007aff));
@@ -1190,7 +1190,7 @@ void main() {
);
},
),
const Duration(milliseconds: 40),
duration: const Duration(milliseconds: 40),
);
expect(getBackgroundColor(tester, 0), isSameColorAs(CupertinoColors.white));
expect(getBackgroundColor(tester, 1), CupertinoColors.activeBlue);

View File

@@ -631,8 +631,8 @@ void main() {
testWidgets('_RenderButtonBarRow.constraints does not work before layout', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(home: ButtonBar()),
Duration.zero,
EnginePhase.build,
duration: Duration.zero,
phase: EnginePhase.build,
);
final Finder buttonBar = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_ButtonBarRow');

View File

@@ -6570,8 +6570,7 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular
),
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
} finally {
FlutterError.onError = oldHandler;

View File

@@ -441,8 +441,7 @@ void main() {
await tester.pumpWidget(
buildFrame(const EdgeInsets.only(bottom: 400)),
null,
EnginePhase.build,
phase: EnginePhase.build,
);
expect(renderBox.debugNeedsLayout, true);

View File

@@ -306,7 +306,7 @@ void main() {
indicatorPadding: indicatorPadding + const EdgeInsets.all(7.0),
),
),
), Duration.zero, EnginePhase.build);
), duration: Duration.zero, phase: EnginePhase.build);
expect(tester.renderObject(find.byType(CustomPaint)).debugNeedsPaint, true);
});

View File

@@ -32,7 +32,7 @@ class Foo extends SingleChildRenderObjectWidget {
void main() {
testWidgets('Stack parsing in non-normalized constraints error', (WidgetTester tester) async {
await tester.pumpWidget(const Foo(child: Placeholder()), Duration.zero, EnginePhase.layout);
await tester.pumpWidget(const Foo(child: Placeholder()), duration: Duration.zero, phase: EnginePhase.layout);
final Object? exception = tester.takeException();
final String text = exception.toString();
expect(text, contains('BoxConstraints has non-normalized width constraints.'));

View File

@@ -18,8 +18,7 @@ void main() {
await tester.pumpWidget(
const Placeholder(),
// Stops right after the warm up frame.
null,
EnginePhase.build,
phase: EnginePhase.build,
);
// The warm up frame will send update for an empty semantics tree. We
// ignore this one time update.
@@ -91,8 +90,7 @@ void main() {
await tester.pumpWidget(
const Placeholder(),
// Stops right after the warm up frame.
null,
EnginePhase.build,
phase: EnginePhase.build,
);
// The warm up frame will send update for an empty semantics tree. We
// ignore this one time update.

View File

@@ -378,7 +378,7 @@ void main() {
),
),
),
duration,
duration: duration,
);
}

View File

@@ -202,7 +202,7 @@ void main() {
await tester.pumpWidget(FutureBuilder<String>(
future: completer.future,
builder: snapshotText,
), const Duration(seconds: 1));
), duration: const Duration(seconds: 1));
completer.completeError('bad');
}, (Object error, StackTrace stack) {
expectSync(error, equals('bad'));

View File

@@ -1248,7 +1248,7 @@ void main() {
),
],
),
), null, EnginePhase.build);
), phase: EnginePhase.build);
expect(tester.takeException(), isAssertionError);
});

View File

@@ -109,8 +109,8 @@ void main() {
Column(),
],
),
Duration.zero,
EnginePhase.layout,
duration: Duration.zero,
phase: EnginePhase.layout,
);
// Turn off intrinsics checking, which also fails with the same exception.
@@ -125,8 +125,8 @@ void main() {
),
],
),
Duration.zero,
EnginePhase.layout,
duration: Duration.zero,
phase: EnginePhase.layout,
);
debugCheckIntrinsicSizes = true;
final String message = tester.takeException().toString();

View File

@@ -146,9 +146,7 @@ RenderImage getRenderImage(WidgetTester tester, Key key) {
}
Future<void> pumpTreeToLayout(WidgetTester tester, Widget widget) {
const Duration pumpDuration = Duration.zero;
const EnginePhase pumpPhase = EnginePhase.layout;
return tester.pumpWidget(widget, pumpDuration, pumpPhase);
return tester.pumpWidget(widget, duration: Duration.zero, phase: EnginePhase.layout);
}
void main() {

View File

@@ -56,8 +56,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -95,8 +95,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -130,8 +130,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -165,8 +165,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -200,8 +200,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..translate(x: 50.0, y: 0.0)
@@ -231,8 +231,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -259,8 +259,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -287,8 +287,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(Container), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -314,8 +314,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -351,8 +351,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -384,8 +384,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -417,8 +417,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
@@ -477,8 +477,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -503,8 +503,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -529,8 +529,8 @@ void main() {
),
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
expect(find.byType(SizedBox), paints
..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
@@ -548,8 +548,8 @@ void main() {
alignment: Alignment.centerRight,
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
await tester.pumpWidget(
Directionality(
@@ -560,8 +560,8 @@ void main() {
matchTextDirection: true,
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
await tester.pumpWidget(
Directionality(
@@ -571,8 +571,8 @@ void main() {
alignment: Alignment.centerRight,
),
),
Duration.zero,
EnginePhase.layout, // so that we don't try to paint the fake images
duration: Duration.zero,
phase: EnginePhase.layout, // so that we don't try to paint the fake images
);
});
}

View File

@@ -97,8 +97,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
RenderImage renderImage = key.currentContext!.findRenderObject()! as RenderImage;
expect(renderImage.image, isNull);
@@ -119,8 +118,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
renderImage = key.currentContext!.findRenderObject()! as RenderImage;
@@ -139,8 +137,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
RenderImage renderImage = key.currentContext!.findRenderObject()! as RenderImage;
expect(renderImage.image, isNull);
@@ -162,8 +159,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
renderImage = key.currentContext!.findRenderObject()! as RenderImage;
@@ -179,8 +175,7 @@ void main() {
image: imageProvider1,
excludeFromSemantics: true,
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
RenderImage renderImage = key.currentContext!.findRenderObject()! as RenderImage;
expect(renderImage.image, isNull);
@@ -199,8 +194,7 @@ void main() {
image: imageProvider2,
excludeFromSemantics: true,
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
renderImage = key.currentContext!.findRenderObject()! as RenderImage;
@@ -217,8 +211,7 @@ void main() {
image: imageProvider1,
excludeFromSemantics: true,
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
RenderImage renderImage = key.currentContext!.findRenderObject()! as RenderImage;
expect(renderImage.image, isNull);
@@ -238,8 +231,7 @@ void main() {
excludeFromSemantics: true,
image: imageProvider2,
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
renderImage = key.currentContext!.findRenderObject()! as RenderImage;
@@ -927,8 +919,7 @@ void main() {
image: imageProvider1,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
RenderImage renderImage = key.currentContext!.findRenderObject()! as RenderImage;
expect(renderImage.image, isNull);
@@ -951,8 +942,7 @@ void main() {
image: imageProvider2,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
renderImage = key.currentContext!.findRenderObject()! as RenderImage;
@@ -965,10 +955,10 @@ void main() {
final Image image2 = Image(image: _TestImageProvider()..complete(image10x10.clone()), width: 20.0, excludeFromSemantics: true);
final Column column = Column(children: <Widget>[image1, image2]);
await tester.pumpWidget(column, null, EnginePhase.layout);
await tester.pumpWidget(column, phase:EnginePhase.layout);
final Column columnSwapped = Column(children: <Widget>[image2, image1]);
await tester.pumpWidget(columnSwapped, null, EnginePhase.layout);
await tester.pumpWidget(columnSwapped, phase: EnginePhase.layout);
final List<RenderImage> renderObjects = tester.renderObjectList<RenderImage>(find.byType(Image)).toList();
expect(renderObjects, hasLength(2));
@@ -1420,8 +1410,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
// only listener from resolveStreamForKey is left.
@@ -1454,8 +1443,7 @@ void main() {
excludeFromSemantics: true,
),
),
null,
EnginePhase.layout,
phase: EnginePhase.layout,
);
// only listener from resolveStreamForKey is left.

View File

@@ -117,7 +117,7 @@ void main() {
expect(find.text('5'), findsOneWidget);
await tester.pumpWidget(Container());
await tester.pumpWidget(buildFrame(textDirection: TextDirection.ltr), const Duration(seconds: 1));
await tester.pumpWidget(buildFrame(textDirection: TextDirection.ltr), duration: const Duration(seconds: 1));
await tester.drag(find.text('2'), const Offset(-280.0, 0.0), touchSlopX: 0.0);
await tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items:
@@ -436,7 +436,7 @@ void main() {
expect(find.text('5'), findsOneWidget);
await tester.pumpWidget(Container());
await tester.pumpWidget(buildFrame(reverse: true, textDirection: TextDirection.rtl), const Duration(seconds: 1));
await tester.pumpWidget(buildFrame(reverse: true, textDirection: TextDirection.rtl), duration: const Duration(seconds: 1));
await tester.drag(find.text('2'), const Offset(-280.0, 0.0), touchSlopX: 0.0);
await tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items:

View File

@@ -2664,7 +2664,7 @@ void main() {
),
);
await tester.pumpWidget(myApp, Duration.zero, EnginePhase.build);
await tester.pumpWidget(myApp, duration: Duration.zero, phase: EnginePhase.build);
expect(isScrolled, false);
expect(tester.takeException(), isNull);
});

View File

@@ -199,7 +199,7 @@ void main() {
await tester.pump(); // Start the animation.
// We will now change the tree on the same frame as the animation ends.
await tester.pumpWidget(Container(), const Duration(seconds: 2));
await tester.pumpWidget(Container(), duration: const Duration(seconds: 2));
});
testWidgets('Read operations on ScrollControllers with no positions fail', (WidgetTester tester) async {

View File

@@ -1023,7 +1023,7 @@ void main() {
await tester.pumpWidget(
buildTable(const ValueKey<int>(1)),
null, EnginePhase.build, // Children are not laid out!
phase: EnginePhase.build, // Children are not laid out!
);
await tester.pumpWidget(

View File

@@ -584,10 +584,10 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
/// this method works when the test is run with `flutter run`.
Future<void> pumpWidget(
Widget widget, [
Widget widget, {
Duration? duration,
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
]) {
}) {
return TestAsyncUtils.guard<void>(() {
binding.attachRootWidget(binding.wrapWithDefaultView(widget));
binding.scheduleFrame();

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
@@ -48,7 +49,7 @@ void main() {
_testExecutions.add(execution);
testWidgets(execution.name, experimentalLeakTesting: settings,
(WidgetTester tester) async {
await test.body(tester.pumpWidget, tester.runAsync);
await test.body((Widget widget, [Duration? duration]) => tester.pumpWidget(widget, duration: duration), tester.runAsync);
});
}
}