Skip to content

Commit 6483d0a

Browse files
authored
feat(test): add --update-goldens (#341)
1 parent edcd171 commit 6483d0a

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Usage: very_good test [arguments]
170170
-x, --exclude-tags Run only tests that do not have the specified tags.
171171
--min-coverage Whether to enforce a minimum coverage percentage.
172172
--test-randomize-ordering-seed The seed to randomize the execution order of test cases within test files.
173+
--update-goldens Whether "matchesGoldenFile()" calls within your test methods should update the golden files.
173174

174175
Run "very_good help" to see global options.
175176
```

lib/src/commands/test/test.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class TestCommand extends Command<int> {
7373
'test-randomize-ordering-seed',
7474
help: 'The seed to randomize the execution order of test cases '
7575
'within test files.',
76+
)
77+
..addFlag(
78+
'update-goldens',
79+
help: 'Whether "matchesGoldenFile()" calls within your test methods '
80+
'should update the golden files.',
81+
negatable: false,
7682
);
7783
}
7884

@@ -120,11 +126,13 @@ This command should be run from the root of your Flutter project.''',
120126
? Random().nextInt(4294967295).toString()
121127
: randomOrderingSeed;
122128
final optimizePerformance = _argResults['optimization'] as bool;
129+
final updateGoldens = _argResults['update-goldens'] as bool;
123130

124131
if (isFlutterInstalled) {
125132
try {
126133
await _flutterTest(
127-
optimizePerformance: optimizePerformance && _argResults.rest.isEmpty,
134+
optimizePerformance:
135+
optimizePerformance && _argResults.rest.isEmpty && !updateGoldens,
128136
recursive: recursive,
129137
progress: _logger.progress,
130138
stdout: _logger.write,
@@ -135,6 +143,7 @@ This command should be run from the root of your Flutter project.''',
135143
randomSeed: randomSeed,
136144
arguments: [
137145
if (excludeTags != null) ...['-x', excludeTags],
146+
if (updateGoldens) '--update-goldens',
138147
'--no-pub',
139148
..._argResults.rest,
140149
],

test/src/commands/test/test_test.dart

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const expectedTestUsage = [
2323
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
2424
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
2525
''' --test-randomize-ordering-seed The seed to randomize the execution order of test cases within test files.\n'''
26+
''' --update-goldens Whether "matchesGoldenFile()" calls within your test methods should update the golden files.\n'''
2627
'\n'
2728
'Run "very_good help" to see global options.'
2829
];
@@ -89,6 +90,7 @@ void main() {
8990
).thenAnswer((_) async {});
9091
when<dynamic>(() => argResults['recursive']).thenReturn(false);
9192
when<dynamic>(() => argResults['coverage']).thenReturn(false);
93+
when<dynamic>(() => argResults['update-goldens']).thenReturn(false);
9294
when<dynamic>(() => argResults['optimization']).thenReturn(true);
9395
when(() => argResults.rest).thenReturn([]);
9496
});
@@ -180,6 +182,20 @@ void main() {
180182
).called(1);
181183
});
182184

185+
test('completes normally --update-goldens', () async {
186+
when<dynamic>(() => argResults['update-goldens']).thenReturn(true);
187+
final result = await testCommand.run();
188+
expect(result, equals(ExitCode.success.code));
189+
verify(
190+
() => flutterTest(
191+
arguments: ['--update-goldens', ...defaultArguments],
192+
progress: logger.progress,
193+
stdout: logger.write,
194+
stderr: logger.err,
195+
),
196+
).called(1);
197+
});
198+
183199
test('completes normally --test-randomize-ordering-seed random', () async {
184200
when<dynamic>(
185201
() => argResults['test-randomize-ordering-seed'],

0 commit comments

Comments
 (0)