Skip to content

Commit d18f578

Browse files
authored
test: golden tests don't work with test optimisation flag (#419)
1 parent 9bfb159 commit d18f578

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

lib/src/commands/test/templates/test_runner_bundle.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/golden_test.png

20.5 KB
Loading

test/src/cli/flutter_cli_test.dart

+71
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ void main() {
6969
});
7070
}''';
7171

72+
const flutterGoldenTestContents = '''
73+
import 'package:flutter/material.dart';
74+
import 'package:flutter_test/flutter_test.dart';
75+
76+
void main() {
77+
testWidgets('test with golden', (tester) async {
78+
await tester.pumpWidget(
79+
MaterialApp(
80+
debugShowCheckedModeBanner: false,
81+
home: Scaffold(
82+
appBar: AppBar(),
83+
body: Center(child: ColoredBox(color: Colors.blue)),
84+
),
85+
),
86+
);
87+
88+
await expectLater(
89+
find.byType(MaterialApp),
90+
matchesGoldenFile('golden_test.png'),
91+
);
92+
});
93+
}
94+
''';
95+
7296
const longTestNameContents = '''
7397
import 'package:test/test.dart';
7498
@@ -210,6 +234,8 @@ dev_dependencies:
210234
class MockLogger extends Mock implements Logger {}
211235

212236
void main() {
237+
final cwd = Directory.current;
238+
213239
group('Flutter', () {
214240
group('.packagesGet', () {
215241
test('throws when there is no pubspec.yaml', () {
@@ -847,6 +873,51 @@ void main() {
847873
).called(1);
848874
});
849875

876+
test(
877+
'completes when there is a nested golden test w/optimizations Flutter (passing)',
878+
() async {
879+
final directory = Directory.systemTemp.createTempSync();
880+
final testDirectory = Directory(p.join(directory.path, 'test'))
881+
..createSync();
882+
final goldenTestDirectory =
883+
Directory(p.join(testDirectory.path, 'golden'))..createSync();
884+
File(
885+
p.join(directory.path, 'pubspec.yaml'),
886+
).writeAsStringSync(pubspecFlutter);
887+
File(
888+
p.join(goldenTestDirectory.path, 'golden_test.dart'),
889+
).writeAsStringSync(flutterGoldenTestContents);
890+
File(
891+
p.join(goldenTestDirectory.path, 'golden_test.png'),
892+
).writeAsBytesSync(
893+
File(p.join(cwd.path, 'test', 'fixtures', 'golden_test.png'))
894+
.readAsBytesSync(),
895+
);
896+
await expectLater(
897+
Flutter.test(
898+
cwd: directory.path,
899+
optimizePerformance: true,
900+
stdout: logger.write,
901+
stderr: logger.err,
902+
progress: logger.progress,
903+
),
904+
completion(equals([ExitCode.success.code])),
905+
);
906+
verify(() => logger.progress('Optimizing tests')).called(1);
907+
verify(
908+
() => logger.write(
909+
any(
910+
that: contains(
911+
'Running "flutter test" in ${p.dirname(directory.path)}',
912+
),
913+
),
914+
),
915+
).called(1);
916+
verify(
917+
() => logger.write(any(that: contains('+1: All tests passed!'))),
918+
).called(1);
919+
});
920+
850921
test('completes when there is a test directory (recursive)', () async {
851922
final directory = Directory.systemTemp.createTempSync();
852923
final nestedDirectory = Directory(p.join(directory.path, 'nested'))

0 commit comments

Comments
 (0)