diff --git a/lib/src/commands/test/test.dart b/lib/src/commands/test/test.dart index 373b8bba..e2a8cfe1 100644 --- a/lib/src/commands/test/test.dart +++ b/lib/src/commands/test/test.dart @@ -55,6 +55,12 @@ class TestCommand extends Command { defaultsTo: true, help: 'Whether to apply optimizations for test performance.', ) + ..addOption( + 'concurrency', + abbr: 'j', + defaultsTo: '4', + help: 'The number of concurrent test suites run.', + ) ..addOption( 'exclude-coverage', 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.''', return ExitCode.noInput.code; } + final concurrency = _argResults['concurrency'] as String; final recursive = _argResults['recursive'] as bool; final collectCoverage = _argResults['coverage'] as bool; final minCoverage = double.tryParse( @@ -144,6 +151,7 @@ This command should be run from the root of your Flutter project.''', arguments: [ if (excludeTags != null) ...['-x', excludeTags], if (updateGoldens) '--update-goldens', + ...['-j', concurrency], '--no-pub', ..._argResults.rest, ], diff --git a/test/src/commands/test/test_test.dart b/test/src/commands/test/test_test.dart index 14351d36..c42ba9c1 100644 --- a/test/src/commands/test/test_test.dart +++ b/test/src/commands/test/test_test.dart @@ -19,6 +19,8 @@ const expectedTestUsage = [ '''-r, --recursive Run tests recursively for all nested packages.\n''' ''' --[no-]optimization Whether to apply optimizations for test performance.\n''' ' (defaults to on)\n' + '''-j, --concurrency The number of concurrent test suites run.\n''' + ' (defaults to "4")\n' ''' --exclude-coverage A glob which will be used to exclude files that match from the coverage.\n''' '''-x, --exclude-tags Run only tests that do not have the specified tags.\n''' ''' --min-coverage Whether to enforce a minimum coverage percentage.\n''' @@ -54,7 +56,8 @@ class MockFlutterTestCommand extends Mock implements FlutterTestCommand {} void main() { group('test', () { final cwd = Directory.current; - const defaultArguments = ['--no-pub']; + const concurrency = '4'; + const defaultArguments = ['-j', concurrency, '--no-pub']; late Logger logger; late bool isFlutterInstalled; @@ -88,6 +91,7 @@ void main() { stderr: any(named: 'stderr'), ), ).thenAnswer((_) async => [0]); + when(() => argResults['concurrency']).thenReturn(concurrency); when(() => argResults['recursive']).thenReturn(false); when(() => argResults['coverage']).thenReturn(false); when(() => argResults['update-goldens']).thenReturn(false); @@ -189,6 +193,21 @@ void main() { ).called(1); }); + test('completes normally --concurrency 1', () async { + when(() => argResults['concurrency']).thenReturn('1'); + final result = await testCommand.run(); + expect(result, equals(ExitCode.success.code)); + verify( + () => flutterTest( + arguments: ['-j', '1', '--no-pub'], + optimizePerformance: true, + progress: logger.progress, + stdout: logger.write, + stderr: logger.err, + ), + ).called(1); + }); + test('completes normally --no-optimization', () async { when(() => argResults['optimization']).thenReturn(false); final result = await testCommand.run();