Skip to content

Commit 9bcf4bf

Browse files
authored
[ci] Add LUCI web platform tests (flutter#4391)
Adds web platform tests for LUCI in bringup mode. The Cirrus version of the test starts `chromedriver` at the beginning and just leaves it running, which is fine since it's a fresh docker image each run. For LUCI we don't want that behavior though, so instead this adds tooling support for running chromedriver as part of running the integration tests, controllable with a flag. This will also be useful for running locally. Part of flutter/flutter#114373
1 parent fd04153 commit 9bcf4bf

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-0
lines changed

-

Whitespace-only changes.

.ci.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,50 @@ targets:
437437
target_file: web_build_all_packages.yaml
438438
channel: stable
439439

440+
- name: Linux_web web_platform_tests_shard_1 master
441+
bringup: true # New target
442+
recipe: packages/packages
443+
timeout: 60
444+
properties:
445+
target_file: web_platform_tests.yaml
446+
cores: "32"
447+
version_file: flutter_master.version
448+
channel: master
449+
package_sharding: "--shardIndex 0 --shardCount 2"
450+
451+
- name: Linux_web web_platform_tests_shard_2 master
452+
bringup: true # New target
453+
recipe: packages/packages
454+
timeout: 60
455+
properties:
456+
target_file: web_platform_tests.yaml
457+
cores: "32"
458+
version_file: flutter_master.version
459+
channel: master
460+
package_sharding: "--shardIndex 1 --shardCount 2"
461+
462+
- name: Linux_web web_platform_tests_shard_1 stable
463+
bringup: true # New target
464+
recipe: packages/packages
465+
timeout: 60
466+
properties:
467+
target_file: web_platform_tests.yaml
468+
cores: "32"
469+
version_file: flutter_stable.version
470+
channel: stable
471+
package_sharding: "--shardIndex 0 --shardCount 2"
472+
473+
- name: Linux_web web_platform_tests_shard_2 stable
474+
bringup: true # New target
475+
recipe: packages/packages
476+
timeout: 60
477+
properties:
478+
target_file: web_platform_tests.yaml
479+
cores: "32"
480+
version_file: flutter_stable.version
481+
channel: stable
482+
package_sharding: "--shardIndex 1 --shardCount 2"
483+
440484
### Linux desktop tasks
441485
- name: Linux_desktop build_all_packages master
442486
recipe: packages/packages

.ci/targets/web_platform_tests.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tasks:
2+
- name: prepare tool
3+
script: .ci/scripts/prepare_tool.sh
4+
- name: build examples
5+
script: script/tool_runner.sh
6+
args: ["build-examples", "--web"]
7+
- name: drive examples
8+
script: script/tool_runner.sh
9+
args: ["drive-examples", "--web", "--run-chromedriver", "--exclude=script/configs/exclude_integration_web.yaml"]

script/tool/lib/src/drive_examples_command.dart

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:async';
56
import 'dart:convert';
67
import 'dart:io';
78

@@ -17,6 +18,9 @@ import 'common/repository_package.dart';
1718
const int _exitNoPlatformFlags = 2;
1819
const int _exitNoAvailableDevice = 3;
1920

21+
// From https://docs.flutter.dev/testing/integration-tests#running-in-a-browser
22+
const int _chromeDriverPort = 4444;
23+
2024
/// A command to run the integration tests for a package's example applications.
2125
class DriveExamplesCommand extends PackageLoopingCommand {
2226
/// Creates an instance of the drive command.
@@ -44,8 +48,13 @@ class DriveExamplesCommand extends PackageLoopingCommand {
4448
help:
4549
'Runs the driver tests in Dart VM with the given experiments enabled.',
4650
);
51+
argParser.addFlag(_chromeDriverFlag,
52+
help: 'Runs chromedriver for the duration of the test.\n\n'
53+
'Requires the correct version of chromedriver to be in your path.');
4754
}
4855

56+
static const String _chromeDriverFlag = 'run-chromedriver';
57+
4958
@override
5059
final String name = 'drive-examples';
5160

@@ -197,6 +206,12 @@ class DriveExamplesCommand extends PackageLoopingCommand {
197206

198207
testsRan = true;
199208
if (useFlutterDrive) {
209+
Process? chromedriver;
210+
if (getBoolArg(_chromeDriverFlag)) {
211+
print('Starting chromedriver on port $_chromeDriverPort');
212+
chromedriver = await processRunner
213+
.start('chromedriver', <String>['--port=$_chromeDriverPort']);
214+
}
200215
for (final File driver in drivers) {
201216
final List<File> failingTargets = await _driveTests(
202217
example, driver, testTargets,
@@ -206,6 +221,10 @@ class DriveExamplesCommand extends PackageLoopingCommand {
206221
getRelativePosixPath(failingTarget, from: package.directory));
207222
}
208223
}
224+
if (chromedriver != null) {
225+
print('Stopping chromedriver');
226+
chromedriver.kill();
227+
}
209228
} else {
210229
if (!await _runTests(example, deviceFlags: deviceFlags)) {
211230
errors.add('Integration tests failed.');

script/tool/test/drive_examples_command_test.dart

+48
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,54 @@ void main() {
520520
]));
521521
});
522522

523+
test('runs chromedriver when requested', () async {
524+
final RepositoryPackage plugin = createFakePlugin(
525+
'plugin',
526+
packagesDir,
527+
extraFiles: <String>[
528+
'example/integration_test/plugin_test.dart',
529+
'example/test_driver/integration_test.dart',
530+
'example/web/index.html',
531+
],
532+
platformSupport: <String, PlatformDetails>{
533+
platformWeb: const PlatformDetails(PlatformSupport.inline),
534+
},
535+
);
536+
537+
final Directory pluginExampleDirectory = getExampleDir(plugin);
538+
539+
final List<String> output = await runCapturingPrint(
540+
runner, <String>['drive-examples', '--web', '--run-chromedriver']);
541+
542+
expect(
543+
output,
544+
containsAllInOrder(<Matcher>[
545+
contains('Running for plugin'),
546+
contains('No issues found!'),
547+
]),
548+
);
549+
550+
expect(
551+
processRunner.recordedCalls,
552+
orderedEquals(<ProcessCall>[
553+
const ProcessCall('chromedriver', <String>['--port=4444'], null),
554+
ProcessCall(
555+
getFlutterCommand(mockPlatform),
556+
const <String>[
557+
'drive',
558+
'-d',
559+
'web-server',
560+
'--web-port=7357',
561+
'--browser-name=chrome',
562+
'--driver',
563+
'test_driver/integration_test.dart',
564+
'--target',
565+
'integration_test/plugin_test.dart',
566+
],
567+
pluginExampleDirectory.path),
568+
]));
569+
});
570+
523571
test('drives a web plugin with CHROME_EXECUTABLE', () async {
524572
final RepositoryPackage plugin = createFakePlugin(
525573
'plugin',

script/tool/test/mocks.dart

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class MockProcess extends Mock implements io.Process {
7979

8080
@override
8181
IOSink get stdin => stdinMock;
82+
83+
@override
84+
bool kill([io.ProcessSignal signal = io.ProcessSignal.sigterm]) => true;
8285
}
8386

8487
class MockIOSink extends Mock implements IOSink {

0 commit comments

Comments
 (0)