[flutter_tools] support machine and coverage together but for real (#54692)
This commit is contained in:
parent
8ed40ddd4b
commit
9cc69d47a5
@ -177,6 +177,12 @@ class CoverageCollector extends TestWatcher {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> handleTestCrashed(ProcessEvent event) async { }
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> handleTestTimedOut(ProcessEvent event) async { }
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<VMService> _defaultConnect(Uri serviceUri) {
|
Future<VMService> _defaultConnect(Uri serviceUri) {
|
||||||
|
@ -22,6 +22,21 @@ class EventPrinter extends TestWatcher {
|
|||||||
_parent?.handleStartedProcess(event);
|
_parent?.handleStartedProcess(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> handleTestCrashed(ProcessEvent event) async {
|
||||||
|
return _parent.handleTestCrashed(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> handleTestTimedOut(ProcessEvent event) async {
|
||||||
|
return _parent.handleTestTimedOut(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> handleFinishedTest(ProcessEvent event) async {
|
||||||
|
return _parent.handleFinishedTest(event);
|
||||||
|
}
|
||||||
|
|
||||||
void _sendEvent(String name, [ dynamic params ]) {
|
void _sendEvent(String name, [ dynamic params ]) {
|
||||||
final Map<String, dynamic> map = <String, dynamic>{'event': name};
|
final Map<String, dynamic> map = <String, dynamic>{'event': name};
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
|
@ -17,14 +17,14 @@ abstract class TestWatcher {
|
|||||||
///
|
///
|
||||||
/// The child process won't exit until this method completes.
|
/// The child process won't exit until this method completes.
|
||||||
/// Not called if the process died.
|
/// Not called if the process died.
|
||||||
Future<void> handleFinishedTest(ProcessEvent event) async { }
|
Future<void> handleFinishedTest(ProcessEvent event);
|
||||||
|
|
||||||
/// Called when the test process crashed before connecting to test harness.
|
/// Called when the test process crashed before connecting to test harness.
|
||||||
Future<void> handleTestCrashed(ProcessEvent event) async { }
|
Future<void> handleTestCrashed(ProcessEvent event);
|
||||||
|
|
||||||
/// Called if we timed out waiting for the test process to connect to test
|
/// Called if we timed out waiting for the test process to connect to test
|
||||||
/// harness.
|
/// harness.
|
||||||
Future<void> handleTestTimedOut(ProcessEvent event) async { }
|
Future<void> handleTestTimedOut(ProcessEvent event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes a child process started during testing.
|
/// Describes a child process started during testing.
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:file/file.dart';
|
||||||
|
import 'package:file_testing/file_testing.dart';
|
||||||
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
|
|
||||||
|
import '../src/common.dart';
|
||||||
|
|
||||||
|
import 'test_data/test_project.dart';
|
||||||
|
import 'test_driver.dart';
|
||||||
|
import 'test_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Directory tempDir;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
tempDir = createResolvedTempDirectorySync('flutter_coverage_collection_test.');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
tryToDelete(tempDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Can collect coverage in machine mode', () async {
|
||||||
|
final TestProject project = TestProject();
|
||||||
|
await project.setUpIn(tempDir);
|
||||||
|
final FlutterTestTestDriver flutter = FlutterTestTestDriver(tempDir);
|
||||||
|
await flutter.test(coverage: true);
|
||||||
|
await flutter.done;
|
||||||
|
|
||||||
|
expect(tempDir.childDirectory('coverage').childFile('lcov.info'), exists);
|
||||||
|
});
|
||||||
|
}
|
@ -26,6 +26,7 @@ abstract class Project {
|
|||||||
|
|
||||||
String get pubspec;
|
String get pubspec;
|
||||||
String get main;
|
String get main;
|
||||||
|
String get test => null;
|
||||||
|
|
||||||
Uri get mainDart => Uri.parse('package:test/main.dart');
|
Uri get mainDart => Uri.parse('package:test/main.dart');
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ abstract class Project {
|
|||||||
if (main != null) {
|
if (main != null) {
|
||||||
writeFile(globals.fs.path.join(dir.path, 'lib', 'main.dart'), main);
|
writeFile(globals.fs.path.join(dir.path, 'lib', 'main.dart'), main);
|
||||||
}
|
}
|
||||||
|
if (test != null) {
|
||||||
|
writeFile(globals.fs.path.join(dir.path, 'test', 'test.dart'), test);
|
||||||
|
}
|
||||||
writeFile(globals.fs.path.join(dir.path, 'web', 'index.html'), _kDefaultHtml);
|
writeFile(globals.fs.path.join(dir.path, 'web', 'index.html'), _kDefaultHtml);
|
||||||
await getPackages(dir.path);
|
await getPackages(dir.path);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'project.dart';
|
||||||
|
|
||||||
|
class TestProject extends Project {
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String pubspec = '''
|
||||||
|
name: test
|
||||||
|
environment:
|
||||||
|
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String main = r'''
|
||||||
|
int foo(int bar) {
|
||||||
|
return bar + 2;
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String test = r'''
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:test/main.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('it can test', (WidgetTester tester) async {
|
||||||
|
expect(foo(2), 4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
}
|
@ -126,6 +126,8 @@ abstract class FlutterTestDriver {
|
|||||||
_stderr.stream.listen((String message) => _debugPrint(message, topic: '<=stderr='));
|
_stderr.stream.listen((String message) => _debugPrint(message, topic: '<=stderr='));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> get done => _process.exitCode;
|
||||||
|
|
||||||
Future<void> connectToVmService({ bool pauseOnExceptions = false }) async {
|
Future<void> connectToVmService({ bool pauseOnExceptions = false }) async {
|
||||||
_vmService = await vmServiceConnectUri('$_vmServiceWsUri');
|
_vmService = await vmServiceConnectUri('$_vmServiceWsUri');
|
||||||
_vmService.onSend.listen((String s) => _debugPrint(s, topic: '=vm=>'));
|
_vmService.onSend.listen((String s) => _debugPrint(s, topic: '=vm=>'));
|
||||||
@ -680,6 +682,7 @@ class FlutterTestTestDriver extends FlutterTestDriver {
|
|||||||
String testFile = 'test/test.dart',
|
String testFile = 'test/test.dart',
|
||||||
bool withDebugger = false,
|
bool withDebugger = false,
|
||||||
bool pauseOnExceptions = false,
|
bool pauseOnExceptions = false,
|
||||||
|
bool coverage = false,
|
||||||
File pidFile,
|
File pidFile,
|
||||||
Future<void> Function() beforeStart,
|
Future<void> Function() beforeStart,
|
||||||
}) async {
|
}) async {
|
||||||
@ -687,6 +690,8 @@ class FlutterTestTestDriver extends FlutterTestDriver {
|
|||||||
'test',
|
'test',
|
||||||
'--disable-service-auth-codes',
|
'--disable-service-auth-codes',
|
||||||
'--machine',
|
'--machine',
|
||||||
|
if (coverage)
|
||||||
|
'--coverage',
|
||||||
], script: testFile, withDebugger: withDebugger, pauseOnExceptions: pauseOnExceptions, pidFile: pidFile, beforeStart: beforeStart);
|
], script: testFile, withDebugger: withDebugger, pauseOnExceptions: pauseOnExceptions, pidFile: pidFile, beforeStart: beforeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user