Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): flutter_test compatibility #337

Merged
merged 1 commit into from
Mar 25, 2022
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
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