Skip to content

Commit

Permalink
fix(test): flutter_test compatibility (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Mar 25, 2022
1 parent 5f28014 commit 844a599
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/src/commands/test/templates/test_runner_bundle.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 57 additions & 1 deletion test/src/cli/flutter_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ void main() {
});
}''';

const flutterTestContents = '''
import 'package:flutter_test/flutter_test.dart';
void main() {
test('example', () {
expect(true, isTrue);
});
}''';

const longTestNameContents = '''
import 'package:test/test.dart';
Expand Down Expand Up @@ -151,6 +160,15 @@ environment:
dev_dependencies:
test: any''';

const pubspecFlutter = '''
name: example
environment:
sdk: ">=2.13.0 <3.0.0"
dev_dependencies:
flutter_test:
sdk: flutter''';

const invalidPubspec = 'name: example';

class MockLogger extends Mock implements Logger {}
Expand Down Expand Up @@ -596,7 +614,8 @@ void main() {
).called(1);
});

test('completes when there is a test directory w/optimizations (passing)',
test(
'completes when there is a test directory w/optimizations Dart (passing)',
() async {
final directory = Directory.systemTemp.createTempSync();
final testDirectory = Directory(p.join(directory.path, 'test'))
Expand Down Expand Up @@ -630,6 +649,43 @@ void main() {
).called(1);
});

test(
'completes when there is a test directory w/optimizations Flutter (passing)',
() async {
final directory = Directory.systemTemp.createTempSync();
final testDirectory = Directory(p.join(directory.path, 'test'))
..createSync();
File(
p.join(directory.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecFlutter);
File(
p.join(testDirectory.path, 'example_test.dart'),
).writeAsStringSync(flutterTestContents);
await expectLater(
Flutter.test(
cwd: directory.path,
optimizePerformance: true,
stdout: logger.write,
stderr: logger.err,
progress: logger.progress,
),
completes,
);
verify(() => logger.progress('Optimizing tests')).called(1);
verify(
() => logger.write(
any(
that: contains(
'Running "flutter test" in ${p.dirname(directory.path)}',
),
),
),
).called(1);
verify(
() => logger.write(any(that: contains('+1: All tests passed!'))),
).called(1);
});

test('completes when there is a test directory (recursive)', () async {
final directory = Directory.systemTemp.createTempSync();
final nestedDirectory = Directory(p.join(directory.path, 'nested'))
Expand Down

0 comments on commit 844a599

Please sign in to comment.