diff --git a/.travis.yml b/.travis.yml index 17d55f4..a9ac822 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: script: - cd packages/golden_toolkit - ../../flutter/bin/flutter analyze - - ../../flutter/bin/cache/dart-sdk/bin/dartfmt -n ./lib -l 120 --set-exit-if-changed + - ../../flutter/bin/cache/dart-sdk/bin/dartfmt -n ./lib --set-exit-if-changed - ../../flutter/bin/flutter test --coverage --coverage-path=lcov.info - cd example - ../../../flutter/bin/flutter analyze diff --git a/packages/golden_toolkit/.vscode/settings.json b/packages/golden_toolkit/.vscode/settings.json index 219f07d..c94b85d 100644 --- a/packages/golden_toolkit/.vscode/settings.json +++ b/packages/golden_toolkit/.vscode/settings.json @@ -1,4 +1,5 @@ { "editor.insertSpaces": false, - "editor.wordWrapColumn": 120 + "editor.wordWrapColumn": 80, + "dart.lineLength": 80 } \ No newline at end of file diff --git a/packages/golden_toolkit/CHANGELOG.md b/packages/golden_toolkit/CHANGELOG.md index 7aa39b9..5f6d567 100644 --- a/packages/golden_toolkit/CHANGELOG.md +++ b/packages/golden_toolkit/CHANGELOG.md @@ -1,19 +1,27 @@ # Changelog +## 0.7.0 + +Thanks to @moonytoes29 for the following enhancements: + +A new helper widget `DeviceBuilder` has been added. This works conceptually similar to `GoldenBuilder` but is used for displaying multiple device renderings of a widget in a single golden. This is an alternative to the existing `multiScreenGolden()` API which captures separate golden images for each device variation under test. + +To assist with usage of `DeviceBuilder`, there is a new helper API: `tester.pumpDeviceBuilder(builder)` which assists in easily pumping a DeviceBuilder widget in your tests. Check out the documentation for more details. + ## 0.6.0 -Added the ability to configure the default set of devices to use for ```multiScreenGolden``` assertions globally. +Added the ability to configure the default set of devices to use for `multiScreenGolden` assertions globally. For example: -```GoldenToolkitConfiguration(defaultDevices: [Device.iphone11, Device.iphone11.dark()])``` +`GoldenToolkitConfiguration(defaultDevices: [Device.iphone11, Device.iphone11.dark()])` -As part of this, the default parameter value has been removed from ```multiScreenGolden```. +As part of this, the default parameter value has been removed from `multiScreenGolden`. There was also a minor breaking change in that the const constructor of GoldenToolkitConfiguration is no longer const. ## 0.5.1 -Improved the reliability of the default behavior for ```tester.waitForAssets()``` to handle additional cases. +Improved the reliability of the default behavior for `tester.waitForAssets()` to handle additional cases. ## 0.5.0 @@ -23,7 +31,7 @@ A new mechanism has been added for ensuring that images have been decoded before This may be a breaking change for some consumers. If you run into issues, you can revert to the old behavior, by applying the following configuration: -```GoldenToolkitConfiguration(primeAssets: legacyPrimeAssets);``` +`GoldenToolkitConfiguration(primeAssets: legacyPrimeAssets);` Additionally, you can provide your own implementation that extends the new default behavior: @@ -48,7 +56,7 @@ GoldenToolkit.runWithConfiguration((){/* callback() */}, config: GoldenToolkitCo ### Added the ability to customize the generated filenames -When using ```screenMatchesGolden``` or ```multiGoldenFile```, you can now supply your own functions for controlling the naming of the files. This can be done using the configuration API mentioned above. +When using `screenMatchesGolden` or `multiGoldenFile`, you can now supply your own functions for controlling the naming of the files. This can be done using the configuration API mentioned above. ```dart GoldenToolkit.runWithConfiguration((){ /* callback() */}, config: GoldenToolkitConfiguration(fileNameFactory: (filename) => '' /*output filename*/)); @@ -56,8 +64,8 @@ GoldenToolkit.runWithConfiguration((){ /* callback() */}, config: GoldenToolkitC There are two methods that can be overridden: -* ```fileNameFactory``` is used for screenMatchesGolden -* ```deviceFileNameFactory``` is used for multiScreenGolden +- `fileNameFactory` is used for screenMatchesGolden +- `deviceFileNameFactory` is used for multiScreenGolden Future releases will likely consolidate these APIs. @@ -65,9 +73,9 @@ Thanks to @christian-muertz for this enhancement. ### Added additional utility functions for preparing for goldens -Extracted out some public extension methods that were previously private implementation details of ```multiScreenGolden``` & ```screenMatchesGolden``` +Extracted out some public extension methods that were previously private implementation details of `multiScreenGolden` & `screenMatchesGolden` -Added the following extensions. These can be used with any vanilla golden assertions and do not require ```multiScreenGolden```, ```screenMatchesGolden```, or ```GoldenBuilder```. +Added the following extensions. These can be used with any vanilla golden assertions and do not require `multiScreenGolden`, `screenMatchesGolden`, or `GoldenBuilder`. ```dart // configures the simulated device to mirror the supplied device configuration (dimensions, pixel density, safe area, etc) @@ -95,7 +103,7 @@ A few API / parameters were marked as deprecated and will be removed in future r ### Configuration API -Added a configuration API so that you can control the behavior of skipping golden assertions in a single location, rather than at each call to ```screenMatchesGolden``` or ```multiScreenGolden```. +Added a configuration API so that you can control the behavior of skipping golden assertions in a single location, rather than at each call to `screenMatchesGolden` or `multiScreenGolden`. You can now call: @@ -109,7 +117,7 @@ GoldenToolkit.configure(GoldenToolkitConfiguration(skipGoldenAssertion: () => /* ### Auto-Sized Goldens -A new optional parameter ```autoHeight``` has been added to ```screenMatchesGolden``` and ```multiScreenGolden```. If set to true, the height of the golden will adapt to fit the widget under test. Thanks to @christian-muertz! +A new optional parameter `autoHeight` has been added to `screenMatchesGolden` and `multiScreenGolden`. If set to true, the height of the golden will adapt to fit the widget under test. Thanks to @christian-muertz! ## 0.3.2 diff --git a/packages/golden_toolkit/README.md b/packages/golden_toolkit/README.md index dd4240c..33faa47 100644 --- a/packages/golden_toolkit/README.md +++ b/packages/golden_toolkit/README.md @@ -74,7 +74,6 @@ The output of this test will be this golden file: `weather_accessibility.png`: See tests for usage examples: [golden_builder_test.dart](example/test/golden_builder_test.dart) - ### DeviceBuilder DeviceBuilder class is like the GoldenBuilder except that it constrains scenario widget sizes to Device configurations. This removes the need @@ -83,9 +82,6 @@ to specify a column or grid based layout. It will generate a widget that lays out its scenarios vertically and the Device configurations of those scenarios horizontally. All in one single golden png file. -In the case of a single scenario the helper method of (#multiDeviceGolden) can simplify DeviceBuilder usage. For multiple scenarios, DeviceBuilder -can help - ```dart testGoldens('DeviceBuilder - multiple scenarios - with onCreate', (tester) async { @@ -142,7 +138,6 @@ This will generate the following golden: ![example widget captured](example/test/goldens/flutter_demo_page_multiple_scenarios.png) - ### multiScreenGolden The multiScreenGolden assertion is used to capture multiple goldens of a single widget using different simulated device sizes & characteristics. @@ -227,10 +222,7 @@ If you use VSCode, we highly recommend adding this configuration to your `.vscod "request": "launch", "type": "dart", "codeLens": { - "for": [ - "run-test", - "run-test-file" - ] + "for": ["run-test", "run-test-file"] }, "args": ["--update-goldens"] } @@ -358,7 +350,7 @@ See more usage examples here: [golden_builder_test.dart](test/golden_builder_tes There are global settings that can be configured by calling the following API: -```GoldenToolkit.runWithConfiguration()``` +`GoldenToolkit.runWithConfiguration()` Currently, the primary option is to allow consumers to holistically skip golden assertions. For example, perhaps you only want to perform golden assertions on certain platforms. diff --git a/packages/golden_toolkit/example/lib/src/weather_widgets.dart b/packages/golden_toolkit/example/lib/src/weather_widgets.dart index 44bbf6a..f361e77 100644 --- a/packages/golden_toolkit/example/lib/src/weather_widgets.dart +++ b/packages/golden_toolkit/example/lib/src/weather_widgets.dart @@ -56,7 +56,8 @@ class WeatherForecast extends StatelessWidget { shape: const CircleBorder(), ), textTheme: theme.textTheme.copyWith( - bodyText2: theme.textTheme.bodyText2.copyWith(fontSize: 24), + bodyText2: + theme.textTheme.bodyText2.copyWith(fontSize: 24), ), ), child: WeatherCard.forecast(today), @@ -70,8 +71,10 @@ class WeatherForecast extends StatelessWidget { Column( mainAxisSize: MainAxisSize.min, children: [ - Text('This Week\'s Forecast', style: Theme.of(context).textTheme.headline6), - if (MediaQuery.of(context).size.width > 400 && MediaQuery.of(context).size.height > 600) + Text('This Week\'s Forecast', + style: Theme.of(context).textTheme.headline6), + if (MediaQuery.of(context).size.width > 400 && + MediaQuery.of(context).size.height > 600) WeeklyForecastExpanded(forecasts: _list) else WeeklyForecastCompact(forecasts: _list), @@ -107,7 +110,9 @@ class WeeklyForecastExpanded extends StatelessWidget { const SizedBox(width: 8), Flexible( flex: 5, - child: Align(alignment: Alignment.centerLeft, child: Text(f.description)), + child: Align( + alignment: Alignment.centerLeft, + child: Text(f.description)), ), ], )) @@ -293,7 +298,8 @@ enum Weather { cloudy, } -final RoundedRectangleBorder _cardShape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)); +final RoundedRectangleBorder _cardShape = + RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)); class Forecast { const Forecast({this.day, this.temp, this.weather, this.description}); diff --git a/packages/golden_toolkit/example/pubspec.lock b/packages/golden_toolkit/example/pubspec.lock index c124a8a..2468b44 100644 --- a/packages/golden_toolkit/example/pubspec.lock +++ b/packages/golden_toolkit/example/pubspec.lock @@ -66,7 +66,7 @@ packages: path: ".." relative: true source: path - version: "0.6.0" + version: "0.7.0" matcher: dependency: transitive description: diff --git a/packages/golden_toolkit/example/test/example_test.dart b/packages/golden_toolkit/example/test/example_test.dart index 6a52e28..e725616 100644 --- a/packages/golden_toolkit/example/test/example_test.dart +++ b/packages/golden_toolkit/example/test/example_test.dart @@ -30,9 +30,12 @@ void main() { bgColor: Colors.white, widthToHeightRatio: 1, ) - ..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) - ..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) - ..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain)) + ..addScenario( + 'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) + ..addScenario( + 'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) + ..addScenario( + 'Raining', const WeatherCard(temp: 37, weather: Weather.rain)) ..addScenario( 'Cold', const WeatherCard(temp: 25, weather: Weather.cold), @@ -46,15 +49,20 @@ void main() { }); /// lays out the results in a column - testGoldens('COLUMN: Different weather types with extra frame', (tester) async { + testGoldens('COLUMN: Different weather types with extra frame', + (tester) async { final gb = GoldenBuilder.column( bgColor: Colors.white, wrap: _simpleFrame, ) - ..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) - ..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) - ..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain)) - ..addScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold)); + ..addScenario( + 'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) + ..addScenario( + 'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) + ..addScenario( + 'Raining', const WeatherCard(temp: 37, weather: Weather.rain)) + ..addScenario( + 'Cold', const WeatherCard(temp: 25, weather: Weather.cold)); await tester.pumpWidgetBuilder( gb.build(), @@ -65,13 +73,19 @@ void main() { /// Demonstrates how golden builder can be combined with multiScreenGolden to /// test with multiple dimensions of parameters - testGoldens('Card should look right on different devices / screen sizes', (tester) async { + testGoldens('Card should look right on different devices / screen sizes', + (tester) async { final gb = GoldenBuilder.column(bgColor: Colors.white) - ..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) - ..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) - ..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain)) - ..addScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold)) - ..addTextScaleScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold)); + ..addScenario( + 'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny)) + ..addScenario( + 'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy)) + ..addScenario( + 'Raining', const WeatherCard(temp: 37, weather: Weather.rain)) + ..addScenario( + 'Cold', const WeatherCard(temp: 25, weather: Weather.cold)) + ..addTextScaleScenario( + 'Cold', const WeatherCard(temp: 25, weather: Weather.cold)); await tester.pumpWidgetBuilder( gb.build(), @@ -88,13 +102,17 @@ void main() { group('GoldenBuilder examples of accessibility testing', () { // With those test we want to make sure our widgets look right when user changes system font size - testGoldens('Card should look right when user bumps system font size', (tester) async { + testGoldens('Card should look right when user bumps system font size', + (tester) async { const widget = WeatherCard(temp: 56, weather: Weather.cloudy); - final gb = GoldenBuilder.column(bgColor: Colors.white, wrap: _simpleFrame) - ..addScenario('Regular font size', widget) - ..addTextScaleScenario('Large font size', widget, textScaleFactor: 2.0) - ..addTextScaleScenario('Largest font size', widget, textScaleFactor: 3.2); + final gb = + GoldenBuilder.column(bgColor: Colors.white, wrap: _simpleFrame) + ..addScenario('Regular font size', widget) + ..addTextScaleScenario('Large font size', widget, + textScaleFactor: 2.0) + ..addTextScaleScenario('Largest font size', widget, + textScaleFactor: 3.2); await tester.pumpWidgetBuilder( gb.build(), @@ -119,8 +137,11 @@ void main() { ///then you may run into issues with some images not displaying properly. /// ///This is an example of the the "issue" - testGoldens('Some images missing in multiScreenGoldens that require additional setup', (tester) async { - await tester.pumpWidgetBuilder(_forecastWithDifferentImagesForLargeAndSmallScreen()); + testGoldens( + 'Some images missing in multiScreenGoldens that require additional setup', + (tester) async { + await tester.pumpWidgetBuilder( + _forecastWithDifferentImagesForLargeAndSmallScreen()); await multiScreenGolden( tester, 'example_of_images_not_properly_loading', @@ -128,8 +149,11 @@ void main() { }); ///here is an example of how to workaround it. - testGoldens('Should render images in multiScreenGoldens that require additional setup', (tester) async { - await tester.pumpWidgetBuilder(_forecastWithDifferentImagesForLargeAndSmallScreen()); + testGoldens( + 'Should render images in multiScreenGoldens that require additional setup', + (tester) async { + await tester.pumpWidgetBuilder( + _forecastWithDifferentImagesForLargeAndSmallScreen()); await multiScreenGolden( tester, 'weather_image_async_load_correct_duration', @@ -176,7 +200,9 @@ Widget _forecastWithDifferentImagesForLargeAndSmallScreen() { } class FutureWidgetTester extends StatefulWidget { - const FutureWidgetTester({Key key, this.child, this.duration = const Duration(milliseconds: 100)}) : super(key: key); + const FutureWidgetTester( + {Key key, this.child, this.duration = const Duration(milliseconds: 100)}) + : super(key: key); final Widget child; final Duration duration; @override @@ -205,7 +231,8 @@ class _FutureWidgetTesterState extends State { } class InvalidateWidgetTreeWhenSizeChanges extends StatelessWidget { - const InvalidateWidgetTreeWhenSizeChanges({Key key, this.child}) : super(key: key); + const InvalidateWidgetTreeWhenSizeChanges({Key key, this.child}) + : super(key: key); final Widget child; @override diff --git a/packages/golden_toolkit/example/test/flutter_demo_page_test.dart b/packages/golden_toolkit/example/test/flutter_demo_page_test.dart index 74f2baf..be70a9c 100644 --- a/packages/golden_toolkit/example/test/flutter_demo_page_test.dart +++ b/packages/golden_toolkit/example/test/flutter_demo_page_test.dart @@ -18,7 +18,8 @@ void main() { await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario'); }); - testGoldens('DeviceBuilder - one scenario - override devices', (tester) async { + testGoldens('DeviceBuilder - one scenario - override devices', + (tester) async { final builder = DeviceBuilder() ..overrideDevicesForAllScenarios(devices: [ Device.phone, @@ -33,10 +34,12 @@ void main() { await tester.pumpDeviceBuilder(builder); - await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario_more_devices'); + await screenMatchesGolden( + tester, 'flutter_demo_page_single_scenario_more_devices'); }); - testGoldens('DeviceBuilder - multiple scenarios - with onCreate', (tester) async { + testGoldens('DeviceBuilder - multiple scenarios - with onCreate', + (tester) async { final builder = DeviceBuilder() ..overrideDevicesForAllScenarios(devices: [ Device.phone, diff --git a/packages/golden_toolkit/lib/src/configuration.dart b/packages/golden_toolkit/lib/src/configuration.dart index 388028e..88c6e47 100644 --- a/packages/golden_toolkit/lib/src/configuration.dart +++ b/packages/golden_toolkit/lib/src/configuration.dart @@ -21,7 +21,8 @@ import 'device.dart'; class GoldenToolkit { GoldenToolkit._(); - static GoldenToolkitConfiguration _configuration = GoldenToolkitConfiguration(); + static GoldenToolkitConfiguration _configuration = + GoldenToolkitConfiguration(); /// Applies a GoldenToolkitConfiguration to a block of code to effectively provide a scoped /// singleton. The configuration will apply to just the injected body function. @@ -121,7 +122,8 @@ class GoldenToolkitConfiguration { return GoldenToolkitConfiguration( skipGoldenAssertion: skipGoldenAssertion ?? this.skipGoldenAssertion, fileNameFactory: fileNameFactory ?? this.fileNameFactory, - deviceFileNameFactory: deviceFileNameFactory ?? this.deviceFileNameFactory, + deviceFileNameFactory: + deviceFileNameFactory ?? this.deviceFileNameFactory, primeAssets: primeAssets ?? this.primeAssets, defaultDevices: defaultDevices ?? this.defaultDevices, ); diff --git a/packages/golden_toolkit/lib/src/device.dart b/packages/golden_toolkit/lib/src/device.dart index 39d84f8..cf0397e 100644 --- a/packages/golden_toolkit/lib/src/device.dart +++ b/packages/golden_toolkit/lib/src/device.dart @@ -35,10 +35,12 @@ class Device { ); /// [tabletLandscape] example of tablet that in landscape mode - static const Device tabletLandscape = Device(name: 'tablet_landscape', size: Size(1366, 1024)); + static const Device tabletLandscape = + Device(name: 'tablet_landscape', size: Size(1366, 1024)); /// [tabletPortrait] example of tablet that in portrait mode - static const Device tabletPortrait = Device(name: 'tablet_portrait', size: Size(1024, 1366)); + static const Device tabletPortrait = + Device(name: 'tablet_portrait', size: Size(1024, 1366)); /// [name] specify device name. Ex: Phone, Tablet, Watch diff --git a/packages/golden_toolkit/lib/src/device_builder.dart b/packages/golden_toolkit/lib/src/device_builder.dart index 3deeb7b..7d0e99f 100644 --- a/packages/golden_toolkit/lib/src/device_builder.dart +++ b/packages/golden_toolkit/lib/src/device_builder.dart @@ -58,7 +58,8 @@ class DeviceBuilder { /// list of created DeviceScenarios for each device type final List<_DeviceScenario> scenarios = []; - List _devicesForScenarios = GoldenToolkit.configuration.defaultDevices ?? [Device.phone]; + List _devicesForScenarios = + GoldenToolkit.configuration.defaultDevices ?? [Device.phone]; int get _numberOfDevicesPerScenario => _devicesForScenarios?.length ?? 1; /// Overrides the list of devices that are rendered for each scenario @@ -102,9 +103,13 @@ class DeviceBuilder { /// outputs calculated required size to render all Scenarios and their corresponding Devices Size get requiredWidgetSize { - var width = scenarios.map((scenario) => scenario.widget.scenarioSize.width).reduce((pw, cw) => pw + cw); + var width = scenarios + .map((scenario) => scenario.widget.scenarioSize.width) + .reduce((pw, cw) => pw + cw); - var height = scenarios.map((scenario) => scenario.widget.scenarioSize.height).reduce(max); + var height = scenarios + .map((scenario) => scenario.widget.scenarioSize.height) + .reduce(max); if (scenarios.length > _numberOfDevicesPerScenario) { final scenariosPerDevice = scenarios.length / _numberOfDevicesPerScenario; @@ -120,15 +125,18 @@ class DeviceBuilder { final requiredSize = requiredWidgetSize; final numberOfDevices = _numberOfDevicesPerScenario; - assert(scenarios.length % numberOfDevices == 0, 'scenarios should always be divisible by number of devices'); + assert(scenarios.length % numberOfDevices == 0, + 'scenarios should always be divisible by number of devices'); final numberOfRequiredRows = scenarios.length ~/ numberOfDevices; final scenarioRows = []; for (var i = 0; i < numberOfRequiredRows; i++) { final startRange = i * numberOfDevices; scenarioRows.add(Row( - children: - scenarios.getRange(startRange, startRange + numberOfDevices).map((scenario) => scenario.widget).toList(), + children: scenarios + .getRange(startRange, startRange + numberOfDevices) + .map((scenario) => scenario.widget) + .toList(), )); } @@ -165,7 +173,8 @@ class _DeviceScenarioWidget extends StatelessWidget { static const double _horizontalScenarioPadding = 8.0; static const double _borderWidth = 1.0; - Size get scenarioSize => Size(device.size.width + (_horizontalScenarioPadding * 2) + (_borderWidth * 2), + Size get scenarioSize => Size( + device.size.width + (_horizontalScenarioPadding * 2) + (_borderWidth * 2), device.size.height + 24 + (_borderWidth * 2)); Widget get _sizedWidget => Container( @@ -179,7 +188,8 @@ class _DeviceScenarioWidget extends StatelessWidget { final scenarioWidget = wrap != null ? wrap(_sizedWidget) : _sizedWidget; return ClipRect( child: Padding( - padding: const EdgeInsets.symmetric(horizontal: _horizontalScenarioPadding), + padding: + const EdgeInsets.symmetric(horizontal: _horizontalScenarioPadding), child: Container( decoration: BoxDecoration( border: Border.all( diff --git a/packages/golden_toolkit/lib/src/golden_builder.dart b/packages/golden_toolkit/lib/src/golden_builder.dart index 72fba9d..8ed9640 100644 --- a/packages/golden_toolkit/lib/src/golden_builder.dart +++ b/packages/golden_toolkit/lib/src/golden_builder.dart @@ -123,7 +123,8 @@ class GoldenBuilder { ); } - Column _column() => Column(mainAxisSize: MainAxisSize.min, children: scenarios); + Column _column() => + Column(mainAxisSize: MainAxisSize.min, children: scenarios); } class _Scenario extends StatelessWidget { diff --git a/packages/golden_toolkit/lib/src/multi_screen_golden.dart b/packages/golden_toolkit/lib/src/multi_screen_golden.dart index 3929d4f..dbd3e3a 100644 --- a/packages/golden_toolkit/lib/src/multi_screen_golden.dart +++ b/packages/golden_toolkit/lib/src/multi_screen_golden.dart @@ -66,7 +66,8 @@ Future multiScreenGolden( device, body: () async { if (overrideGoldenHeight != null) { - await tester.binding.setSurfaceSize(Size(device.size.width, overrideGoldenHeight)); + await tester.binding + .setSurfaceSize(Size(device.size.width, overrideGoldenHeight)); } await deviceSetupPump(device, tester); await compareWithGolden( diff --git a/packages/golden_toolkit/lib/src/testing_tools.dart b/packages/golden_toolkit/lib/src/testing_tools.dart index 80f87cd..9292bf7 100644 --- a/packages/golden_toolkit/lib/src/testing_tools.dart +++ b/packages/golden_toolkit/lib/src/testing_tools.dart @@ -195,7 +195,8 @@ Future screenMatchesGolden( customPump: customPump, skip: skip, device: null, - fileNameFactory: (String name, Device device) => GoldenToolkit.configuration.fileNameFactory(name), + fileNameFactory: (String name, Device device) => + GoldenToolkit.configuration.fileNameFactory(name), ); } @@ -218,7 +219,8 @@ Future compareWithGolden( fail( 'Golden tests MUST be run within a testGoldens method, not just a testWidgets method. This is so we can be confident that running "flutter test --name=GOLDEN" will run all golden tests.'); } - final shouldSkipGoldenGeneration = skip ?? GoldenToolkit.configuration.skipGoldenAssertion(); + final shouldSkipGoldenGeneration = + skip ?? GoldenToolkit.configuration.skipGoldenAssertion(); final pumpAfterPrime = customPump ?? _onlyPumpAndSettle; /* if no finder is specified, use the first widget. Note, there is no guarantee this evaluates top-down, but in theory if all widgets are in the same @@ -236,7 +238,10 @@ Future compareWithGolden( if (autoHeight == true) { // Find the first scrollable element which can be scrolled vertical. // ListView, SingleChildScrollView, CustomScrollView? are implemented using a Scrollable widget. - final scrollable = find.byType(Scrollable).evaluate().map((Element element) { + final scrollable = find + .byType(Scrollable) + .evaluate() + .map((Element element) { if (element is StatefulElement && element.state is ScrollableState) { return element.state; } @@ -305,7 +310,8 @@ Future legacyPrimeAssets(WidgetTester tester) async { /// * [GoldenToolkitConfiguration.primeAssets] to configure a global asset prime function. Future defaultPrimeAssets(WidgetTester tester) async { final imageElements = find.byType(Image, skipOffstage: false).evaluate(); - final containerElements = find.byType(DecoratedBox, skipOffstage: false).evaluate(); + final containerElements = + find.byType(DecoratedBox, skipOffstage: false).evaluate(); await tester.runAsync(() async { for (final imageElement in imageElements) { final widget = imageElement.widget; @@ -325,4 +331,5 @@ Future defaultPrimeAssets(WidgetTester tester) async { }); } -Future _onlyPumpAndSettle(WidgetTester tester) async => tester.pumpAndSettle(); +Future _onlyPumpAndSettle(WidgetTester tester) async => + tester.pumpAndSettle(); diff --git a/packages/golden_toolkit/pubspec.yaml b/packages/golden_toolkit/pubspec.yaml index 33da5f6..71fe463 100644 --- a/packages/golden_toolkit/pubspec.yaml +++ b/packages/golden_toolkit/pubspec.yaml @@ -1,6 +1,6 @@ name: golden_toolkit description: Common patterns for screenshot-based widget testing using Goldens. -version: 0.6.0 +version: 0.7.0 homepage: https://github.com/eBay/flutter_glove_box/ repository: https://github.com/eBay/flutter_glove_box/tree/master/packages/golden_toolkit issue_tracker: https://github.com/eBay/flutter_glove_box/issues diff --git a/packages/golden_toolkit/test/configuration/static_configuration_test.dart b/packages/golden_toolkit/test/configuration/static_configuration_test.dart index a49c221..6816b79 100644 --- a/packages/golden_toolkit/test/configuration/static_configuration_test.dart +++ b/packages/golden_toolkit/test/configuration/static_configuration_test.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; void main() { - testGoldens('legacy static global configuration should still work', (tester) async { + testGoldens('legacy static global configuration should still work', + (tester) async { //ignore:deprecated_member_use_from_same_package - GoldenToolkit.configure(GoldenToolkitConfiguration(skipGoldenAssertion: () => true)); + GoldenToolkit.configure( + GoldenToolkitConfiguration(skipGoldenAssertion: () => true)); await tester.pumpWidget(Container()); await screenMatchesGolden(tester, 'this_is_expected_to_skip'); }); diff --git a/packages/golden_toolkit/test/configuration_test.dart b/packages/golden_toolkit/test/configuration_test.dart index 4b33941..99a5eba 100644 --- a/packages/golden_toolkit/test/configuration_test.dart +++ b/packages/golden_toolkit/test/configuration_test.dart @@ -13,7 +13,9 @@ import 'package:golden_toolkit/golden_toolkit.dart'; void main() { group('GoldenToolkitConfiguration Tests', () { - testGoldens('screenMatchesGolden method should defer skip to global configuration', (tester) async { + testGoldens( + 'screenMatchesGolden method should defer skip to global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidget(Container()); @@ -23,18 +25,23 @@ void main() { ); }); - testGoldens('screenMatchesGolden method level skip should trump global configuration', (tester) async { + testGoldens( + 'screenMatchesGolden method level skip should trump global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(Container()); - //ignore: deprecated_member_use_from_same_package - await screenMatchesGolden(tester, 'this_is_expected_to_skip', skip: true); + await screenMatchesGolden(tester, 'this_is_expected_to_skip', + //ignore: deprecated_member_use_from_same_package + skip: true); }, config: GoldenToolkitConfiguration(skipGoldenAssertion: () => false), ); }); - testGoldens('MultiScreenGolden method should defer skip to global configuration', (tester) async { + testGoldens( + 'MultiScreenGolden method should defer skip to global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(Container()); @@ -44,58 +51,75 @@ void main() { ); }); - testGoldens('MultiScreenGolden method level skip should trump global configuration', (tester) async { + testGoldens( + 'MultiScreenGolden method level skip should trump global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(Container()); - //ignore: deprecated_member_use_from_same_package - await multiScreenGolden(tester, 'this_is_expected_to_skip', skip: true); + await multiScreenGolden(tester, 'this_is_expected_to_skip', + //ignore: deprecated_member_use_from_same_package + skip: true); }, config: GoldenToolkitConfiguration(skipGoldenAssertion: () => false), ); }); - testGoldens('screenMatchesGolden method should defer fileNameFactory to global configuration', (tester) async { + testGoldens( + 'screenMatchesGolden method should defer fileNameFactory to global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(Container()); await screenMatchesGolden(tester, 'global_file_name_factory'); }, - config: GoldenToolkit.configuration.copyWith(fileNameFactory: (name) => 'goldens/custom/custom_$name.png'), + config: GoldenToolkit.configuration.copyWith( + fileNameFactory: (name) => 'goldens/custom/custom_$name.png'), ); }); - testGoldens('multiScreenGolden method should defer fileNameFactory to global configuration', (tester) async { + testGoldens( + 'multiScreenGolden method should defer fileNameFactory to global configuration', + (tester) async { return GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(Container()); await multiScreenGolden(tester, 'global_device_file_name_factory'); }, - config: GoldenToolkit.configuration - .copyWith(deviceFileNameFactory: (name, device) => 'goldens/custom/custom_${name}_${device.name}.png'), + config: GoldenToolkit.configuration.copyWith( + deviceFileNameFactory: (name, device) => + 'goldens/custom/custom_${name}_${device.name}.png'), ); }); - testGoldens('screenMatchesGolden method uses primeAssets from global configuration', (tester) async { + testGoldens( + 'screenMatchesGolden method uses primeAssets from global configuration', + (tester) async { var globalPrimeCalledCount = 0; return GoldenToolkit.runWithConfiguration( () async { - await tester.pumpWidgetBuilder(Image.asset('packages/sample_dependency/images/image.png')); - await screenMatchesGolden(tester, 'screen_matches_golden_defers_primeAssets'); + await tester.pumpWidgetBuilder( + Image.asset('packages/sample_dependency/images/image.png')); + await screenMatchesGolden( + tester, 'screen_matches_golden_defers_primeAssets'); expect(globalPrimeCalledCount, 1); }, - config: GoldenToolkitConfiguration(primeAssets: (WidgetTester tester) async { + config: GoldenToolkitConfiguration( + primeAssets: (WidgetTester tester) async { globalPrimeCalledCount += 1; await legacyPrimeAssets(tester); }), ); }); - testGoldens('multiScreenGolden method uses primeAssets from global configuration', (tester) async { + testGoldens( + 'multiScreenGolden method uses primeAssets from global configuration', + (tester) async { var globalPrimeCalledCount = 0; return GoldenToolkit.runWithConfiguration( () async { - await tester.pumpWidgetBuilder(Image.asset('packages/sample_dependency/images/image.png')); + await tester.pumpWidgetBuilder( + Image.asset('packages/sample_dependency/images/image.png')); await multiScreenGolden( tester, 'multi_screen_golden_defers_primeAssets', @@ -103,7 +127,8 @@ void main() { ); expect(globalPrimeCalledCount, 1); }, - config: GoldenToolkitConfiguration(primeAssets: (WidgetTester tester) async { + config: GoldenToolkitConfiguration( + primeAssets: (WidgetTester tester) async { globalPrimeCalledCount += 1; await legacyPrimeAssets(tester); }), @@ -151,12 +176,15 @@ void main() { test('Default Configuration', () { final config = GoldenToolkitConfiguration(); expect(config.skipGoldenAssertion(), isFalse); - expect(config.fileNameFactory('test_name'), equals('goldens/test_name.png')); expect( - config.deviceFileNameFactory('test_name', const Device(name: 'my_device', size: Size(500, 500))), + config.fileNameFactory('test_name'), equals('goldens/test_name.png')); + expect( + config.deviceFileNameFactory( + 'test_name', const Device(name: 'my_device', size: Size(500, 500))), equals('goldens/test_name.my_device.png'), ); - expect(config.defaultDevices, equals([Device.phone, Device.tabletLandscape])); + expect(config.defaultDevices, + equals([Device.phone, Device.tabletLandscape])); }); group('Equality/Hashcode/CopyWith', () { @@ -181,25 +209,50 @@ void main() { group('should not be equal when params differ', () { test('skipGoldenAssertion', () { - expect(config, isNot(equals(config.copyWith(skipGoldenAssertion: () => false)))); - expect(config.hashCode, isNot(equals(config.copyWith(skipGoldenAssertion: () => false).hashCode))); + expect(config, + isNot(equals(config.copyWith(skipGoldenAssertion: () => false)))); + expect( + config.hashCode, + isNot(equals( + config.copyWith(skipGoldenAssertion: () => false).hashCode))); }); test('fileNameFactory', () { - expect(config, isNot(equals(config.copyWith(fileNameFactory: (file) => '')))); - expect(config.hashCode, isNot(equals(config.copyWith(fileNameFactory: (file) => '').hashCode))); + expect(config, + isNot(equals(config.copyWith(fileNameFactory: (file) => '')))); + expect( + config.hashCode, + isNot(equals( + config.copyWith(fileNameFactory: (file) => '').hashCode))); }); test('deviceFileNameFactory', () { - expect(config, isNot(equals(config.copyWith(deviceFileNameFactory: (file, dev) => '')))); - expect(config.hashCode, isNot(equals(config.copyWith(deviceFileNameFactory: (file, dev) => '').hashCode))); + expect( + config, + isNot(equals( + config.copyWith(deviceFileNameFactory: (file, dev) => '')))); + expect( + config.hashCode, + isNot(equals(config + .copyWith(deviceFileNameFactory: (file, dev) => '') + .hashCode))); }); test('primeImages', () { - expect(config, isNot(equals(config.copyWith(primeAssets: (_) async {})))); - expect(config.hashCode, isNot(equals(config.copyWith(primeAssets: (_) async {}).hashCode))); + expect(config, + isNot(equals(config.copyWith(primeAssets: (_) async {})))); + expect( + config.hashCode, + isNot( + equals(config.copyWith(primeAssets: (_) async {}).hashCode))); }); test('defaultDevices', () { - expect(config, isNot(equals(config.copyWith(defaultDevices: [Device.tabletPortrait])))); - expect(config.hashCode, isNot(equals(config.copyWith(defaultDevices: [Device.tabletPortrait]).hashCode))); + expect( + config, + isNot(equals( + config.copyWith(defaultDevices: [Device.tabletPortrait])))); + expect( + config.hashCode, + isNot(equals(config.copyWith( + defaultDevices: [Device.tabletPortrait]).hashCode))); }); }); }); diff --git a/packages/golden_toolkit/test/device_builder_test.dart b/packages/golden_toolkit/test/device_builder_test.dart index fe6ff11..43cca5f 100644 --- a/packages/golden_toolkit/test/device_builder_test.dart +++ b/packages/golden_toolkit/test/device_builder_test.dart @@ -87,7 +87,8 @@ void main() { final scenario = sut.scenarios.first; expect(scenario.widget.name, equals('scenarioName - $deviceName')); - expect(scenario.widget.key, equals(const Key('scenarioName - $deviceName'))); + expect( + scenario.widget.key, equals(const Key('scenarioName - $deviceName'))); expect(scenario.key, equals(const Key('scenarioName - $deviceName'))); }); @@ -134,7 +135,9 @@ void main() { expect(requiredSize, const Size(28, 36)); }); - test('requiredWidgetSize - scenarios <= devicesPerScenarios - sized for maxHeight', () { + test( + 'requiredWidgetSize - scenarios <= devicesPerScenarios - sized for maxHeight', + () { // given final sut = DeviceBuilder(); @@ -159,7 +162,9 @@ void main() { expect(requiredSize, const Size(76, 56)); }); - test('requiredWidgetSize - scenarios >= devicesPerScenarios - sized for maxHeight', () { + test( + 'requiredWidgetSize - scenarios >= devicesPerScenarios - sized for maxHeight', + () { // given final sut = DeviceBuilder(); @@ -212,7 +217,8 @@ void main() { ), ); - await tester.pumpWidgetBuilder(widget, surfaceSize: sut.requiredWidgetSize); + await tester.pumpWidgetBuilder(widget, + surfaceSize: sut.requiredWidgetSize); // then expect(find.byType(Align), findsOneWidget); diff --git a/packages/golden_toolkit/test/device_test.dart b/packages/golden_toolkit/test/device_test.dart index 7fb1830..747843f 100644 --- a/packages/golden_toolkit/test/device_test.dart +++ b/packages/golden_toolkit/test/device_test.dart @@ -61,8 +61,10 @@ void main() { safeArea: EdgeInsets.all(1), textScale: 1.5, ); - expect(device.toString(), - equals('Device: foo, 100.0x200.0 @ 1.5, text: 1.5, Brightness.dark, safe: EdgeInsets.all(1.0)')); + expect( + device.toString(), + equals( + 'Device: foo, 100.0x200.0 @ 1.5, text: 1.5, Brightness.dark, safe: EdgeInsets.all(1.0)')); }); }); } diff --git a/packages/golden_toolkit/test/font_loading_test.dart b/packages/golden_toolkit/test/font_loading_test.dart index 1a6799e..53df17e 100644 --- a/packages/golden_toolkit/test/font_loading_test.dart +++ b/packages/golden_toolkit/test/font_loading_test.dart @@ -16,22 +16,32 @@ Future main() async { group('Font loading integration test', () { testGoldens('Roboto fonts should work', (tester) async { final golden = GoldenBuilder.column() - ..addScenario('Material Fonts should work', const Text('This is material text in "Roboto"')) - ..addScenario('Material Icons should work', const Icon(Icons.phone_in_talk)) - ..addScenario('Fonts from packages should work', - const Text('This is a custom font', style: TextStyle(fontFamily: 'OpenSans', package: 'sample_dependency'))) + ..addScenario('Material Fonts should work', + const Text('This is material text in "Roboto"')) + ..addScenario( + 'Material Icons should work', const Icon(Icons.phone_in_talk)) + ..addScenario( + 'Fonts from packages should work', + const Text('This is a custom font', + style: TextStyle( + fontFamily: 'OpenSans', package: 'sample_dependency'))) ..addScenario( 'Different Font weights are not well supported (w900)', const Text('This should be weight 900', - style: TextStyle(fontFamily: 'Roboto', fontWeight: FontWeight.w900))) + style: TextStyle( + fontFamily: 'Roboto', fontWeight: FontWeight.w900))) ..addScenario( 'Different Font weights are not well supported (w100)', const Text('This should be weight 100)', - style: TextStyle(fontFamily: 'Roboto', fontWeight: FontWeight.w100))) - ..addScenario('Italics are supported', - const Text('This should be italic', style: TextStyle(fontFamily: 'Roboto', fontStyle: FontStyle.italic))) + style: TextStyle( + fontFamily: 'Roboto', fontWeight: FontWeight.w100))) ..addScenario( - 'Unknown fonts render in Ahem (Foo.ttf)', const Text('unknown font', style: TextStyle(fontFamily: 'foo'))); + 'Italics are supported', + const Text('This should be italic', + style: TextStyle( + fontFamily: 'Roboto', fontStyle: FontStyle.italic))) + ..addScenario('Unknown fonts render in Ahem (Foo.ttf)', + const Text('unknown font', style: TextStyle(fontFamily: 'foo'))); await tester.pumpWidgetBuilder(golden.build()); await screenMatchesGolden(tester, 'material_fonts'); }); @@ -44,15 +54,18 @@ Future main() async { equals('Roboto'), ); expect( - derivedFontFamily(_font('packages/foo/Roboto', ['packages/foo/fonts/roboto.ttf'])), + derivedFontFamily( + _font('packages/foo/Roboto', ['packages/foo/fonts/roboto.ttf'])), equals('Roboto'), ); expect( - derivedFontFamily(_font('.SF UI Display', ['packages/foo/fonts/sf.ttf'])), + derivedFontFamily( + _font('.SF UI Display', ['packages/foo/fonts/sf.ttf'])), equals('.SF UI Display'), ); expect( - derivedFontFamily(_font('packages/foo/.SF UI Display', ['packages/foo/fonts/sf.ttf'])), + derivedFontFamily(_font( + 'packages/foo/.SF UI Display', ['packages/foo/fonts/sf.ttf'])), equals('.SF UI Display'), ); expect( @@ -60,22 +73,26 @@ Future main() async { equals('.SF UI Text'), ); expect( - derivedFontFamily(_font('packages/foo/.SF UI Text', ['packages/foo/fonts/sf.ttf'])), + derivedFontFamily( + _font('packages/foo/.SF UI Text', ['packages/foo/fonts/sf.ttf'])), equals('.SF UI Text'), ); expect( - derivedFontFamily(_font('packages/foo/.SF Pro Text', ['packages/foo/fonts/sf.ttf'])), + derivedFontFamily( + _font('packages/foo/.SF Pro Text', ['packages/foo/fonts/sf.ttf'])), equals('.SF Pro Text'), ); expect( - derivedFontFamily(_font('packages/foo/.SF Pro Display', ['packages/foo/fonts/sf.ttf'])), + derivedFontFamily(_font( + 'packages/foo/.SF Pro Display', ['packages/foo/fonts/sf.ttf'])), equals('.SF Pro Display'), ); }); test('leave packaged font families unaltered', () { expect( - derivedFontFamily(_font('packages/foo/bar', ['packages/foo/fonts/bar.ttf'])), + derivedFontFamily( + _font('packages/foo/bar', ['packages/foo/fonts/bar.ttf'])), equals('packages/foo/bar'), ); }); diff --git a/packages/golden_toolkit/test/golden_assertion_test.dart b/packages/golden_toolkit/test/golden_assertion_test.dart index 7421601..37a8b29 100644 --- a/packages/golden_toolkit/test/golden_assertion_test.dart +++ b/packages/golden_toolkit/test/golden_assertion_test.dart @@ -13,19 +13,25 @@ import 'package:golden_toolkit/golden_toolkit.dart'; void main() { group('testGoldens validation', () { - testWidgets('screenMatchesGolden should require testGoldens', (tester) async { + testWidgets('screenMatchesGolden should require testGoldens', + (tester) async { await tester.pumpWidgetBuilder(Container(height: 100, width: 100)); - await expectLater(() => screenMatchesGolden(tester, 'anything'), throwsA(isInstanceOf())); + await expectLater(() => screenMatchesGolden(tester, 'anything'), + throwsA(isInstanceOf())); }); - testGoldens('screenMatchesGolden filename should not include extension', (tester) async { + testGoldens('screenMatchesGolden filename should not include extension', + (tester) async { await tester.pumpWidget(Container(height: 100, width: 100)); - await expectLater(() => screenMatchesGolden(tester, 'anything.png'), throwsAssertionError); + await expectLater(() => screenMatchesGolden(tester, 'anything.png'), + throwsAssertionError); }); - testGoldens('Goldens for multiple sized devices should respect specified finder', (tester) async { + testGoldens( + 'Goldens for multiple sized devices should respect specified finder', + (tester) async { // This is an example of how a larger widget tree can be pumped, but goldens can be created capturing just a certain child widget await tester.pumpWidgetBuilder( Container( diff --git a/packages/golden_toolkit/test/golden_builder_test.dart b/packages/golden_toolkit/test/golden_builder_test.dart index 0358908..de82bf4 100644 --- a/packages/golden_toolkit/test/golden_builder_test.dart +++ b/packages/golden_toolkit/test/golden_builder_test.dart @@ -17,39 +17,51 @@ void main() { await tester.pumpWidgetBuilder( Center( child: (GoldenBuilder.column() - ..addScenario('red', Container(height: 50, width: 50, color: Colors.red)) - ..addScenario('green', Container(height: 50, width: 50, color: Colors.green)) - ..addScenario('blue', Container(height: 50, width: 50, color: Colors.blue))) + ..addScenario('red', + Container(height: 50, width: 50, color: Colors.red)) + ..addScenario('green', + Container(height: 50, width: 50, color: Colors.green)) + ..addScenario('blue', + Container(height: 50, width: 50, color: Colors.blue))) .build()), surfaceSize: const Size(100, 300), ); - await screenMatchesGolden(tester, 'golden_builder_column', autoHeight: true); + await screenMatchesGolden(tester, 'golden_builder_column', + autoHeight: true); }); testGoldens('Grid layout example', (tester) async { await tester.pumpWidgetBuilder( Center( child: (GoldenBuilder.grid(columns: 2, widthToHeightRatio: 1) - ..addScenario('red', Container(height: 50, width: 50, color: Colors.red)) - ..addScenario('green', Container(height: 50, width: 50, color: Colors.green)) - ..addScenario('blue', Container(height: 50, width: 50, color: Colors.blue))) + ..addScenario('red', + Container(height: 50, width: 50, color: Colors.red)) + ..addScenario('green', + Container(height: 50, width: 50, color: Colors.green)) + ..addScenario('blue', + Container(height: 50, width: 50, color: Colors.blue))) .build()), surfaceSize: const Size(300, 300), ); - await screenMatchesGolden(tester, 'golden_builder_grid', autoHeight: true); + await screenMatchesGolden(tester, 'golden_builder_grid', + autoHeight: true); }); testGoldens('TextScaleScenario', (tester) async { await tester.pumpWidgetBuilder( Center( child: (GoldenBuilder.column() - ..addTextScaleScenario('small', const Text('text'), textScaleFactor: 1.0) - ..addTextScaleScenario('medium', const Text('text'), textScaleFactor: 2.0) - ..addTextScaleScenario('large', const Text('text'), textScaleFactor: 3.2)) + ..addTextScaleScenario('small', const Text('text'), + textScaleFactor: 1.0) + ..addTextScaleScenario('medium', const Text('text'), + textScaleFactor: 2.0) + ..addTextScaleScenario('large', const Text('text'), + textScaleFactor: 3.2)) .build()), surfaceSize: const Size(100, 300), ); - await screenMatchesGolden(tester, 'golden_builder_textscale', autoHeight: true); + await screenMatchesGolden(tester, 'golden_builder_textscale', + autoHeight: true); }); }); } diff --git a/packages/golden_toolkit/test/image_loading/default/default_asset_loading_test.dart b/packages/golden_toolkit/test/image_loading/default/default_asset_loading_test.dart index e0e8542..68861c6 100644 --- a/packages/golden_toolkit/test/image_loading/default/default_asset_loading_test.dart +++ b/packages/golden_toolkit/test/image_loading/default/default_asset_loading_test.dart @@ -9,12 +9,14 @@ void main() { group( 'Image Loading Tests', () { - testWidgets('demonstrate that waitForAssets is required for: Image', (tester) async { + testWidgets('demonstrate that waitForAssets is required for: Image', + (tester) async { await GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(const ImageWidget()); await tester.pump(); - await expectLater(find.byType(ImageWidget).first, matchesGoldenFile('goldens/image_wont_show.png')); + await expectLater(find.byType(ImageWidget).first, + matchesGoldenFile('goldens/image_wont_show.png')); }, config: defaultConfiguration, ); @@ -26,38 +28,43 @@ void main() { await tester.pumpWidgetBuilder(const ImageWidget()); await tester.waitForAssets(); await tester.pump(); - await expectLater(find.byType(ImageWidget).first, matchesGoldenFile('goldens/image_will_show.png')); + await expectLater(find.byType(ImageWidget).first, + matchesGoldenFile('goldens/image_will_show.png')); }, config: defaultConfiguration, ); }); - testWidgets('demonstrate that waitForAssets is required for: BoxDecoration', (tester) async { + testWidgets( + 'demonstrate that waitForAssets is required for: BoxDecoration', + (tester) async { await GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(const BoxDecorationWithImage()); await tester.pump(); - await expectLater( - find.byType(BoxDecorationWithImage).first, matchesGoldenFile('goldens/boxdecoration_wont_show.png')); + await expectLater(find.byType(BoxDecorationWithImage).first, + matchesGoldenFile('goldens/boxdecoration_wont_show.png')); }, config: defaultConfiguration, ); }); - testWidgets('should load assets from BoxDecoration images', (tester) async { + testWidgets('should load assets from BoxDecoration images', + (tester) async { await GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(const BoxDecorationWithImage()); await tester.waitForAssets(); await tester.pump(); - await expectLater( - find.byType(BoxDecorationWithImage).first, matchesGoldenFile('goldens/boxdecoration_will_show.png')); + await expectLater(find.byType(BoxDecorationWithImage).first, + matchesGoldenFile('goldens/boxdecoration_will_show.png')); }, config: defaultConfiguration, ); }); - testWidgets('should load assets that have not come into view yet', (tester) async { + testWidgets('should load assets that have not come into view yet', + (tester) async { await GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder( @@ -71,8 +78,8 @@ void main() { await tester.waitForAssets(); await tester.drag(find.byType(Scrollable), const Offset(0, -1000)); await tester.pump(); - await expectLater( - find.byType(ListOfItemsWithOneImage).first, matchesGoldenFile('goldens/list_of_images_will_show.png')); + await expectLater(find.byType(ListOfItemsWithOneImage).first, + matchesGoldenFile('goldens/list_of_images_will_show.png')); }, config: defaultConfiguration, ); diff --git a/packages/golden_toolkit/test/image_loading/image_loading_utils.dart b/packages/golden_toolkit/test/image_loading/image_loading_utils.dart index 327e727..e7a2bcc 100644 --- a/packages/golden_toolkit/test/image_loading/image_loading_utils.dart +++ b/packages/golden_toolkit/test/image_loading/image_loading_utils.dart @@ -21,7 +21,8 @@ class BoxDecorationWithImage extends StatelessWidget { return const DecoratedBox( decoration: BoxDecoration( image: DecorationImage( - image: AssetImage('images/earth_image.jpg', package: 'sample_dependency'), + image: AssetImage('images/earth_image.jpg', + package: 'sample_dependency'), ), ), ); @@ -58,7 +59,9 @@ class ListOfItemsWithOneImage extends StatelessWidget { width: itemSize.width, height: itemSize.height, color: Colors.lightBlue, - child: (index == indexThatContainsImage) ? const ImageWidget() : null, + child: (index == indexThatContainsImage) + ? const ImageWidget() + : null, ), ], ), diff --git a/packages/golden_toolkit/test/image_loading/legacy/box_decoration_load_test.dart b/packages/golden_toolkit/test/image_loading/legacy/box_decoration_load_test.dart index e90c168..7af453f 100644 --- a/packages/golden_toolkit/test/image_loading/legacy/box_decoration_load_test.dart +++ b/packages/golden_toolkit/test/image_loading/legacy/box_decoration_load_test.dart @@ -8,14 +8,17 @@ void main() { group( 'Image Loading Tests - Legacy', () { - testWidgets('should load assets from BoxDecoration images', (tester) async { + testWidgets('should load assets from BoxDecoration images', + (tester) async { await GoldenToolkit.runWithConfiguration( () async { await tester.pumpWidgetBuilder(const BoxDecorationWithImage()); await tester.waitForAssets(); await tester.pump(); - await expectLater(find.byType(BoxDecorationWithImage).first, - matchesGoldenFile('goldens/boxdecoration_will_show_legacy.png')); + await expectLater( + find.byType(BoxDecorationWithImage).first, + matchesGoldenFile( + 'goldens/boxdecoration_will_show_legacy.png')); }, config: legacyConfiguration, ); diff --git a/packages/golden_toolkit/test/image_loading/legacy/image_widget_load_test.dart b/packages/golden_toolkit/test/image_loading/legacy/image_widget_load_test.dart index 95ae134..527adf4 100644 --- a/packages/golden_toolkit/test/image_loading/legacy/image_widget_load_test.dart +++ b/packages/golden_toolkit/test/image_loading/legacy/image_widget_load_test.dart @@ -14,7 +14,8 @@ void main() { await tester.pumpWidgetBuilder(const ImageWidget()); await tester.waitForAssets(); await tester.pump(); - await expectLater(find.byType(ImageWidget).first, matchesGoldenFile('goldens/image_will_show_legacy.png')); + await expectLater(find.byType(ImageWidget).first, + matchesGoldenFile('goldens/image_will_show_legacy.png')); }, config: legacyConfiguration, ); diff --git a/packages/golden_toolkit/test/material_app_wrapper_test.dart b/packages/golden_toolkit/test/material_app_wrapper_test.dart index e8cd7a0..76a9019 100644 --- a/packages/golden_toolkit/test/material_app_wrapper_test.dart +++ b/packages/golden_toolkit/test/material_app_wrapper_test.dart @@ -4,13 +4,15 @@ import 'package:golden_toolkit/golden_toolkit.dart'; void main() { group('materialAppWrapper', () { - testWidgets('navigatorObserver should be passed into material app', (tester) async { + testWidgets('navigatorObserver should be passed into material app', + (tester) async { final observer = _SampleNavigatorObserver(); await tester.pumpWidgetBuilder( Builder( builder: (context) => MaterialButton( onPressed: () { - Navigator.of(context).push(MaterialPageRoute(builder: (_) => Container())); + Navigator.of(context) + .push(MaterialPageRoute(builder: (_) => Container())); }, ), ), diff --git a/packages/golden_toolkit/test/multi_screen_golden_test.dart b/packages/golden_toolkit/test/multi_screen_golden_test.dart index 9266154..230ba42 100644 --- a/packages/golden_toolkit/test/multi_screen_golden_test.dart +++ b/packages/golden_toolkit/test/multi_screen_golden_test.dart @@ -15,7 +15,9 @@ Future main() async { group('Responsive layout when image changes depending on layout', () { testGoldens('Safe Area test', (tester) async { await tester.pumpWidgetBuilder( - Container(color: Colors.white, child: SafeArea(child: Container(color: Colors.blue))), + Container( + color: Colors.white, + child: SafeArea(child: Container(color: Colors.blue))), ); await multiScreenGolden( tester, @@ -38,7 +40,10 @@ Future main() async { await tester.pumpWidgetBuilder( Builder( builder: (context) => Container( - color: MediaQuery.of(context).platformBrightness == Brightness.dark ? Colors.grey : Colors.white, + color: + MediaQuery.of(context).platformBrightness == Brightness.dark + ? Colors.grey + : Colors.white, child: Text(MediaQuery.of(context).platformBrightness.toString()), ), ), @@ -87,13 +92,17 @@ Future main() async { expect(tester.binding.createViewConfiguration().size, equals(size)); expect(tester.binding.window.physicalSize, equals(initialSize)); - expect(tester.binding.window.platformBrightness, equals(initialBrightness)); - expect(tester.binding.window.devicePixelRatio, equals(initialDevicePixelRatio)); - expect(tester.binding.window.textScaleFactor, equals(initialTextScaleFactor)); + expect(tester.binding.window.platformBrightness, + equals(initialBrightness)); + expect(tester.binding.window.devicePixelRatio, + equals(initialDevicePixelRatio)); + expect(tester.binding.window.textScaleFactor, + equals(initialTextScaleFactor)); expect(tester.binding.window.padding, equals(initialViewInsets)); }); - testGoldens('Should expand scrollable if autoHeight is true', (tester) async { + testGoldens('Should expand scrollable if autoHeight is true', + (tester) async { await tester.pumpWidgetBuilder(ListView.builder( itemBuilder: (BuildContext context, int index) { return Container( @@ -118,7 +127,8 @@ Future main() async { ); }); - testGoldens('Should expand scrollable only if not infinite', (tester) async { + testGoldens('Should expand scrollable only if not infinite', + (tester) async { await tester.pumpWidgetBuilder(ListView.builder( itemBuilder: (BuildContext context, int index) { return Container( @@ -142,7 +152,8 @@ Future main() async { ); }); - testGoldens('Should shrink to finders height if autoHeight is true', (tester) async { + testGoldens('Should shrink to finders height if autoHeight is true', + (tester) async { await tester.pumpWidget(Center( // We center here so the Container is not forced to go full height child: Container(color: Colors.red, height: 50), @@ -163,7 +174,8 @@ Future main() async { ); }); - testGoldens('Should set to exact height if override height is specified', (tester) async { + testGoldens('Should set to exact height if override height is specified', + (tester) async { await tester.pumpWidget(Center( // We center here so the Container is not forced to go full height child: Container(color: Colors.red, height: 50), diff --git a/packages/golden_toolkit/test/platform_agnostic_test.dart b/packages/golden_toolkit/test/platform_agnostic_test.dart index d90fbbb..2a4be91 100644 --- a/packages/golden_toolkit/test/platform_agnostic_test.dart +++ b/packages/golden_toolkit/test/platform_agnostic_test.dart @@ -13,7 +13,8 @@ void main() { await tester.pumpWidget(Container()); await screenMatchesGolden(tester, 'empty_container'); }, - config: GoldenToolkit.configuration.copyWith(skipGoldenAssertion: () => false), + config: GoldenToolkit.configuration + .copyWith(skipGoldenAssertion: () => false), ); }); }); diff --git a/packages/golden_toolkit/test/screen_matches_golden_test.dart b/packages/golden_toolkit/test/screen_matches_golden_test.dart index 6d2f419..af2fc6d 100644 --- a/packages/golden_toolkit/test/screen_matches_golden_test.dart +++ b/packages/golden_toolkit/test/screen_matches_golden_test.dart @@ -10,7 +10,8 @@ void main() { await tester.pumpWidgetBuilder( ValueListenableBuilder( valueListenable: dynamicColor, - builder: (ctx, color, _) => AnimatedContainer(color: color, duration: const Duration(seconds: 1)), + builder: (ctx, color, _) => AnimatedContainer( + color: color, duration: const Duration(seconds: 1)), ), surfaceSize: const Size(60, 60), ); diff --git a/packages/golden_toolkit/test/test_asset_builder_test.dart b/packages/golden_toolkit/test/test_asset_builder_test.dart index a27591b..5467db8 100644 --- a/packages/golden_toolkit/test/test_asset_builder_test.dart +++ b/packages/golden_toolkit/test/test_asset_builder_test.dart @@ -8,7 +8,8 @@ void main() { /* chasing code coverage... we're at 99% coverage, and this slightly forked code is the last 1% */ test('Should throw if asset not found', () { final bundle = FakeTestAssetBundle(); - expectLater(() => bundle.loadString('nothing'), throwsA(isInstanceOf())); + expectLater(() => bundle.loadString('nothing'), + throwsA(isInstanceOf())); }); }); }