Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/src/commands/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class TestCommand extends Command<int> {
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 '
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
],
Expand Down
21 changes: 20 additions & 1 deletion test/src/commands/test/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +91,7 @@ void main() {
stderr: any(named: 'stderr'),
),
).thenAnswer((_) async => [0]);
when<dynamic>(() => argResults['concurrency']).thenReturn(concurrency);
when<dynamic>(() => argResults['recursive']).thenReturn(false);
when<dynamic>(() => argResults['coverage']).thenReturn(false);
when<dynamic>(() => argResults['update-goldens']).thenReturn(false);
Expand Down Expand Up @@ -189,6 +193,21 @@ void main() {
).called(1);
});

test('completes normally --concurrency 1', () async {
when<dynamic>(() => 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<dynamic>(() => argResults['optimization']).thenReturn(false);
final result = await testCommand.run();
Expand Down