Skip to content

Commit 96411b2

Browse files
authored
Merge pull request #71 from eBay/update-formatting
Update formatting / changelog / docs / new version #
2 parents 43445ee + 87fb2e7 commit 96411b2

31 files changed

+373
-184
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ before_script:
77
script:
88
- cd packages/golden_toolkit
99
- ../../flutter/bin/flutter analyze
10-
- ../../flutter/bin/cache/dart-sdk/bin/dartfmt -n ./lib -l 120 --set-exit-if-changed
10+
- ../../flutter/bin/cache/dart-sdk/bin/dartfmt -n ./lib --set-exit-if-changed
1111
- ../../flutter/bin/flutter test --coverage --coverage-path=lcov.info
1212
- cd example
1313
- ../../../flutter/bin/flutter analyze
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"editor.insertSpaces": false,
3-
"editor.wordWrapColumn": 120
3+
"editor.wordWrapColumn": 80,
4+
"dart.lineLength": 80
45
}

packages/golden_toolkit/CHANGELOG.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
# Changelog
22

3+
## 0.7.0
4+
5+
Thanks to @moonytoes29 for the following enhancements:
6+
7+
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.
8+
9+
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.
10+
311
## 0.6.0
412

5-
Added the ability to configure the default set of devices to use for ```multiScreenGolden``` assertions globally.
13+
Added the ability to configure the default set of devices to use for `multiScreenGolden` assertions globally.
614

715
For example:
8-
```GoldenToolkitConfiguration(defaultDevices: [Device.iphone11, Device.iphone11.dark()])```
16+
`GoldenToolkitConfiguration(defaultDevices: [Device.iphone11, Device.iphone11.dark()])`
917

10-
As part of this, the default parameter value has been removed from ```multiScreenGolden```.
18+
As part of this, the default parameter value has been removed from `multiScreenGolden`.
1119

1220
There was also a minor breaking change in that the const constructor of GoldenToolkitConfiguration is no longer const.
1321

1422
## 0.5.1
1523

16-
Improved the reliability of the default behavior for ```tester.waitForAssets()``` to handle additional cases.
24+
Improved the reliability of the default behavior for `tester.waitForAssets()` to handle additional cases.
1725

1826
## 0.5.0
1927

@@ -23,7 +31,7 @@ A new mechanism has been added for ensuring that images have been decoded before
2331

2432
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:
2533

26-
```GoldenToolkitConfiguration(primeAssets: legacyPrimeAssets);```
34+
`GoldenToolkitConfiguration(primeAssets: legacyPrimeAssets);`
2735

2836
Additionally, you can provide your own implementation that extends the new default behavior:
2937

@@ -48,26 +56,26 @@ GoldenToolkit.runWithConfiguration((){/* callback() */}, config: GoldenToolkitCo
4856

4957
### Added the ability to customize the generated filenames
5058

51-
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.
59+
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.
5260

5361
```dart
5462
GoldenToolkit.runWithConfiguration((){ /* callback() */}, config: GoldenToolkitConfiguration(fileNameFactory: (filename) => '' /*output filename*/));
5563
```
5664

5765
There are two methods that can be overridden:
5866

59-
* ```fileNameFactory``` is used for screenMatchesGolden
60-
* ```deviceFileNameFactory``` is used for multiScreenGolden
67+
- `fileNameFactory` is used for screenMatchesGolden
68+
- `deviceFileNameFactory` is used for multiScreenGolden
6169

6270
Future releases will likely consolidate these APIs.
6371

6472
Thanks to @christian-muertz for this enhancement.
6573

6674
### Added additional utility functions for preparing for goldens
6775

68-
Extracted out some public extension methods that were previously private implementation details of ```multiScreenGolden``` & ```screenMatchesGolden```
76+
Extracted out some public extension methods that were previously private implementation details of `multiScreenGolden` & `screenMatchesGolden`
6977

70-
Added the following extensions. These can be used with any vanilla golden assertions and do not require ```multiScreenGolden```, ```screenMatchesGolden```, or ```GoldenBuilder```.
78+
Added the following extensions. These can be used with any vanilla golden assertions and do not require `multiScreenGolden`, `screenMatchesGolden`, or `GoldenBuilder`.
7179

7280
```dart
7381
// 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
95103

96104
### Configuration API
97105

98-
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```.
106+
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`.
99107

100108
You can now call:
101109

@@ -109,7 +117,7 @@ GoldenToolkit.configure(GoldenToolkitConfiguration(skipGoldenAssertion: () => /*
109117

110118
### Auto-Sized Goldens
111119

112-
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!
120+
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!
113121

114122
## 0.3.2
115123

packages/golden_toolkit/README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ The output of this test will be this golden file: `weather_accessibility.png`:
7474

7575
See tests for usage examples: [golden_builder_test.dart](example/test/golden_builder_test.dart)
7676

77-
7877
### DeviceBuilder
7978

8079
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.
8382
It will generate a widget that lays out its scenarios vertically and the Device configurations of those scenarios horizontally. All in one single
8483
golden png file.
8584

86-
In the case of a single scenario the helper method of (#multiDeviceGolden) can simplify DeviceBuilder usage. For multiple scenarios, DeviceBuilder
87-
can help
88-
8985
```dart
9086
testGoldens('DeviceBuilder - multiple scenarios - with onCreate',
9187
(tester) async {
@@ -142,7 +138,6 @@ This will generate the following golden:
142138

143139
![example widget captured](example/test/goldens/flutter_demo_page_multiple_scenarios.png)
144140

145-
146141
### multiScreenGolden
147142

148143
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
227222
"request": "launch",
228223
"type": "dart",
229224
"codeLens": {
230-
"for": [
231-
"run-test",
232-
"run-test-file"
233-
]
225+
"for": ["run-test", "run-test-file"]
234226
},
235227
"args": ["--update-goldens"]
236228
}
@@ -358,7 +350,7 @@ See more usage examples here: [golden_builder_test.dart](test/golden_builder_tes
358350

359351
There are global settings that can be configured by calling the following API:
360352

361-
```GoldenToolkit.runWithConfiguration()```
353+
`GoldenToolkit.runWithConfiguration()`
362354

363355
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.
364356

packages/golden_toolkit/example/lib/src/weather_widgets.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class WeatherForecast extends StatelessWidget {
5656
shape: const CircleBorder(),
5757
),
5858
textTheme: theme.textTheme.copyWith(
59-
bodyText2: theme.textTheme.bodyText2.copyWith(fontSize: 24),
59+
bodyText2:
60+
theme.textTheme.bodyText2.copyWith(fontSize: 24),
6061
),
6162
),
6263
child: WeatherCard.forecast(today),
@@ -70,8 +71,10 @@ class WeatherForecast extends StatelessWidget {
7071
Column(
7172
mainAxisSize: MainAxisSize.min,
7273
children: [
73-
Text('This Week\'s Forecast', style: Theme.of(context).textTheme.headline6),
74-
if (MediaQuery.of(context).size.width > 400 && MediaQuery.of(context).size.height > 600)
74+
Text('This Week\'s Forecast',
75+
style: Theme.of(context).textTheme.headline6),
76+
if (MediaQuery.of(context).size.width > 400 &&
77+
MediaQuery.of(context).size.height > 600)
7578
WeeklyForecastExpanded(forecasts: _list)
7679
else
7780
WeeklyForecastCompact(forecasts: _list),
@@ -107,7 +110,9 @@ class WeeklyForecastExpanded extends StatelessWidget {
107110
const SizedBox(width: 8),
108111
Flexible(
109112
flex: 5,
110-
child: Align(alignment: Alignment.centerLeft, child: Text(f.description)),
113+
child: Align(
114+
alignment: Alignment.centerLeft,
115+
child: Text(f.description)),
111116
),
112117
],
113118
))
@@ -293,7 +298,8 @@ enum Weather {
293298
cloudy,
294299
}
295300

296-
final RoundedRectangleBorder _cardShape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0));
301+
final RoundedRectangleBorder _cardShape =
302+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0));
297303

298304
class Forecast {
299305
const Forecast({this.day, this.temp, this.weather, this.description});

packages/golden_toolkit/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ packages:
6666
path: ".."
6767
relative: true
6868
source: path
69-
version: "0.6.0"
69+
version: "0.7.0"
7070
matcher:
7171
dependency: transitive
7272
description:

packages/golden_toolkit/example/test/example_test.dart

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ void main() {
3030
bgColor: Colors.white,
3131
widthToHeightRatio: 1,
3232
)
33-
..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
34-
..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
35-
..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain))
33+
..addScenario(
34+
'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
35+
..addScenario(
36+
'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
37+
..addScenario(
38+
'Raining', const WeatherCard(temp: 37, weather: Weather.rain))
3639
..addScenario(
3740
'Cold',
3841
const WeatherCard(temp: 25, weather: Weather.cold),
@@ -46,15 +49,20 @@ void main() {
4649
});
4750

4851
/// lays out the results in a column
49-
testGoldens('COLUMN: Different weather types with extra frame', (tester) async {
52+
testGoldens('COLUMN: Different weather types with extra frame',
53+
(tester) async {
5054
final gb = GoldenBuilder.column(
5155
bgColor: Colors.white,
5256
wrap: _simpleFrame,
5357
)
54-
..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
55-
..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
56-
..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain))
57-
..addScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold));
58+
..addScenario(
59+
'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
60+
..addScenario(
61+
'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
62+
..addScenario(
63+
'Raining', const WeatherCard(temp: 37, weather: Weather.rain))
64+
..addScenario(
65+
'Cold', const WeatherCard(temp: 25, weather: Weather.cold));
5866

5967
await tester.pumpWidgetBuilder(
6068
gb.build(),
@@ -65,13 +73,19 @@ void main() {
6573

6674
/// Demonstrates how golden builder can be combined with multiScreenGolden to
6775
/// test with multiple dimensions of parameters
68-
testGoldens('Card should look right on different devices / screen sizes', (tester) async {
76+
testGoldens('Card should look right on different devices / screen sizes',
77+
(tester) async {
6978
final gb = GoldenBuilder.column(bgColor: Colors.white)
70-
..addScenario('Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
71-
..addScenario('Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
72-
..addScenario('Raining', const WeatherCard(temp: 37, weather: Weather.rain))
73-
..addScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold))
74-
..addTextScaleScenario('Cold', const WeatherCard(temp: 25, weather: Weather.cold));
79+
..addScenario(
80+
'Sunny', const WeatherCard(temp: 66, weather: Weather.sunny))
81+
..addScenario(
82+
'Cloudy', const WeatherCard(temp: 56, weather: Weather.cloudy))
83+
..addScenario(
84+
'Raining', const WeatherCard(temp: 37, weather: Weather.rain))
85+
..addScenario(
86+
'Cold', const WeatherCard(temp: 25, weather: Weather.cold))
87+
..addTextScaleScenario(
88+
'Cold', const WeatherCard(temp: 25, weather: Weather.cold));
7589

7690
await tester.pumpWidgetBuilder(
7791
gb.build(),
@@ -88,13 +102,17 @@ void main() {
88102

89103
group('GoldenBuilder examples of accessibility testing', () {
90104
// With those test we want to make sure our widgets look right when user changes system font size
91-
testGoldens('Card should look right when user bumps system font size', (tester) async {
105+
testGoldens('Card should look right when user bumps system font size',
106+
(tester) async {
92107
const widget = WeatherCard(temp: 56, weather: Weather.cloudy);
93108

94-
final gb = GoldenBuilder.column(bgColor: Colors.white, wrap: _simpleFrame)
95-
..addScenario('Regular font size', widget)
96-
..addTextScaleScenario('Large font size', widget, textScaleFactor: 2.0)
97-
..addTextScaleScenario('Largest font size', widget, textScaleFactor: 3.2);
109+
final gb =
110+
GoldenBuilder.column(bgColor: Colors.white, wrap: _simpleFrame)
111+
..addScenario('Regular font size', widget)
112+
..addTextScaleScenario('Large font size', widget,
113+
textScaleFactor: 2.0)
114+
..addTextScaleScenario('Largest font size', widget,
115+
textScaleFactor: 3.2);
98116

99117
await tester.pumpWidgetBuilder(
100118
gb.build(),
@@ -119,17 +137,23 @@ void main() {
119137
///then you may run into issues with some images not displaying properly.
120138
///
121139
///This is an example of the the "issue"
122-
testGoldens('Some images missing in multiScreenGoldens that require additional setup', (tester) async {
123-
await tester.pumpWidgetBuilder(_forecastWithDifferentImagesForLargeAndSmallScreen());
140+
testGoldens(
141+
'Some images missing in multiScreenGoldens that require additional setup',
142+
(tester) async {
143+
await tester.pumpWidgetBuilder(
144+
_forecastWithDifferentImagesForLargeAndSmallScreen());
124145
await multiScreenGolden(
125146
tester,
126147
'example_of_images_not_properly_loading',
127148
);
128149
});
129150

130151
///here is an example of how to workaround it.
131-
testGoldens('Should render images in multiScreenGoldens that require additional setup', (tester) async {
132-
await tester.pumpWidgetBuilder(_forecastWithDifferentImagesForLargeAndSmallScreen());
152+
testGoldens(
153+
'Should render images in multiScreenGoldens that require additional setup',
154+
(tester) async {
155+
await tester.pumpWidgetBuilder(
156+
_forecastWithDifferentImagesForLargeAndSmallScreen());
133157
await multiScreenGolden(
134158
tester,
135159
'weather_image_async_load_correct_duration',
@@ -176,7 +200,9 @@ Widget _forecastWithDifferentImagesForLargeAndSmallScreen() {
176200
}
177201

178202
class FutureWidgetTester extends StatefulWidget {
179-
const FutureWidgetTester({Key key, this.child, this.duration = const Duration(milliseconds: 100)}) : super(key: key);
203+
const FutureWidgetTester(
204+
{Key key, this.child, this.duration = const Duration(milliseconds: 100)})
205+
: super(key: key);
180206
final Widget child;
181207
final Duration duration;
182208
@override
@@ -205,7 +231,8 @@ class _FutureWidgetTesterState extends State<FutureWidgetTester> {
205231
}
206232

207233
class InvalidateWidgetTreeWhenSizeChanges extends StatelessWidget {
208-
const InvalidateWidgetTreeWhenSizeChanges({Key key, this.child}) : super(key: key);
234+
const InvalidateWidgetTreeWhenSizeChanges({Key key, this.child})
235+
: super(key: key);
209236
final Widget child;
210237

211238
@override

packages/golden_toolkit/example/test/flutter_demo_page_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ void main() {
1818
await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario');
1919
});
2020

21-
testGoldens('DeviceBuilder - one scenario - override devices', (tester) async {
21+
testGoldens('DeviceBuilder - one scenario - override devices',
22+
(tester) async {
2223
final builder = DeviceBuilder()
2324
..overrideDevicesForAllScenarios(devices: [
2425
Device.phone,
@@ -33,10 +34,12 @@ void main() {
3334

3435
await tester.pumpDeviceBuilder(builder);
3536

36-
await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario_more_devices');
37+
await screenMatchesGolden(
38+
tester, 'flutter_demo_page_single_scenario_more_devices');
3739
});
3840

39-
testGoldens('DeviceBuilder - multiple scenarios - with onCreate', (tester) async {
41+
testGoldens('DeviceBuilder - multiple scenarios - with onCreate',
42+
(tester) async {
4043
final builder = DeviceBuilder()
4144
..overrideDevicesForAllScenarios(devices: [
4245
Device.phone,

packages/golden_toolkit/lib/src/configuration.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import 'device.dart';
2121
class GoldenToolkit {
2222
GoldenToolkit._();
2323

24-
static GoldenToolkitConfiguration _configuration = GoldenToolkitConfiguration();
24+
static GoldenToolkitConfiguration _configuration =
25+
GoldenToolkitConfiguration();
2526

2627
/// Applies a GoldenToolkitConfiguration to a block of code to effectively provide a scoped
2728
/// singleton. The configuration will apply to just the injected body function.
@@ -121,7 +122,8 @@ class GoldenToolkitConfiguration {
121122
return GoldenToolkitConfiguration(
122123
skipGoldenAssertion: skipGoldenAssertion ?? this.skipGoldenAssertion,
123124
fileNameFactory: fileNameFactory ?? this.fileNameFactory,
124-
deviceFileNameFactory: deviceFileNameFactory ?? this.deviceFileNameFactory,
125+
deviceFileNameFactory:
126+
deviceFileNameFactory ?? this.deviceFileNameFactory,
125127
primeAssets: primeAssets ?? this.primeAssets,
126128
defaultDevices: defaultDevices ?? this.defaultDevices,
127129
);

0 commit comments

Comments
 (0)