Skip to content

Commit 9b4159c

Browse files
author
Jonah Williams
authored
[flutter_tools] support run -d chrome test scripts (flutter#51658)
1 parent 266742e commit 9b4159c

File tree

8 files changed

+49
-6
lines changed

8 files changed

+49
-6
lines changed

dev/bots/test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ Future<void> _runWebUnitTests() async {
590590
Future<void> _runWebIntegrationTests() async {
591591
await _runWebStackTraceTest('profile');
592592
await _runWebStackTraceTest('release');
593-
await _runWebDebugStackTraceTest();
593+
await _runWebDebugTest('lib/stack_trace.dart');
594+
await _runWebDebugTest('test/test.dart');
594595
}
595596

596597
Future<void> _runWebStackTraceTest(String buildMode) async {
@@ -636,7 +637,7 @@ Future<void> _runWebStackTraceTest(String buildMode) async {
636637
/// Debug mode is special because `flutter build web` doesn't build in debug mode.
637638
///
638639
/// Instead, we use `flutter run --debug` and sniff out the standard output.
639-
Future<void> _runWebDebugStackTraceTest() async {
640+
Future<void> _runWebDebugTest(String target) async {
640641
final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web');
641642
final CapturedOutput output = CapturedOutput();
642643
bool success = false;
@@ -648,7 +649,8 @@ Future<void> _runWebDebugStackTraceTest() async {
648649
'-d',
649650
'chrome',
650651
'--web-run-headless',
651-
'lib/stack_trace.dart',
652+
'-t',
653+
target,
652654
],
653655
output: output,
654656
outputMode: OutputMode.capture,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
const String message = 'a';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
const String message = 'b';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
const String message = 'c';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
const String message = 'd';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:web_integration/a.dart'
6+
if (dart.library.io) 'package:web_integration/b.dart' as message1;
7+
import 'package:web_integration/c.dart'
8+
if (dart.library.html) 'package:web_integration/d.dart' as message2;
9+
10+
void main() {
11+
if (message1.message == 'a' && message2.message == 'd') {
12+
print('--- TEST SUCCEEDED ---');
13+
} else {
14+
print('--- TEST FAILED ---');
15+
}
16+
}

packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,13 @@ class _ResidentWebRunner extends ResidentWebRunner {
573573
.childFile('generated_plugin_registrant.dart')
574574
.absolute.path;
575575
final Uri generatedImport = packageUriMapper.map(generatedPath);
576-
final String importedEntrypoint = packageUriMapper.map(main).toString() ?? 'file://$main';
576+
String importedEntrypoint = packageUriMapper.map(main)?.toString();
577+
// Special handling for entrypoints that are not under lib, such as test scripts.
578+
if (importedEntrypoint == null) {
579+
final String parent = globals.fs.file(main).parent.path;
580+
flutterDevices.first.generator.addFileSystemRoot(parent);
581+
importedEntrypoint = 'org-dartlang-app:///${globals.fs.path.basename(main)}';
582+
}
577583

578584
final String entrypoint = <String>[
579585
'import "$importedEntrypoint" as entrypoint;',

packages/flutter_tools/test/general.shard/resident_web_runner_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,8 @@ void main() {
427427
Usage: () => MockFlutterUsage(),
428428
}));
429429

430-
test('web resident runner iss debuggable', () => testbed.run(() {
430+
test('web resident runner is debuggable', () => testbed.run(() {
431431
expect(residentWebRunner.debuggingEnabled, true);
432-
}, overrides: <Type, Generator>{
433432
}));
434433

435434
test('Exits when initial compile fails', () => testbed.run(() async {

0 commit comments

Comments
 (0)