Skip to content

Commit a84e369

Browse files
authored
Revert "Allow Flutter golden file tests to be flaky (#114450)" (#114902)
This reverts commit 53e6876.
1 parent a1432a9 commit a84e369

35 files changed

+1351
-2093
lines changed

dev/automated_tests/flutter_test/flutter_gold_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'dart:typed_data';
88

99
import 'package:file/file.dart';
1010
import 'package:file/memory.dart';
11-
import 'package:flutter_goldens/src/flutter_goldens_io.dart';
11+
import 'package:flutter_goldens/flutter_goldens.dart';
1212
import 'package:flutter_test/flutter_test.dart';
1313
import 'package:platform/platform.dart';
1414

dev/bots/analyze.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches
418418
}
419419
}
420420

421-
final RegExp _findGoldenTestPattern = RegExp(r'(matchesGoldenFile|expectFlakyGolden)\(');
422-
final RegExp _findGoldenDefinitionPattern = RegExp(r'(matchesGoldenFile|expectFlakyGolden)\(Object');
421+
final RegExp _findGoldenTestPattern = RegExp(r'matchesGoldenFile\(');
422+
final RegExp _findGoldenDefinitionPattern = RegExp(r'matchesGoldenFile\(Object');
423423
final RegExp _leadingComment = RegExp(r'//');
424424
final RegExp _goldenTagPattern1 = RegExp(r'@Tags\(');
425425
final RegExp _goldenTagPattern2 = RegExp(r"'reduced-test-set'");
@@ -431,17 +431,8 @@ const String _ignoreGoldenTag = '// flutter_ignore: golden_tag (see analyze.dart
431431
const String _ignoreGoldenTagForFile = '// flutter_ignore_for_file: golden_tag (see analyze.dart)';
432432

433433
Future<void> verifyGoldenTags(String workingDirectory, { int minimumMatches = 2000 }) async {
434-
// Skip flutter_goldens/lib because this library uses `matchesGoldenFile`
435-
// but is not itself a test that needs tags.
436-
final String flutterGoldensPackageLib = path.join(flutterPackages, 'flutter_goldens', 'lib');
437-
bool isWithinFlutterGoldenLib(File file) {
438-
return path.isWithin(flutterGoldensPackageLib, file.path);
439-
}
440-
441434
final List<String> errors = <String>[];
442-
final Stream<File> allTestFiles = _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)
443-
.where((File file) => !isWithinFlutterGoldenLib(file));
444-
await for (final File file in allTestFiles) {
435+
await for (final File file in _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)) {
445436
bool needsTag = false;
446437
bool hasTagNotation = false;
447438
bool hasReducedTag = false;

dev/bots/test/analyze-test-input/root/packages/foo/flaky_golden_ignore.dart

Lines changed: 0 additions & 16 deletions
This file was deleted.

dev/bots/test/analyze-test-input/root/packages/foo/flaky_golden_missing_tag.dart

Lines changed: 0 additions & 14 deletions
This file was deleted.

dev/bots/test/analyze-test-input/root/packages/foo/golden_class.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@
77
void matchesGoldenFile(Object key) {
88
return;
99
}
10-
11-
void expectFlakyGolden(Object key, String string){
12-
return;
13-
}

dev/bots/test/analyze-test-input/root/packages/foo/golden_doc.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@
3535
/// ```
3636
/// {@end-tool}
3737
///
38-
/// expectFlakyGolden(a, b)
3938
4039
// Other comments
4140
// matchesGoldenFile('comment.png');
42-
// expectFlakyGolden(a, b);
4341

4442
String literal = 'matchesGoldenFile()'; // flutter_ignore: golden_tag (see analyze.dart)
45-
String flakyLiteral = 'expectFlakyGolden';

dev/bots/test/analyze_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ void main() {
7979
'at the top of the file before import statements.';
8080
const String missingTag = "Files containing golden tests must be tagged with 'reduced-test-set'.";
8181
final List<String> lines = <String>[
82-
'║ test/analyze-test-input/root/packages/foo/flaky_golden_no_tag.dart: $noTag',
8382
'║ test/analyze-test-input/root/packages/foo/golden_missing_tag.dart: $missingTag',
84-
'║ test/analyze-test-input/root/packages/foo/flaky_golden_missing_tag.dart: $missingTag',
8583
'║ test/analyze-test-input/root/packages/foo/golden_no_tag.dart: $noTag',
8684
]
8785
.map((String line) => line.replaceAll('/', Platform.isWindows ? r'\' : '/'))

dev/devicelab/bin/tasks/technical_debt__cost.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const double todoCost = 1009.0; // about two average SWE days, in dollars
1717
const double ignoreCost = 2003.0; // four average SWE days, in dollars
1818
const double pythonCost = 3001.0; // six average SWE days, in dollars
1919
const double skipCost = 2473.0; // 20 hours: 5 to fix the issue we're ignoring, 15 to fix the bugs we missed because the test was off
20-
const double flakyGoldenCost = 2467.0; // Similar to skip cost
2120
const double ignoreForFileCost = 2477.0; // similar thinking as skipCost
2221
const double asDynamicCost = 2011.0; // a few days to refactor the code.
2322
const double deprecationCost = 233.0; // a few hours to remove the old code.
@@ -70,9 +69,6 @@ Future<double> findCostsForFile(File file) async {
7069
if (isTest && line.contains('skip:') && !line.contains('[intended]')) {
7170
total += skipCost;
7271
}
73-
if (isTest && line.contains('expectFlakyGolden(')) {
74-
total += flakyGoldenCost;
75-
}
7672
if (isDart && isOptingOutOfNullSafety(line)) {
7773
total += fileNullSafetyMigrationCost;
7874
}

examples/api/test/flutter_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'dart:async';
66

77

8-
import 'package:flutter_goldens/flutter_goldens.dart' as flutter_goldens;
8+
import 'goldens_io.dart' if (dart.library.html) 'goldens_web.dart' as flutter_goldens;
99

1010
Future<void> testExecutable(FutureOr<void> Function() testMain) {
1111
// Enable golden file testing using Skia Gold.
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,4 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// The tag is missing. This should fail analysis.
6-
7-
import 'golden_class.dart';
8-
9-
void main() {
10-
expectFlakyGolden('key', 'missing_tag.png');
11-
}
5+
export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable;

examples/api/test/goldens_web.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
// package:flutter_goldens is not used as part of the test process for web.
8+
Future<void> testExecutable(FutureOr<void> Function() testMain) async => testMain();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
// package:flutter_goldens is not used as part of the test process for web.
8+
Future<void> testExecutable(FutureOr<void> Function() testMain) async => testMain();

packages/flutter/test/cupertino/date_picker_test.dart

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ import 'dart:ui';
1717
import 'package:flutter/cupertino.dart';
1818
import 'package:flutter/material.dart';
1919
import 'package:flutter/rendering.dart';
20-
import 'package:flutter_goldens/flutter_goldens.dart' show expectFlakyGolden;
2120
import 'package:flutter_test/flutter_test.dart';
2221

2322
// TODO(yjbanov): on the web text rendered with perspective produces flaky goldens: https://github.com/flutter/flutter/issues/110785
24-
const bool perspectiveTestIsFlaky = isBrowser;
23+
const bool skipPerspectiveTextGoldens = isBrowser;
2524

2625
// A number of the hit tests below say "warnIfMissed: false". This is because
2726
// the way the CupertinoPicker works, the hits don't actually reach the labels,
@@ -1198,41 +1197,23 @@ void main() {
11981197
}
11991198

12001199
await tester.pumpWidget(buildApp(CupertinoDatePickerMode.time));
1201-
1202-
if (perspectiveTestIsFlaky) {
1203-
await expectFlakyGolden(
1204-
find.byType(CupertinoDatePicker),
1205-
'date_picker_test.time.initial.png',
1206-
);
1207-
} else {
1200+
if (!skipPerspectiveTextGoldens) {
12081201
await expectLater(
12091202
find.byType(CupertinoDatePicker),
12101203
matchesGoldenFile('date_picker_test.time.initial.png'),
12111204
);
12121205
}
12131206

12141207
await tester.pumpWidget(buildApp(CupertinoDatePickerMode.date));
1215-
1216-
if (perspectiveTestIsFlaky) {
1217-
await expectFlakyGolden(
1218-
find.byType(CupertinoDatePicker),
1219-
'date_picker_test.date.initial.png',
1220-
);
1221-
} else {
1208+
if (!skipPerspectiveTextGoldens) {
12221209
await expectLater(
12231210
find.byType(CupertinoDatePicker),
12241211
matchesGoldenFile('date_picker_test.date.initial.png'),
12251212
);
12261213
}
12271214

12281215
await tester.pumpWidget(buildApp(CupertinoDatePickerMode.dateAndTime));
1229-
1230-
if (perspectiveTestIsFlaky) {
1231-
await expectFlakyGolden(
1232-
find.byType(CupertinoDatePicker),
1233-
'date_picker_test.datetime.initial.png',
1234-
);
1235-
} else {
1216+
if (!skipPerspectiveTextGoldens) {
12361217
await expectLater(
12371218
find.byType(CupertinoDatePicker),
12381219
matchesGoldenFile('date_picker_test.datetime.initial.png'),
@@ -1243,12 +1224,7 @@ void main() {
12431224
await tester.drag(find.text('4'), Offset(0, _kRowOffset.dy / 2), warnIfMissed: false); // see top of file
12441225
await tester.pump();
12451226

1246-
if (perspectiveTestIsFlaky) {
1247-
await expectFlakyGolden(
1248-
find.byType(CupertinoDatePicker),
1249-
'date_picker_test.datetime.drag.png',
1250-
);
1251-
} else {
1227+
if (!skipPerspectiveTextGoldens) {
12521228
await expectLater(
12531229
find.byType(CupertinoDatePicker),
12541230
matchesGoldenFile('date_picker_test.datetime.drag.png'),
@@ -1338,12 +1314,7 @@ void main() {
13381314
),
13391315
);
13401316

1341-
if (perspectiveTestIsFlaky) {
1342-
await expectFlakyGolden(
1343-
find.byType(CupertinoTimerPicker),
1344-
'timer_picker_test.datetime.initial.png',
1345-
);
1346-
} else {
1317+
if (!skipPerspectiveTextGoldens) {
13471318
await expectLater(
13481319
find.byType(CupertinoTimerPicker),
13491320
matchesGoldenFile('timer_picker_test.datetime.initial.png'),
@@ -1354,12 +1325,7 @@ void main() {
13541325
await tester.drag(find.text('59'), Offset(0, _kRowOffset.dy / 2), warnIfMissed: false); // see top of file
13551326
await tester.pump();
13561327

1357-
if (perspectiveTestIsFlaky) {
1358-
await expectFlakyGolden(
1359-
find.byType(CupertinoTimerPicker),
1360-
'timer_picker_test.datetime.drag.png',
1361-
);
1362-
} else {
1328+
if (!skipPerspectiveTextGoldens) {
13631329
await expectLater(
13641330
find.byType(CupertinoTimerPicker),
13651331
matchesGoldenFile('timer_picker_test.datetime.drag.png'),

packages/flutter/test/flutter_test_config.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import 'dart:async';
66

77
import 'package:flutter/rendering.dart';
8-
import 'package:flutter_goldens/flutter_goldens.dart' as flutter_goldens;
98
import 'package:flutter_test/flutter_test.dart';
109

10+
import '_goldens_io.dart'
11+
if (dart.library.html) '_goldens_web.dart' as flutter_goldens;
12+
1113
Future<void> testExecutable(FutureOr<void> Function() testMain) {
1214
// Enable checks because there are many implementations of [RenderBox] in this
1315
// package can benefit from the additional validations.
@@ -20,7 +22,3 @@ Future<void> testExecutable(FutureOr<void> Function() testMain) {
2022
// Enable golden file testing using Skia Gold.
2123
return flutter_goldens.testExecutable(testMain);
2224
}
23-
24-
Future<void> processBrowserCommand(dynamic command) {
25-
return flutter_goldens.processBrowserCommand(command);
26-
}

packages/flutter/test/flutter_web_test_config.dart

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)