Skip to content

Commit 42697e4

Browse files
authored
feat(test): support --concurrency option (#416)
1 parent 1523dcb commit 42697e4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/src/commands/test/test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class TestCommand extends Command<int> {
5555
defaultsTo: true,
5656
help: 'Whether to apply optimizations for test performance.',
5757
)
58+
..addOption(
59+
'concurrency',
60+
abbr: 'j',
61+
defaultsTo: '4',
62+
help: 'The number of concurrent test suites run.',
63+
)
5864
..addOption(
5965
'exclude-coverage',
6066
help: 'A glob which will be used to exclude files that match from the '
@@ -112,6 +118,7 @@ This command should be run from the root of your Flutter project.''',
112118
return ExitCode.noInput.code;
113119
}
114120

121+
final concurrency = _argResults['concurrency'] as String;
115122
final recursive = _argResults['recursive'] as bool;
116123
final collectCoverage = _argResults['coverage'] as bool;
117124
final minCoverage = double.tryParse(
@@ -144,6 +151,7 @@ This command should be run from the root of your Flutter project.''',
144151
arguments: [
145152
if (excludeTags != null) ...['-x', excludeTags],
146153
if (updateGoldens) '--update-goldens',
154+
...['-j', concurrency],
147155
'--no-pub',
148156
..._argResults.rest,
149157
],

test/src/commands/test/test_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const expectedTestUsage = [
1919
'''-r, --recursive Run tests recursively for all nested packages.\n'''
2020
''' --[no-]optimization Whether to apply optimizations for test performance.\n'''
2121
' (defaults to on)\n'
22+
'''-j, --concurrency The number of concurrent test suites run.\n'''
23+
' (defaults to "4")\n'
2224
''' --exclude-coverage A glob which will be used to exclude files that match from the coverage.\n'''
2325
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
2426
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
@@ -54,7 +56,8 @@ class MockFlutterTestCommand extends Mock implements FlutterTestCommand {}
5456
void main() {
5557
group('test', () {
5658
final cwd = Directory.current;
57-
const defaultArguments = ['--no-pub'];
59+
const concurrency = '4';
60+
const defaultArguments = ['-j', concurrency, '--no-pub'];
5861

5962
late Logger logger;
6063
late bool isFlutterInstalled;
@@ -88,6 +91,7 @@ void main() {
8891
stderr: any(named: 'stderr'),
8992
),
9093
).thenAnswer((_) async => [0]);
94+
when<dynamic>(() => argResults['concurrency']).thenReturn(concurrency);
9195
when<dynamic>(() => argResults['recursive']).thenReturn(false);
9296
when<dynamic>(() => argResults['coverage']).thenReturn(false);
9397
when<dynamic>(() => argResults['update-goldens']).thenReturn(false);
@@ -189,6 +193,21 @@ void main() {
189193
).called(1);
190194
});
191195

196+
test('completes normally --concurrency 1', () async {
197+
when<dynamic>(() => argResults['concurrency']).thenReturn('1');
198+
final result = await testCommand.run();
199+
expect(result, equals(ExitCode.success.code));
200+
verify(
201+
() => flutterTest(
202+
arguments: ['-j', '1', '--no-pub'],
203+
optimizePerformance: true,
204+
progress: logger.progress,
205+
stdout: logger.write,
206+
stderr: logger.err,
207+
),
208+
).called(1);
209+
});
210+
192211
test('completes normally --no-optimization', () async {
193212
when<dynamic>(() => argResults['optimization']).thenReturn(false);
194213
final result = await testCommand.run();

0 commit comments

Comments
 (0)