From c2418acbd3f7c1298f046bb493a482d660e6e94a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 19 Mar 2021 13:55:22 -0400 Subject: [PATCH 1/5] Add web support to drive-examples script command --- .../tool/lib/src/drive_examples_command.dart | 39 +++++--- .../test/drive_examples_command_test.dart | 88 ++++++++++++++++++- 2 files changed, 111 insertions(+), 16 deletions(-) diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index 4b5b33ff9029..8aad0916d763 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -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: '', @@ -51,6 +53,7 @@ class DriveExamplesCommand extends PluginCommand { final List failingTests = []; 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 = @@ -139,6 +142,13 @@ Tried searching for the following: 'macos', ]); } + if (isWeb && isWebPlugin(plugin, fileSystem)) { + driveArgs.addAll([ + '-d', + 'web-server', + '--browser-name=chrome', + ]); + } if (isWindows && isWindowsPlugin(plugin, fileSystem)) { driveArgs.addAll([ '-d', @@ -180,26 +190,30 @@ Tried searching for the following: Future 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). @@ -207,3 +221,4 @@ Tried searching for the following: return isAndroidPlugin(plugin, fileSystem); } } +// - flutter drive -v --driver=test_driver/integration_test.dart --target=integration_test/example_test.dart diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index 63a3e69adcdc..86d6357dbc81 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -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: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], ], - isMacOsPlugin: false); + isWebPlugin: false); final Directory pluginExampleDirectory = mockPackagesDir.childDirectory('plugin').childDirectory('example'); @@ -372,7 +372,7 @@ void main() { final List output = await runCapturingPrint(runner, [ 'drive-examples', - '--windows', + '--web', ]); expect( @@ -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, []); }); + test('driving a web plugin', () async { + createFakePlugin('plugin', + withExtraFiles: >[ + ['example', 'test_driver', 'plugin_test.dart'], + ['example', 'test_driver', 'plugin.dart'], + ], + isWebPlugin: true); + + final Directory pluginExampleDirectory = + mockPackagesDir.childDirectory('plugin').childDirectory('example'); + + createFakePubspec(pluginExampleDirectory, isFlutter: true); + + final List output = await runCapturingPrint(runner, [ + 'drive-examples', + '--web', + ]); + + expect( + output, + orderedEquals([ + '\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( + flutterCommand, + [ + '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: >[ + ['example', 'test_driver', 'plugin_test.dart'], + ['example', 'test_driver', 'plugin.dart'], + ], + isWindowsPlugin: false); + + final Directory pluginExampleDirectory = + mockPackagesDir.childDirectory('plugin').childDirectory('example'); + + createFakePubspec(pluginExampleDirectory, isFlutter: true); + + final List output = await runCapturingPrint(runner, [ + 'drive-examples', + '--windows', + ]); + + expect( + output, + orderedEquals([ + '\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, []); + }); + test('driving on a Windows plugin', () async { createFakePlugin('plugin', withExtraFiles: >[ From d6c98c80f949d0b78a7bd59103de8b9fd098cd20 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 19 Mar 2021 13:55:45 -0400 Subject: [PATCH 2/5] Enable integration tests for web on master --- .cirrus.yml | 59 ++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 26264b3fb926..7662577e0a39 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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: @@ -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 @@ -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 [[ "$CIRRUS_BRANCH" == "master" ]]; then + - ./script/incremental_build.sh drive-examples --web + - else + - echo "Requires null-safe integration_test; skipping." + - fi # macOS tasks. task: @@ -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`. @@ -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: From 23fcf83a39f72d070fde8f5a715b22f0de5b8964 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 19 Mar 2021 13:56:22 -0400 Subject: [PATCH 3/5] Remove the legacy docker image now that it's no longe used --- .ci/Dockerfile-LegacyChrome | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 .ci/Dockerfile-LegacyChrome diff --git a/.ci/Dockerfile-LegacyChrome b/.ci/Dockerfile-LegacyChrome deleted file mode 100644 index 13ac087498d1..000000000000 --- a/.ci/Dockerfile-LegacyChrome +++ /dev/null @@ -1,29 +0,0 @@ -FROM cirrusci/flutter:stable - -RUN sudo apt-get update -y - -RUN sudo apt-get install -y --no-install-recommends gnupg - -# Add repo for gcloud sdk and install it -RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \ - sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list - -RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ - sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - - -RUN sudo apt-get update && sudo apt-get install -y google-cloud-sdk && \ - gcloud config set core/disable_usage_reporting true && \ - gcloud config set component_manager/disable_update_check true - -RUN yes | sdkmanager \ - "platforms;android-27" \ - "build-tools;27.0.3" \ - "extras;google;m2repository" \ - "extras;android;m2repository" - -RUN yes | sdkmanager --licenses - -# Add repo for Google Chrome and install it -RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - -RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list -RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends google-chrome-stable From 6c217f0fcf83f0319920538b6f296e510c87f533 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 19 Mar 2021 14:17:53 -0400 Subject: [PATCH 4/5] Fix channel check --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index 7662577e0a39..c2bbd35e15e7 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -173,7 +173,7 @@ task: - ./script/incremental_build.sh build-examples --web test_script: # TODO(stuartmorgan): Eliminate this check once 2.1 reaches stable. - - if [[ "$CIRRUS_BRANCH" == "master" ]]; then + - if [[ "$CHANNEL" == "master" ]]; then - ./script/incremental_build.sh drive-examples --web - else - echo "Requires null-safe integration_test; skipping." From 27bb9cf8240b6aed4d7dbd8dc7e6638029c7722a Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 19 Mar 2021 13:07:26 -0700 Subject: [PATCH 5/5] Remove cruft --- script/tool/lib/src/drive_examples_command.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/script/tool/lib/src/drive_examples_command.dart b/script/tool/lib/src/drive_examples_command.dart index 8aad0916d763..12e7bf709ee7 100644 --- a/script/tool/lib/src/drive_examples_command.dart +++ b/script/tool/lib/src/drive_examples_command.dart @@ -221,4 +221,3 @@ Tried searching for the following: return isAndroidPlugin(plugin, fileSystem); } } -// - flutter drive -v --driver=test_driver/integration_test.dart --target=integration_test/example_test.dart