Fix issues running integration tests through DAP debug adapter (#104618)

* Fix issues running integration tests through DAP

These adapters were incorrectly trying to connect a DDS instance even when Flutter would create its own. This change disables DDS in the DAP layer and leaves it to Flutter (although it passes `--no-dds` on to Flutter if provided to the DAP process).

Also fixes an issue where we would unnecessarily connect the VM Service for tests even in 'noDebug' mode because of a change/fix that now includes a 'vmServiceUri' in the `test.startedProcess` event.
This commit is contained in:
Danny Tuppeny
2022-05-26 09:36:30 +01:00
committed by GitHub
parent 2aa348b940
commit 147020366a
5 changed files with 170 additions and 45 deletions

View File

@@ -7,6 +7,7 @@ import 'package:file/file.dart';
import 'package:flutter_tools/src/cache.dart';
import '../../src/common.dart';
import '../test_data/integration_tests_project.dart';
import '../test_data/tests_project.dart';
import '../test_utils.dart';
import 'test_client.dart';
@@ -15,6 +16,8 @@ import 'test_support.dart';
void main() {
late Directory tempDir;
late DapTestSession dap;
late DapTestClient client;
late TestsProject project;
setUpAll(() {
Cache.flutterRoot = getFlutterRoot();
@@ -23,6 +26,7 @@ void main() {
setUp(() async {
tempDir = createResolvedTempDirectorySync('flutter_test_adapter_test.');
dap = await DapTestSession.setUp(additionalArgs: <String>['--test']);
client = dap.client;
});
tearDown(() async {
@@ -30,45 +34,40 @@ void main() {
tryToDelete(tempDir);
});
test('can run in debug mode', () async {
final DapTestClient client = dap.client;
final TestsProject project = TestsProject();
await project.setUpIn(tempDir);
void standardTests({List<String>? toolArgs}) {
test('can run in debug mode', () async {
// Collect output and test events while running the script.
final TestEvents outputEvents = await client.collectTestOutput(
launch: () => client.launch(
program: project.testFilePath,
cwd: project.dir.path,
toolArgs: toolArgs,
),
);
// Collect output and test events while running the script.
final TestEvents outputEvents = await client.collectTestOutput(
launch: () => client.launch(
program: project.testFilePath,
cwd: project.dir.path,
),
);
// Check the printed output shows that the run finished, and it's exit
// code (which is 1 due to the failing test).
final String output = outputEvents.output.map((OutputEventBody e) => e.output).join();
expectLines(
output,
<Object>[
startsWith('Connecting to VM Service at'),
..._testsProjectExpectedOutput,
],
allowExtras: true, // Allow for printed call stack etc.
);
// Check the printed output shows that the run finished, and it's exit
// code (which is 1 due to the failing test).
final String output = outputEvents.output.map((OutputEventBody e) => e.output).join();
expectLines(
output,
<Object>[
startsWith('Connecting to VM Service at'),
..._testsProjectExpectedOutput,
],
allowExtras: true, // Allow for printed call stack etc.
);
_expectStandardTestsProjectResults(outputEvents);
});
_expectStandardTestsProjectResults(outputEvents);
});
test('can run in noDebug mode', () async {
final DapTestClient client = dap.client;
final TestsProject project = TestsProject();
await project.setUpIn(tempDir);
// Collect output and test events while running the script.
final TestEvents outputEvents = await client.collectTestOutput(
launch: () => client.launch(
program: project.testFilePath,
noDebug: true,
cwd: project.dir.path,
toolArgs: toolArgs,
),
);
@@ -85,21 +84,18 @@ void main() {
});
test('can run a single test', () async {
final DapTestClient client = dap.client;
final TestsProject project = TestsProject();
await project.setUpIn(tempDir);
// Collect output and test events while running the script.
final TestEvents outputEvents = await client.collectTestOutput(
launch: () => client.launch(
program: project.testFilePath,
noDebug: true,
cwd: project.dir.path,
// It's up to the calling IDE to pass the correct args for 'dart test'
// if it wants to run a subset of tests.
args: <String>[
// It's up to the calling IDE to pass the correct args for
// 'flutter test' if it wants to run a subset of tests.
toolArgs: <String>[
'--plain-name',
'can pass',
...?toolArgs,
],
),
);
@@ -112,6 +108,27 @@ void main() {
expect(testsNames, contains('Flutter tests can pass'));
expect(testsNames, isNot(contains('Flutter tests can fail')));
});
}
group('widget tests', () {
setUp(() async {
project = TestsProject();
await project.setUpIn(tempDir);
});
standardTests();
});
group('integration tests', () {
const List<String> toolArgs = <String>['-d', 'flutter-tester'];
setUp(() async {
project = IntegrationTestsProject();
await project.setUpIn(tempDir);
});
standardTests(toolArgs: toolArgs);
});
}
/// Matchers for the expected console output of [TestsProject].
@@ -137,8 +154,9 @@ final List<Object> _testsProjectExpectedOutput = <Object>[
void _expectStandardTestsProjectResults(TestEvents events) {
// Check we received all expected test events passed through from
// package:test.
final List<Object> eventNames =
events.testNotifications.map((Map<String, Object?> e) => e['type']!).toList();
final List<Object> eventNames = events.testNotifications
.map((Map<String, Object?> e) => e['type']!)
.toList();
// start/done should always be first/last.
expect(eventNames.first, equals('start'));

View File

@@ -36,6 +36,7 @@ class InProcessDapTestServer extends DapTestServer {
// Simulate flags based on the args to aid testing.
enableDds: !args.contains('--no-dds'),
ipv6: args.contains('--ipv6'),
test: args.contains('--test'),
);
}

View File

@@ -0,0 +1,68 @@
// 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:flutter_tools/src/base/file_system.dart';
import '../test_utils.dart';
import 'project.dart';
import 'tests_project.dart';
class IntegrationTestsProject extends Project implements TestsProject {
@override
final String pubspec = '''
name: test
environment:
sdk: '>=2.12.0-0 <3.0.0'
dependencies:
flutter:
sdk: flutter
dev_dependencies:
integration_test:
sdk: flutter
flutter_test:
sdk: flutter
''';
@override
String get main => '// Unused';
@override
final String testContent = r'''
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
void main() {
group('Flutter tests', () {
testWidgets('can pass', (WidgetTester tester) async {
expect(true, isTrue); // BREAKPOINT
});
testWidgets('can fail', (WidgetTester tester) async {
expect(true, isFalse);
});
});
}
''';
@override
Future<void> setUpIn(Directory dir) {
this.dir = dir;
writeFile(testFilePath, testContent);
return super.setUpIn(dir);
}
@override
String get testFilePath => fileSystem.path.join(dir.path, 'integration_test', 'app_test.dart');
@override
Uri get breakpointUri => throw UnimplementedError();
@override
Uri get breakpointAppUri => throw UnimplementedError();
@override
int get breakpointLine => throw UnimplementedError();
}