Skip to content

Commit 831e127

Browse files
PR updates
1 parent b10a612 commit 831e127

File tree

6 files changed

+28
-57
lines changed

6 files changed

+28
-57
lines changed

lib/src/goldens/golden_collections.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ import 'package:image/image.dart' as img;
1313
/// corresponding golden image.
1414
/// {@endtemplate}
1515
class GoldenCollection {
16-
GoldenCollection(
17-
this.imagesById, {
18-
required this.metadata,
19-
});
16+
GoldenCollection(this.imagesById);
2017

2118
final Map<String, GoldenImage> imagesById;
2219

23-
final GoldenSceneMetadata metadata;
24-
2520
List<String> get ids => imagesById.keys.toList(growable: false);
2621

2722
bool hasId(String id) => imagesById[id] != null;

lib/src/goldens/golden_scenes.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:image/image.dart';
1515
///
1616
/// This function loads the scene image from the [file], extracts each individual golden
1717
/// image from the scene, and then returns all of those golden images as a [GoldenCollection].
18-
GoldenCollection extractGoldenCollectionFromSceneFile(File file) {
18+
(GoldenCollection, GoldenSceneMetadata) extractGoldenCollectionFromSceneFile(File file) {
1919
FtgLog.pipeline.fine("Extracting golden collection from golden image.");
2020

2121
// Read the scene PNG data into memory.
@@ -38,7 +38,7 @@ GoldenCollection extractGoldenCollectionFromSceneFile(File file) {
3838
}
3939

4040
// Extract the golden images from the scene image.
41-
return _extractCollectionFromScene(sceneMetadata, sceneImage);
41+
return (_extractCollectionFromScene(sceneMetadata, sceneImage), sceneMetadata);
4242
}
4343

4444
/// Extracts a [GoldenCollection] from a golden scene within the current widget tree.
@@ -100,10 +100,7 @@ GoldenCollection _extractCollectionFromScene(GoldenSceneMetadata sceneMetadata,
100100
);
101101
}
102102

103-
return GoldenCollection(
104-
goldenImages,
105-
metadata: sceneMetadata,
106-
);
103+
return GoldenCollection(goldenImages);
107104
}
108105

109106
RenderRepaintBoundary? _findNearestRepaintBoundary(Finder bounds) {
@@ -131,6 +128,7 @@ RenderRepaintBoundary? _findNearestRepaintBoundary(Finder bounds) {
131128
class GoldenSceneMetadata {
132129
static GoldenSceneMetadata fromJson(Map<String, dynamic> json) {
133130
return GoldenSceneMetadata(
131+
description: json["description"] ?? "",
134132
images: [
135133
for (final imageJson in (json["images"] as List<dynamic>)) //
136134
GoldenImageMetadata.fromJson(imageJson),
@@ -139,13 +137,16 @@ class GoldenSceneMetadata {
139137
}
140138

141139
const GoldenSceneMetadata({
140+
required this.description,
142141
required this.images,
143142
});
144143

144+
final String description;
145145
final List<GoldenImageMetadata> images;
146146

147147
Map<String, dynamic> toJson() {
148148
return {
149+
"description": description,
149150
"images": images.map((image) => image.toJson()).toList(growable: false),
150151
};
151152
}

lib/src/scenes/film_strip.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class FilmStrip {
277277
// Lookup and return metadata for the position and size of each golden image
278278
// within the gallery.
279279
return GoldenSceneMetadata(
280+
description: goldenName,
280281
images: [
281282
for (final golden in renderablePhotos.keys)
282283
GoldenImageMetadata(
@@ -339,7 +340,7 @@ class FilmStrip {
339340
// TODO: report error in structured way.
340341
throw Exception("Can't compare goldens. Golden file doesn't exist: ${goldenFile.path}");
341342
}
342-
final goldenCollection = extractGoldenCollectionFromSceneFile(goldenFile);
343+
final (goldenCollection, metadata) = extractGoldenCollectionFromSceneFile(goldenFile);
343344

344345
FtgLog.pipeline.fine("Extracting golden collection from current widget tree (screenshots).");
345346
late final GoldenCollection screenshotCollection;

lib/src/scenes/gallery.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ class Gallery {
396396
// Lookup and return metadata for the position and size of each golden image
397397
// within the gallery.
398398
return GoldenSceneMetadata(
399+
description: _sceneDescription,
399400
images: [
400401
for (final golden in renderablePhotos.keys)
401402
GoldenImageMetadata(
@@ -459,7 +460,7 @@ class Gallery {
459460
// TODO: report error in structured way.
460461
throw Exception("Can't compare goldens. Golden file doesn't exist: ${goldenFile.path}");
461462
}
462-
final goldenCollection = extractGoldenCollectionFromSceneFile(goldenFile);
463+
final (goldenCollection, metadata) = extractGoldenCollectionFromSceneFile(goldenFile);
463464

464465
// Extract scene metadata from the current widget tree.
465466
FtgLog.pipeline.fine("Extracting golden collection from current widget tree (screenshots).");
@@ -505,21 +506,15 @@ class Gallery {
505506
// The golden check passed.
506507
items.add(
507508
GoldenReport.success(
508-
goldenCollection.metadata.images.where((image) => image.id == screenshotId).first,
509+
metadata.images.where((image) => image.id == screenshotId).first,
509510
),
510511
);
511512
} else {
512513
// The golden check failed.
513514
items.add(
514515
GoldenReport.failure(
515-
metadata: goldenCollection.metadata.images.where((image) => image.id == screenshotId).first,
516-
details: [
517-
GoldenCheckDetail(
518-
status: GoldenTestStatus.failure,
519-
description: mismatch.toString(),
520-
mismatch: mismatch,
521-
),
522-
],
516+
metadata: metadata.images.where((image) => image.id == screenshotId).first,
517+
mismatch: mismatch,
523518
),
524519
);
525520
}
@@ -548,8 +543,8 @@ class Gallery {
548543
}
549544

550545
final report = GoldenSceneReport(
551-
sceneDescription: _sceneDescription,
552-
metadata: goldenCollection.metadata,
546+
//sceneDescription: _sceneDescription,
547+
metadata: metadata,
553548
items: items,
554549
missingCandidates: missingCandidates,
555550
extraCandidates: extraCandidates,

lib/src/scenes/golden_scene.dart

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,12 @@ typedef GoldenSetup = FutureOr<void> Function(WidgetTester tester);
119119
/// the missing candidates and candidates that have no corresponding golden.
120120
class GoldenSceneReport {
121121
GoldenSceneReport({
122-
required this.sceneDescription,
123122
required this.metadata,
124123
required this.items,
125124
required this.missingCandidates,
126125
required this.extraCandidates,
127126
});
128127

129-
/// The human readable description of the scene.
130-
final String sceneDescription;
131-
132128
/// The metadata of the scene, such as the golden images and their positions.
133129
final GoldenSceneMetadata metadata;
134130

@@ -159,51 +155,38 @@ class GoldenReport {
159155
return GoldenReport(
160156
status: GoldenTestStatus.success,
161157
metadata: metadata,
162-
details: [],
163158
);
164159
}
165160

166161
factory GoldenReport.failure({
167162
required GoldenImageMetadata metadata,
168-
required List<GoldenCheckDetail> details,
163+
required GoldenMismatch mismatch,
169164
}) {
170165
return GoldenReport(
171166
status: GoldenTestStatus.failure,
172167
metadata: metadata,
173-
details: details,
168+
mismatch: mismatch,
174169
);
175170
}
176171

177172
GoldenReport({
178173
required this.status,
179174
required this.metadata,
180-
required this.details,
181-
});
175+
this.mismatch,
176+
}) : assert(
177+
status == GoldenTestStatus.success || mismatch != null,
178+
"A failure report must have a mismatch.",
179+
);
182180

183181
/// Whether the gallery item passed or failed the golden check.
184182
final GoldenTestStatus status;
185183

186184
/// The metadata of the candidate image of this report.
187185
final GoldenImageMetadata metadata;
188186

189-
/// The details of the golden check for this item.
187+
/// The failure details of the gallery item, if it failed the golden check.
190188
///
191-
/// Might contain both successful and failed checks.
192-
final List<GoldenCheckDetail> details;
193-
}
194-
195-
class GoldenCheckDetail {
196-
GoldenCheckDetail({
197-
required this.status,
198-
required this.description,
199-
this.mismatch,
200-
}) : assert(
201-
status != GoldenTestStatus.success || mismatch == null,
202-
"A successful golden test cannot have a mismatch",
203-
);
204-
205-
final GoldenTestStatus status;
206-
final String description;
189+
/// Non-`null` if [status] is [GoldenTestStatus.failure] and `null` otherwise.
207190
final GoldenMismatch? mismatch;
208191
}
209192

lib/src/scenes/golden_scene_report_printer.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GoldenSceneReportPrinter {
1212
final buffer = StringBuffer();
1313

1414
// Report the summary of passed/failed tests and missing/extra candidates.
15-
buffer.write("Golden scene has failures: ${report.sceneDescription} (");
15+
buffer.write("Golden scene has failures: ${report.metadata.description} (");
1616
buffer.write("✅ ${report.totalPassed}/${report.items.length}, ");
1717
buffer.write("❌ ${report.totalFailed}/${report.items.length}");
1818
if (report.missingCandidates.isNotEmpty || report.extraCandidates.isNotEmpty) {
@@ -40,11 +40,7 @@ class GoldenSceneReportPrinter {
4040
}
4141

4242
// This item has a failed check.
43-
final mismatch = item.details //
44-
.where((detail) => detail.mismatch != null)
45-
.firstOrNull
46-
?.mismatch;
47-
43+
final mismatch = item.mismatch;
4844
switch (mismatch) {
4945
case WrongSizeGoldenMismatch():
5046
buffer.writeln(

0 commit comments

Comments
 (0)