Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Enable web integration tests in CI #3738

Merged
merged 5 commits into from
Mar 19, 2021
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
29 changes: 0 additions & 29 deletions .ci/Dockerfile-LegacyChrome

This file was deleted.

59 changes: 24 additions & 35 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ task:
CHANNEL: "stable"
script:
- ./script/build_all_plugins_app.sh web
- name: build-web-examples
env:
matrix:
CHANNEL: "master"
build_script:
- ./script/incremental_build.sh build-examples --web
# TODO: Add driving examples (and move to heavy-workload group).
### Linux desktop tasks ###
- name: build_all_plugins_linux
env:
Expand All @@ -117,35 +110,8 @@ task:
build_script:
- flutter config --enable-linux-desktop
- ./script/incremental_build.sh build-examples --linux
- xvfb-run ./script/incremental_build.sh drive-examples --linux

# Legacy Dockerfile configuration for web integration tests.
# https://github.com/flutter/web_installers doesn't yet support the current
# stable version of Chrome, so newly-generated Docker images don't work.
# TODO: Merge this task into the "Web tasks" section of the "Light-workload
# tasks" block above once web_installers has been updated to support Chrome 89
# (which is what the current image generated from .ci/Dockerfile has).
task:
<< : *FLUTTER_UPGRADE_TEMPLATE
container:
dockerfile: .ci/Dockerfile-LegacyChrome
matrix:
- name: integration_web_smoke_test
env:
matrix:
CHANNEL: "master"
CHANNEL: "stable"
# Tests integration example test in web.
only_if: "changesInclude('.cirrus.yml', 'packages/integration_test/**') || $CIRRUS_PR == ''"
install_script:
- git clone https://github.com/flutter/web_installers.git
- cd web_installers/packages/web_drivers/
- pub get
- dart lib/web_driver_installer.dart chromedriver --install-only
- ./chromedriver/chromedriver --port=4444 &
test_script:
- cd $INTEGRATION_TEST_PATH/example/
- flutter drive -v --driver=test_driver/integration_test.dart --target=integration_test/example_test.dart -d web-server --release --browser-name=chrome
- xvfb-run ./script/incremental_build.sh drive-examples --linux

# Heavy-workload Linux tasks.
# These use machines with more CPUs and memory, so will reduce parallelization
Expand Down Expand Up @@ -191,6 +157,27 @@ task:
- fi
- export CIRRUS_CHANGE_MESSAGE=`cat /tmp/cirrus_change_message.txt`
- export CIRRUS_COMMIT_MESSAGE=`cat /tmp/cirrus_commit_message.txt`
### Web tasks ###
- name: build-web+drive-examples
env:
matrix:
CHANNEL: "master"
CHANNEL: "stable"
install_script:
- git clone https://github.com/flutter/web_installers.git
- cd web_installers/packages/web_drivers/
- pub get
- dart lib/web_driver_installer.dart chromedriver --install-only
- ./chromedriver/chromedriver --port=4444 &
build_script:
- ./script/incremental_build.sh build-examples --web
test_script:
# TODO(stuartmorgan): Eliminate this check once 2.1 reaches stable.
- if [[ "$CHANNEL" == "master" ]]; then
- ./script/incremental_build.sh drive-examples --web
- else
- echo "Requires null-safe integration_test; skipping."
- fi

# macOS tasks.
task:
Expand Down Expand Up @@ -223,6 +210,7 @@ task:
- xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-3 | xargs xcrun simctl boot
build_script:
- ./script/incremental_build.sh build-examples --ipa
test_script:
- ./script/incremental_build.sh xctest --skip $PLUGINS_TO_SKIP_XCTESTS --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
# `drive-examples` contains integration tests, which changes the UI of the application.
# This UI change sometimes affects `xctest`.
Expand All @@ -246,6 +234,7 @@ task:
build_script:
- flutter config --enable-macos-desktop
- ./script/incremental_build.sh build-examples --macos --no-ipa
test_script:
- ./script/incremental_build.sh drive-examples --macos

task:
Expand Down
38 changes: 26 additions & 12 deletions script/tool/lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ class DriveExamplesCommand extends PluginCommand {
FileSystem fileSystem, {
ProcessRunner processRunner = const ProcessRunner(),
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
argParser.addFlag(kAndroid,
help: 'Runs the Android implementation of the examples');
argParser.addFlag(kIos,
help: 'Runs the iOS implementation of the examples');
argParser.addFlag(kLinux,
help: 'Runs the Linux implementation of the examples');
argParser.addFlag(kMacos,
help: 'Runs the macOS implementation of the examples');
argParser.addFlag(kWeb,
help: 'Runs the web implementation of the examples');
argParser.addFlag(kWindows,
help: 'Runs the Windows implementation of the examples');
argParser.addFlag(kIos,
help: 'Runs the iOS implementation of the examples');
argParser.addFlag(kAndroid,
help: 'Runs the Android implementation of the examples');
argParser.addOption(
kEnableExperiment,
defaultsTo: '',
Expand Down Expand Up @@ -51,6 +53,7 @@ class DriveExamplesCommand extends PluginCommand {
final List<String> failingTests = <String>[];
final bool isLinux = argResults[kLinux];
final bool isMacos = argResults[kMacos];
final bool isWeb = argResults[kWeb];
final bool isWindows = argResults[kWindows];
await for (Directory plugin in getPlugins()) {
final String flutterCommand =
Expand Down Expand Up @@ -139,6 +142,13 @@ Tried searching for the following:
'macos',
]);
}
if (isWeb && isWebPlugin(plugin, fileSystem)) {
driveArgs.addAll(<String>[
'-d',
'web-server',
'--browser-name=chrome',
]);
}
if (isWindows && isWindowsPlugin(plugin, fileSystem)) {
driveArgs.addAll(<String>[
'-d',
Expand Down Expand Up @@ -180,26 +190,30 @@ Tried searching for the following:

Future<bool> pluginSupportedOnCurrentPlatform(
FileSystemEntity plugin, FileSystem fileSystem) async {
final bool isAndroid = argResults[kAndroid];
final bool isIOS = argResults[kIos];
final bool isLinux = argResults[kLinux];
final bool isMacos = argResults[kMacos];
final bool isWeb = argResults[kWeb];
final bool isWindows = argResults[kWindows];
final bool isIOS = argResults[kIos];
final bool isAndroid = argResults[kAndroid];
if (isAndroid) {
return (isAndroidPlugin(plugin, fileSystem));
}
if (isIOS) {
return isIosPlugin(plugin, fileSystem);
}
if (isLinux) {
return isLinuxPlugin(plugin, fileSystem);
}
if (isMacos) {
return isMacOsPlugin(plugin, fileSystem);
}
if (isWeb) {
return isWebPlugin(plugin, fileSystem);
}
if (isWindows) {
return isWindowsPlugin(plugin, fileSystem);
}
if (isIOS) {
return isIosPlugin(plugin, fileSystem);
}
if (isAndroid) {
return (isAndroidPlugin(plugin, fileSystem));
}
// When we are here, no flags are specified. Only return true if the plugin
// supports Android for legacy command support. TODO(cyanglaz): Make Android
// flag also required like other platforms (breaking change).
Expand Down
88 changes: 84 additions & 4 deletions script/tool/test/drive_examples_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ void main() {
]));
});

test('driving when plugin does not suppport windows is a no-op', () async {
test('driving when plugin does not suppport web is a no-op', () async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
<String>['example', 'test_driver', 'plugin_test.dart'],
<String>['example', 'test_driver', 'plugin.dart'],
],
isMacOsPlugin: false);
isWebPlugin: false);

final Directory pluginExampleDirectory =
mockPackagesDir.childDirectory('plugin').childDirectory('example');
Expand All @@ -372,7 +372,7 @@ void main() {

final List<String> output = await runCapturingPrint(runner, <String>[
'drive-examples',
'--windows',
'--web',
]);

expect(
Expand All @@ -384,11 +384,91 @@ void main() {
);

print(processRunner.recordedCalls);
// Output should be empty since running drive-examples --windows on a non-windows
// Output should be empty since running drive-examples --web on a non-web
// plugin is a no-op.
expect(processRunner.recordedCalls, <ProcessCall>[]);
});

test('driving a web plugin', () async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
<String>['example', 'test_driver', 'plugin_test.dart'],
<String>['example', 'test_driver', 'plugin.dart'],
],
isWebPlugin: true);

final Directory pluginExampleDirectory =
mockPackagesDir.childDirectory('plugin').childDirectory('example');

createFakePubspec(pluginExampleDirectory, isFlutter: true);

final List<String> output = await runCapturingPrint(runner, <String>[
'drive-examples',
'--web',
]);

expect(
output,
orderedEquals(<String>[
'\n\n',
'All driver tests successful!',
]),
);

String deviceTestPath = p.join('test_driver', 'plugin.dart');
String driverTestPath = p.join('test_driver', 'plugin_test.dart');
print(processRunner.recordedCalls);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
flutterCommand,
<String>[
'drive',
'-d',
'web-server',
'--browser-name=chrome',
'--driver',
driverTestPath,
'--target',
deviceTestPath
],
pluginExampleDirectory.path),
]));
});

test('driving when plugin does not suppport Windows is a no-op', () async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
<String>['example', 'test_driver', 'plugin_test.dart'],
<String>['example', 'test_driver', 'plugin.dart'],
],
isWindowsPlugin: false);

final Directory pluginExampleDirectory =
mockPackagesDir.childDirectory('plugin').childDirectory('example');

createFakePubspec(pluginExampleDirectory, isFlutter: true);

final List<String> output = await runCapturingPrint(runner, <String>[
'drive-examples',
'--windows',
]);

expect(
output,
orderedEquals(<String>[
'\n\n',
'All driver tests successful!',
]),
);

print(processRunner.recordedCalls);
// Output should be empty since running drive-examples --windows on a
// non-Windows plugin is a no-op.
expect(processRunner.recordedCalls, <ProcessCall>[]);
});

test('driving on a Windows plugin', () async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
Expand Down