From c2d9583da6d222abc152eea8f29752590e7bc4af Mon Sep 17 00:00:00 2001 From: Jonathan Edey Date: Mon, 30 Nov 2026 18:39:59 +0000 Subject: [PATCH] test(e2e): make web e2e verdicts trustworthy for plain test() suites On web, `flutter drive -d web-server` exits 0 for suites whose plain `test()` cases fail: `IntegrationTestWidgetsFlutterBinding` only records `testWidgets` failures (via `reportTestException`), so `allTestsPassed` is always true, and the browser console never reaches the host, so the `[E]` check in the retry script has nothing to match. - `integration_test/report_test_results.dart` (one copy per e2e app, kept identical by a test in `tests/test`) now records a `Failure` in `binding.results` for every executed test whose `TestHandle.shouldBeDone` is false, and for a suite that executed nothing, so the stock `integrationDriver` verdict and exit code are correct without any custom tally. The copies stay per app because the web build cannot resolve an import above the package root. The same entries also reach the native `allTestsFinished` payload, where `flutter test`'s own exit code was already authoritative. A suite that skips every test on a platform (firebase_performance on web) keeps failing, as it did with the previous empty-tally check. - The `flutter drive` entrypoint is shared: the 15 per-app `test_driver/integration_test.dart` copies are deleted and CI/Melos point `--driver` at `tests/test_driver/integration_test.dart`, which also dumps the WebDriver session's browser console (with API keys and tokens redacted, and also when connecting to the app failed) so assertion messages and the runner's `[E]` lines appear in the `flutter drive` log. The Windows e2e jobs use the same shared driver (the console dump is a no-op without a WebDriver session). - Product e2e workflows trigger on changes to the shared driver: `tests/test_driver/**` sits under the `web` and `windows` filters in `reusable_e2e_changes.yaml`, so a driver change does not trigger the Android, iOS and macOS jobs that never use it. --- .github/workflows/e2e_tests_ai.yaml | 4 + .github/workflows/e2e_tests_analytics.yaml | 4 + .github/workflows/e2e_tests_app_check.yaml | 4 + .../e2e_tests_app_installations.yaml | 4 + .github/workflows/e2e_tests_auth.yaml | 4 + .github/workflows/e2e_tests_database.yaml | 4 + .github/workflows/e2e_tests_fdc.yaml | 8 +- .github/workflows/e2e_tests_firestore.yaml | 4 + .github/workflows/e2e_tests_functions.yaml | 4 + .github/workflows/e2e_tests_messaging.yaml | 4 + .github/workflows/e2e_tests_performance.yaml | 4 + .github/workflows/e2e_tests_pipeline.yaml | 6 +- .../workflows/e2e_tests_remote_config.yaml | 4 + .github/workflows/e2e_tests_storage.yaml | 4 + .github/workflows/reusable_e2e_changes.yaml | 5 +- .github/workflows/reusable_e2e_web.yaml | 5 +- .github/workflows/reusable_e2e_windows.yaml | 4 +- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../pipeline/report_test_results.dart | 73 ++++-- .../test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 67 ++--- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- .../integration_test/report_test_results.dart | 73 ++++-- .../example/test_driver/integration_test.dart | 38 --- pubspec.yaml | 24 +- .../integration_test/report_test_results.dart | 73 ++++-- tests/test/web_e2e_reporting_test.dart | 245 ++++++++++++++++++ tests/test_driver/integration_test.dart | 115 ++++++-- 51 files changed, 1127 insertions(+), 1065 deletions(-) delete mode 100644 packages/cloud_firestore/cloud_firestore/example/test_driver/integration_test.dart delete mode 100644 packages/cloud_firestore/cloud_firestore/pipeline_example/test_driver/integration_test.dart delete mode 100644 packages/cloud_functions/cloud_functions/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_ai/firebase_ai/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_analytics/firebase_analytics/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_app_check/firebase_app_check/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_app_installations/firebase_app_installations/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_auth/firebase_auth/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_crashlytics/firebase_crashlytics/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_data_connect/firebase_data_connect/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_database/firebase_database/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_messaging/firebase_messaging/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_performance/firebase_performance/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_remote_config/firebase_remote_config/example/test_driver/integration_test.dart delete mode 100644 packages/firebase_storage/firebase_storage/example/test_driver/integration_test.dart create mode 100644 tests/test/web_e2e_reporting_test.dart diff --git a/.github/workflows/e2e_tests_ai.yaml b/.github/workflows/e2e_tests_ai.yaml index 860101dc13cc..4ffeef08b4ab 100644 --- a/.github/workflows/e2e_tests_ai.yaml +++ b/.github/workflows/e2e_tests_ai.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_ai/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_ai.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_ai/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_ai.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_analytics.yaml b/.github/workflows/e2e_tests_analytics.yaml index bd5acc729d94..2ad5c1f6a277 100644 --- a/.github/workflows/e2e_tests_analytics.yaml +++ b/.github/workflows/e2e_tests_analytics.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_analytics/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_analytics.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_analytics/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_analytics.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_app_check.yaml b/.github/workflows/e2e_tests_app_check.yaml index 14b05d188005..ad331d5f3746 100644 --- a/.github/workflows/e2e_tests_app_check.yaml +++ b/.github/workflows/e2e_tests_app_check.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_app_check/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_app_check.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_app_check/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_app_check.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_app_installations.yaml b/.github/workflows/e2e_tests_app_installations.yaml index 97e0a49325f4..8e339c26ce17 100644 --- a/.github/workflows/e2e_tests_app_installations.yaml +++ b/.github/workflows/e2e_tests_app_installations.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_app_installations/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_app_installations.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_app_installations/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_app_installations.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_auth.yaml b/.github/workflows/e2e_tests_auth.yaml index a0ce1ca07dcb..0d1fda20da6a 100644 --- a/.github/workflows/e2e_tests_auth.yaml +++ b/.github/workflows/e2e_tests_auth.yaml @@ -23,6 +23,8 @@ on: paths: - 'packages/firebase_auth/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_auth.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -33,6 +35,8 @@ on: paths: - 'packages/firebase_auth/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_auth.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_database.yaml b/.github/workflows/e2e_tests_database.yaml index 5e801fbd82fa..b71781a14ca2 100644 --- a/.github/workflows/e2e_tests_database.yaml +++ b/.github/workflows/e2e_tests_database.yaml @@ -17,6 +17,8 @@ on: paths: - 'packages/firebase_database/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_database.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -27,6 +29,8 @@ on: paths: - 'packages/firebase_database/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_database.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_fdc.yaml b/.github/workflows/e2e_tests_fdc.yaml index 4b8000a830d7..5e4afab7b826 100644 --- a/.github/workflows/e2e_tests_fdc.yaml +++ b/.github/workflows/e2e_tests_fdc.yaml @@ -12,6 +12,8 @@ on: paths: - 'packages/firebase_data_connect/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_fdc.yaml' - '.github/actions/setup-flutterfire/**' push: @@ -20,6 +22,8 @@ on: paths: - 'packages/firebase_data_connect/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_fdc.yaml' - '.github/actions/setup-flutterfire/**' workflow_call: @@ -266,7 +270,7 @@ jobs: # connect. Retry only those infrastructure startup failures. run: | FLUTTER_DRIVE_TARGET="./integration_test/e2e_test.dart" \ - FLUTTER_DRIVE_DRIVER="./test_driver/integration_test.dart" \ + FLUTTER_DRIVE_DRIVER="${GITHUB_WORKSPACE}/tests/test_driver/integration_test.dart" \ FLUTTER_DRIVE_EXTRA_ARGS="--dart-define=CI=true" \ "${GITHUB_WORKSPACE}/.github/workflows/scripts/flutter-drive-web-retry.sh" shell: bash @@ -325,7 +329,7 @@ jobs: run: | mv ./web/wasm_index.html ./web/index.html FLUTTER_DRIVE_TARGET="./integration_test/e2e_test.dart" \ - FLUTTER_DRIVE_DRIVER="./test_driver/integration_test.dart" \ + FLUTTER_DRIVE_DRIVER="${GITHUB_WORKSPACE}/tests/test_driver/integration_test.dart" \ FLUTTER_DRIVE_EXTRA_ARGS="--wasm --dart-define=CI=true" \ FLUTTER_DRIVE_TIMEOUT_SECONDS="300" \ FLUTTER_DRIVE_MAX_ATTEMPTS="2" \ diff --git a/.github/workflows/e2e_tests_firestore.yaml b/.github/workflows/e2e_tests_firestore.yaml index 0cf044de477c..23ae4cba893b 100644 --- a/.github/workflows/e2e_tests_firestore.yaml +++ b/.github/workflows/e2e_tests_firestore.yaml @@ -20,6 +20,8 @@ on: paths: - 'packages/cloud_firestore/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_firestore.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -30,6 +32,8 @@ on: paths: - 'packages/cloud_firestore/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_firestore.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_functions.yaml b/.github/workflows/e2e_tests_functions.yaml index b979d19c69c6..0e8f95790e35 100644 --- a/.github/workflows/e2e_tests_functions.yaml +++ b/.github/workflows/e2e_tests_functions.yaml @@ -17,6 +17,8 @@ on: paths: - 'packages/cloud_functions/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_functions.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -27,6 +29,8 @@ on: paths: - 'packages/cloud_functions/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_functions.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_messaging.yaml b/.github/workflows/e2e_tests_messaging.yaml index f46c8b6960f8..fd76acdf8872 100644 --- a/.github/workflows/e2e_tests_messaging.yaml +++ b/.github/workflows/e2e_tests_messaging.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_messaging/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_messaging.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_messaging/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_messaging.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_performance.yaml b/.github/workflows/e2e_tests_performance.yaml index 25daeeaa420a..a27415fd8af4 100644 --- a/.github/workflows/e2e_tests_performance.yaml +++ b/.github/workflows/e2e_tests_performance.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_performance/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_performance.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_performance/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_performance.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_pipeline.yaml b/.github/workflows/e2e_tests_pipeline.yaml index b53c25bf293d..e05e5aaf8f2b 100644 --- a/.github/workflows/e2e_tests_pipeline.yaml +++ b/.github/workflows/e2e_tests_pipeline.yaml @@ -12,6 +12,8 @@ on: paths: - 'packages/cloud_firestore/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_pipeline.yaml' - '.github/actions/setup-flutterfire/**' push: @@ -20,6 +22,8 @@ on: paths: - 'packages/cloud_firestore/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_pipeline.yaml' - '.github/actions/setup-flutterfire/**' workflow_call: @@ -154,7 +158,7 @@ jobs: # connect. Retry only those infrastructure startup failures. run: | FLUTTER_DRIVE_TARGET="./integration_test/pipeline/pipeline_live_test.dart" \ - FLUTTER_DRIVE_DRIVER="./test_driver/integration_test.dart" \ + FLUTTER_DRIVE_DRIVER="${GITHUB_WORKSPACE}/tests/test_driver/integration_test.dart" \ FLUTTER_DRIVE_EXTRA_ARGS="--dart-define=CI=true" \ "${GITHUB_WORKSPACE}/.github/workflows/scripts/flutter-drive-web-retry.sh" shell: bash diff --git a/.github/workflows/e2e_tests_remote_config.yaml b/.github/workflows/e2e_tests_remote_config.yaml index 96d831c3da8f..1c96a663fd2b 100644 --- a/.github/workflows/e2e_tests_remote_config.yaml +++ b/.github/workflows/e2e_tests_remote_config.yaml @@ -19,6 +19,8 @@ on: paths: - 'packages/firebase_remote_config/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_remote_config.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -29,6 +31,8 @@ on: paths: - 'packages/firebase_remote_config/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_remote_config.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/e2e_tests_storage.yaml b/.github/workflows/e2e_tests_storage.yaml index 8beadfce3a67..6e1963e00026 100644 --- a/.github/workflows/e2e_tests_storage.yaml +++ b/.github/workflows/e2e_tests_storage.yaml @@ -17,6 +17,8 @@ on: paths: - 'packages/firebase_storage/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_storage.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' @@ -27,6 +29,8 @@ on: paths: - 'packages/firebase_storage/**' - 'packages/firebase_core/**' + # The web e2e driver is shared by every e2e app. + - 'tests/test_driver/**' - '.github/workflows/e2e_tests_storage.yaml' - '.github/workflows/reusable_e2e_*.yaml' - '.github/actions/setup-flutterfire/**' diff --git a/.github/workflows/reusable_e2e_changes.yaml b/.github/workflows/reusable_e2e_changes.yaml index 951ab4f485d3..196af2b11dfe 100644 --- a/.github/workflows/reusable_e2e_changes.yaml +++ b/.github/workflows/reusable_e2e_changes.yaml @@ -102,7 +102,6 @@ jobs: - '${{ inputs.package-path }}/pubspec.yaml' - '${{ inputs.platform-interface-package && format('packages/*/{0}/**', inputs.platform-interface-package) || 'packages/__none__/**' }}' - '${{ inputs.package-path }}/example/integration_test/**' - - '${{ inputs.package-path }}/example/test_driver/**' - '${{ inputs.package-path }}/example/lib/**' - '${{ inputs.package-path }}/example/pubspec.yaml' - '.github/workflows/reusable_e2e_*.yaml' @@ -125,9 +124,13 @@ jobs: - '${{ inputs.package-path }}/example/macos/**' web: - *shared + # The `flutter drive` entrypoint shared by every e2e app (tests/). + - 'tests/test_driver/**' - '${{ inputs.web-package && format('packages/*/{0}/**', inputs.web-package) || 'packages/__none__/**' }}' - '${{ inputs.package-path }}/example/web/**' windows: - *shared + # Also the `flutter drive -d windows` entrypoint (reusable_e2e_windows.yaml). + - 'tests/test_driver/**' - '${{ inputs.package-path }}/windows/**' - '${{ inputs.package-path }}/example/windows/**' diff --git a/.github/workflows/reusable_e2e_web.yaml b/.github/workflows/reusable_e2e_web.yaml index 4f4020a43596..a6d8f7229785 100644 --- a/.github/workflows/reusable_e2e_web.yaml +++ b/.github/workflows/reusable_e2e_web.yaml @@ -204,7 +204,8 @@ jobs: working-directory: ./.github/workflows/scripts env: FLUTTER_DRIVE_TARGET: './${{ inputs.test-target }}' - FLUTTER_DRIVE_DRIVER: './test_driver/integration_test.dart' + # One driver for every web e2e suite; it lives with the smoke app. + FLUTTER_DRIVE_DRIVER: '${{ github.workspace }}/tests/test_driver/integration_test.dart' FLUTTER_DRIVE_EXTRA_ARGS: ${{ inputs.wasm && '--wasm --dart-define=CI=true' || '--dart-define=CI=true' }} # Empty falls back to the retry script's own defaults (180s, 4 attempts). FLUTTER_DRIVE_TIMEOUT_SECONDS: ${{ inputs.drive-timeout }} @@ -218,7 +219,7 @@ jobs: timeout-minutes: 20 env: FLUTTER_DRIVE_TARGET: './${{ inputs.test-target }}' - FLUTTER_DRIVE_DRIVER: './test_driver/integration_test.dart' + FLUTTER_DRIVE_DRIVER: '${{ github.workspace }}/tests/test_driver/integration_test.dart' FLUTTER_DRIVE_EXTRA_ARGS: ${{ inputs.wasm && '--wasm --dart-define=CI=true' || '--dart-define=CI=true' }} # Empty falls back to the retry script's own defaults (180s, 4 attempts). FLUTTER_DRIVE_TIMEOUT_SECONDS: ${{ inputs.drive-timeout }} diff --git a/.github/workflows/reusable_e2e_windows.yaml b/.github/workflows/reusable_e2e_windows.yaml index 1992fe5f6b10..010a2720b68c 100644 --- a/.github/workflows/reusable_e2e_windows.yaml +++ b/.github/workflows/reusable_e2e_windows.yaml @@ -153,7 +153,7 @@ jobs: run: | cd ./.github/workflows/scripts function Invoke-Drive { - firebase emulators:exec --project flutterfire-e2e-tests "cd ../../../$env:PACKAGE_PATH/example && flutter drive --target=.\$env:TEST_TARGET --driver=.\test_driver\integration_test.dart -d windows --verbose" 2>&1 | Tee-Object -FilePath output.log + firebase emulators:exec --project flutterfire-e2e-tests "cd ../../../$env:PACKAGE_PATH/example && flutter drive --target=.\$env:TEST_TARGET --driver=$env:GITHUB_WORKSPACE\tests\test_driver\integration_test.dart -d windows --verbose" 2>&1 | Tee-Object -FilePath output.log $script:exitCode = $LASTEXITCODE $script:output = Get-Content output.log -Raw } @@ -176,7 +176,7 @@ jobs: run: | cd $env:PACKAGE_PATH/example function Invoke-Drive { - flutter drive --target=.\$env:TEST_TARGET --driver=.\test_driver\integration_test.dart -d windows --dart-define=CI=true --verbose 2>&1 | Tee-Object -FilePath output.log + flutter drive --target=.\$env:TEST_TARGET --driver=$env:GITHUB_WORKSPACE\tests\test_driver\integration_test.dart -d windows --dart-define=CI=true --verbose 2>&1 | Tee-Object -FilePath output.log $script:exitCode = $LASTEXITCODE $script:output = Get-Content output.log -Raw } diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/report_test_results.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/report_test_results.dart index 0e4467aeb106..cd5e6891e992 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/report_test_results.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/cloud_firestore/cloud_firestore/example/test_driver/integration_test.dart b/packages/cloud_firestore/cloud_firestore/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/cloud_firestore/cloud_firestore/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/cloud_firestore/cloud_firestore/pipeline_example/integration_test/pipeline/report_test_results.dart b/packages/cloud_firestore/cloud_firestore/pipeline_example/integration_test/pipeline/report_test_results.dart index 9de87f8dd08b..3e0f99de6c26 100644 --- a/packages/cloud_firestore/cloud_firestore/pipeline_example/integration_test/pipeline/report_test_results.dart +++ b/packages/cloud_firestore/cloud_firestore/pipeline_example/integration_test/pipeline/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/cloud_firestore/cloud_firestore/pipeline_example/test_driver/integration_test.dart b/packages/cloud_firestore/cloud_firestore/pipeline_example/test_driver/integration_test.dart deleted file mode 100644 index fb6f33b1578d..000000000000 --- a/packages/cloud_firestore/cloud_firestore/pipeline_example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2026, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/cloud_functions/cloud_functions/example/integration_test/report_test_results.dart b/packages/cloud_functions/cloud_functions/example/integration_test/report_test_results.dart index ae1d2ffb7574..9a6d1895a5c0 100644 --- a/packages/cloud_functions/cloud_functions/example/integration_test/report_test_results.dart +++ b/packages/cloud_functions/cloud_functions/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/cloud_functions/cloud_functions/example/test_driver/integration_test.dart b/packages/cloud_functions/cloud_functions/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/cloud_functions/cloud_functions/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_ai/firebase_ai/example/integration_test/report_test_results.dart b/packages/firebase_ai/firebase_ai/example/integration_test/report_test_results.dart index 31ac2f7e63b9..7481d14a4fd9 100644 --- a/packages/firebase_ai/firebase_ai/example/integration_test/report_test_results.dart +++ b/packages/firebase_ai/firebase_ai/example/integration_test/report_test_results.dart @@ -17,35 +17,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_ai/firebase_ai/example/test_driver/integration_test.dart b/packages/firebase_ai/firebase_ai/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_ai/firebase_ai/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_analytics/firebase_analytics/example/integration_test/report_test_results.dart b/packages/firebase_analytics/firebase_analytics/example/integration_test/report_test_results.dart index 416b8cd76dd0..14b6ac11f4a6 100644 --- a/packages/firebase_analytics/firebase_analytics/example/integration_test/report_test_results.dart +++ b/packages/firebase_analytics/firebase_analytics/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_analytics/firebase_analytics/example/test_driver/integration_test.dart b/packages/firebase_analytics/firebase_analytics/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_analytics/firebase_analytics/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_app_check/firebase_app_check/example/integration_test/report_test_results.dart b/packages/firebase_app_check/firebase_app_check/example/integration_test/report_test_results.dart index db17f5dab066..30d02f8a2705 100644 --- a/packages/firebase_app_check/firebase_app_check/example/integration_test/report_test_results.dart +++ b/packages/firebase_app_check/firebase_app_check/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_app_check/firebase_app_check/example/test_driver/integration_test.dart b/packages/firebase_app_check/firebase_app_check/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_app_check/firebase_app_check/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_app_installations/firebase_app_installations/example/integration_test/report_test_results.dart b/packages/firebase_app_installations/firebase_app_installations/example/integration_test/report_test_results.dart index db17f5dab066..30d02f8a2705 100644 --- a/packages/firebase_app_installations/firebase_app_installations/example/integration_test/report_test_results.dart +++ b/packages/firebase_app_installations/firebase_app_installations/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_app_installations/firebase_app_installations/example/test_driver/integration_test.dart b/packages/firebase_app_installations/firebase_app_installations/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_app_installations/firebase_app_installations/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_auth/firebase_auth/example/integration_test/report_test_results.dart b/packages/firebase_auth/firebase_auth/example/integration_test/report_test_results.dart index d4101e2e818e..14b6ac11f4a6 100644 --- a/packages/firebase_auth/firebase_auth/example/integration_test/report_test_results.dart +++ b/packages/firebase_auth/firebase_auth/example/integration_test/report_test_results.dart @@ -9,41 +9,50 @@ import 'package:test_api/hooks.dart' show TestHandle; bool _reportTestResultsRegistered = false; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. /// -/// A second call would register another [setUp] and report each test twice. +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { if (_reportTestResultsRegistered) { return; } _reportTestResultsRegistered = true; - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_auth/firebase_auth/example/test_driver/integration_test.dart b/packages/firebase_auth/firebase_auth/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_auth/firebase_auth/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_crashlytics/firebase_crashlytics/example/integration_test/report_test_results.dart b/packages/firebase_crashlytics/firebase_crashlytics/example/integration_test/report_test_results.dart index 416b8cd76dd0..14b6ac11f4a6 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/example/integration_test/report_test_results.dart +++ b/packages/firebase_crashlytics/firebase_crashlytics/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_crashlytics/firebase_crashlytics/example/test_driver/integration_test.dart b/packages/firebase_crashlytics/firebase_crashlytics/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_crashlytics/firebase_crashlytics/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/report_test_results.dart b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/report_test_results.dart index 0e4467aeb106..cd5e6891e992 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/report_test_results.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/test_driver/integration_test.dart b/packages/firebase_data_connect/firebase_data_connect/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_data_connect/firebase_data_connect/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_database/firebase_database/example/integration_test/report_test_results.dart b/packages/firebase_database/firebase_database/example/integration_test/report_test_results.dart index db17f5dab066..30d02f8a2705 100644 --- a/packages/firebase_database/firebase_database/example/integration_test/report_test_results.dart +++ b/packages/firebase_database/firebase_database/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_database/firebase_database/example/test_driver/integration_test.dart b/packages/firebase_database/firebase_database/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_database/firebase_database/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_messaging/firebase_messaging/example/integration_test/report_test_results.dart b/packages/firebase_messaging/firebase_messaging/example/integration_test/report_test_results.dart index 416b8cd76dd0..14b6ac11f4a6 100644 --- a/packages/firebase_messaging/firebase_messaging/example/integration_test/report_test_results.dart +++ b/packages/firebase_messaging/firebase_messaging/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_messaging/firebase_messaging/example/test_driver/integration_test.dart b/packages/firebase_messaging/firebase_messaging/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_messaging/firebase_messaging/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_performance/firebase_performance/example/integration_test/report_test_results.dart b/packages/firebase_performance/firebase_performance/example/integration_test/report_test_results.dart index c170cb63c415..e69abc5c2b20 100644 --- a/packages/firebase_performance/firebase_performance/example/integration_test/report_test_results.dart +++ b/packages/firebase_performance/firebase_performance/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_performance/firebase_performance/example/test_driver/integration_test.dart b/packages/firebase_performance/firebase_performance/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_performance/firebase_performance/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_remote_config/firebase_remote_config/example/integration_test/report_test_results.dart b/packages/firebase_remote_config/firebase_remote_config/example/integration_test/report_test_results.dart index 416b8cd76dd0..14b6ac11f4a6 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/integration_test/report_test_results.dart +++ b/packages/firebase_remote_config/firebase_remote_config/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/integration_test.dart b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/packages/firebase_storage/firebase_storage/example/integration_test/report_test_results.dart b/packages/firebase_storage/firebase_storage/example/integration_test/report_test_results.dart index db17f5dab066..30d02f8a2705 100644 --- a/packages/firebase_storage/firebase_storage/example/integration_test/report_test_results.dart +++ b/packages/firebase_storage/firebase_storage/example/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/packages/firebase_storage/firebase_storage/example/test_driver/integration_test.dart b/packages/firebase_storage/firebase_storage/example/test_driver/integration_test.dart deleted file mode 100644 index 9ccbcc26ab97..000000000000 --- a/packages/firebase_storage/firebase_storage/example/test_driver/integration_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:integration_test/integration_test_driver.dart'; - -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', - ); - if (results.isEmpty) { - // ignore: avoid_print - print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', - ); - exit(1); - } - await writeResponseData(data); - }, -); diff --git a/pubspec.yaml b/pubspec.yaml index 7b095011ca00..9ca429b69371 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -391,84 +391,84 @@ melos: test:e2e:web:cloud_firestore: run: | cd packages/cloud_firestore/cloud_firestore/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for cloud_firestore on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:cloud_functions: run: | cd packages/cloud_functions/cloud_functions/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for cloud_functions on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_ai: run: | cd packages/firebase_ai/firebase_ai/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_ai on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_analytics: run: | cd packages/firebase_analytics/firebase_analytics/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_analytics on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_app_check: run: | cd packages/firebase_app_check/firebase_app_check/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_app_check on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_app_installations: run: | cd packages/firebase_app_installations/firebase_app_installations/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_app_installations on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_messaging: run: | cd packages/firebase_messaging/firebase_messaging/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_messaging on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_auth: run: | cd packages/firebase_auth/firebase_auth/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_auth on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_database: run: | cd packages/firebase_database/firebase_database/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_database on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_remote_config: run: | cd packages/firebase_remote_config/firebase_remote_config/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_remote_config on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_storage: run: | cd packages/firebase_storage/firebase_storage/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart -d chrome description: | Run all e2e tests for firebase_storage on web platform. Please ensure you have "chromedriver" installed and running. test:e2e:web:firebase_performance: run: | cd packages/firebase_performance/firebase_performance/example - flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart --release -d chrome + flutter drive --target=./integration_test/e2e_test.dart --driver=../../../../tests/test_driver/integration_test.dart --release -d chrome description: | Run all e2e tests for firebase_performance on web platform. Please ensure you have "chromedriver" installed and running. diff --git a/tests/integration_test/report_test_results.dart b/tests/integration_test/report_test_results.dart index db17f5dab066..30d02f8a2705 100644 --- a/tests/integration_test/report_test_results.dart +++ b/tests/integration_test/report_test_results.dart @@ -7,35 +7,52 @@ import 'package:integration_test/common.dart' show Failure; import 'package:integration_test/integration_test.dart'; import 'package:test_api/hooks.dart' show TestHandle; -/// Records every executed test via the package:test lifecycle (plain `test()` -/// declarations never reach the binding's `results` map - only `testWidgets` -/// does) and publishes them through -/// [IntegrationTestWidgetsFlutterBinding.reportData], the only channel that -/// crosses the wire on web. +bool _reportTestResultsRegistered = false; + +/// Bridges plain `test()` verdicts into [IntegrationTestWidgetsFlutterBinding] +/// so `flutter drive` receives accurate pass/fail results on web. +/// +/// [IntegrationTestWidgetsFlutterBinding] only records failures reported via +/// `flutter_test`'s `reportTestException` hook, which `testWidgets` triggers +/// and plain `test()` never does. Because `package:test_api` runs +/// `tearDownAll` callbacks in reverse registration (LIFO) order, registering +/// `tearDownAll` here after `ensureInitialized()` populates `binding.results` +/// right before the binding's own `tearDownAll` computes `allTestsPassed` from +/// `failureMethodsDetails`. +/// +/// A second call (a suite importing two entrypoints that both call this) +/// would register another [setUp] and report each test twice. void reportTestResultsToDriver(IntegrationTestWidgetsFlutterBinding binding) { - final executed = []; - setUp(() { - executed.add(TestHandle.current.name); - }); + if (_reportTestResultsRegistered) { + return; + } + _reportTestResultsRegistered = true; + final executed = []; + setUp(() => executed.add(TestHandle.current)); tearDownAll(() { - // `TestHandle.current.name` is the full name, prefixed with the enclosing - // group names, while `binding.results` is keyed by the bare `testWidgets` - // description - so match a failed entry on the suffix as well as on - // equality, otherwise no grouped test could ever be marked failed. - final failures = [ - for (final entry in binding.results.entries) - if (entry.value is Failure) entry.key, - ]; - bool didFail(String name) => failures.any( - (failure) => name == failure || name.endsWith(' $failure'), - ); - - binding.reportData ??= {}; - binding.reportData!['testResults'] = { - // Plain test() failures are not individually attributable here, but they - // fail the run as a whole via allTestsPassed; testWidgets failures are - // attributed from the binding's results map. - for (final name in executed) name: didFail(name) ? 'failed' : 'success', - }; + if (executed.isEmpty && binding.failureMethodsDetails.isEmpty) { + binding.results['(suite)'] = Failure( + '(suite)', + 'No tests were executed.', + ); + return; + } + for (final test in executed) { + if (test.shouldBeDone) { + binding.results[test.name] ??= 'success'; + continue; + } + final alreadyRecorded = binding.results.entries.any( + (e) => + e.value is Failure && + (test.name == e.key || test.name.endsWith(' ${e.key}')), + ); + if (!alreadyRecorded) { + binding.results[test.name] = Failure( + test.name, + 'Test failed; see the browser console dump in the flutter drive log.', + ); + } + } }); } diff --git a/tests/test/web_e2e_reporting_test.dart b/tests/test/web_e2e_reporting_test.dart new file mode 100644 index 000000000000..462f6e328aa8 --- /dev/null +++ b/tests/test/web_e2e_reporting_test.dart @@ -0,0 +1,245 @@ +// Copyright 2026, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/common.dart' show Failure, Response; + +void main() { + test( + 'marks failing plain test() as Failure in binding.results and fails allTestsPassed', + () async { + final decoded = await _runBindingProbe(''' + group('suite', () { + test('passing plain test', () { + expect(1, 1); + }); + + test('failing plain test', () { + expect(1, 2); + }); + }); +'''); + + expect(decoded['allTestsPassed'], isFalse); + expect(decoded['failures'], contains('suite failing plain test')); + expect(decoded['failures'], isNot(contains('suite passing plain test'))); + }, + ); + + test('marks suite with zero executed tests as Failure', () async { + final decoded = await _runBindingProbe(''' + test('skipped test', () { + expect(1, 1); + }, skip: 'intentionally skipped'); +'''); + + expect(decoded['allTestsPassed'], isFalse); + expect(decoded['failures'], contains('(suite)')); + }); + + test( + 'driver forwards WebDriver browser console and exits 1 on failure', + () async { + final tempDir = Directory.systemTemp.createTempSync('ff_driver_test_'); + addTearDown(() { + if (tempDir.existsSync()) { + tempDir.deleteSync(recursive: true); + } + }); + + final seLogContentLengths = []; + final appResponseJson = Response.someTestsFailed([ + Failure('suite failing plain test', 'Test failed'), + ]).toJson(); + final driverPayload = jsonEncode({ + 'isError': false, + 'response': {'message': appResponseJson}, + }); + + final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0); + addTearDown(() => server.close(force: true)); + + server.listen((HttpRequest req) async { + final bodyText = await utf8.decoder.bind(req).join(); + req.response.headers.contentType = ContentType.json; + final path = req.uri.path; + if (path.endsWith('/se/log')) { + seLogContentLengths.add(req.headers.contentLength); + req.response.write( + jsonEncode({ + 'value': >[ + { + 'level': 'INFO', + 'message': + 'http://localhost:8080/main.dart.js 1:2 ' + '"00:00 +1 -1: suite failing plain test [E]"', + }, + { + 'level': 'SEVERE', + 'message': + 'https://identitytoolkit.googleapis.com/v1/accounts:' + 'signUp?key=AIzaSyFAKE-not-a-real-key - Failed to load ' + 'resource {"idToken":"eyJhbGciOi.fake.token"}', + }, + ], + }), + ); + } else if (path.endsWith('/execute/sync') || + path.endsWith('/execute')) { + final decoded = jsonDecode(bodyText) as Map; + final script = '${decoded['script']}'; + if (script.contains(r'typeof(window.$flutterDriver)')) { + req.response.write( + jsonEncode({'value': 'function'}), + ); + } else if (script.contains(r'return $flutterDriverResult')) { + req.response.write( + jsonEncode({'value': driverPayload}), + ); + } else { + req.response.write(jsonEncode({'value': null})); + } + } else { + req.response.write(jsonEncode({'value': null})); + } + await req.response.close(); + }); + + final result = await Process.run( + 'dart', + ['run', 'test_driver/integration_test.dart'], + workingDirectory: Directory.current.path, + environment: { + ...Platform.environment, + 'FLUTTER_WEB_TEST': 'true', + 'VM_SERVICE_URL': 'http://127.0.0.1:${server.port}/app', + 'DRIVER_SESSION_ID': 'fake-session', + 'DRIVER_SESSION_URI': 'http://127.0.0.1:${server.port}/', + 'DRIVER_SESSION_CAPABILITIES': '{}', + 'FLUTTER_TEST_OUTPUTS_DIR': tempDir.path, + }, + ); + + final output = '${result.stdout}\n${result.stderr}'; + expect(result.exitCode, 1, reason: output); + expect(seLogContentLengths, isNotEmpty); + expect(seLogContentLengths.first, greaterThan(0)); + expect(output, contains('Failure in method: suite failing plain test')); + expect(output, contains('===== browser console (2 entries) =====')); + expect( + output, + contains('[INFO] 00:00 +1 -1: suite failing plain test [E]'), + ); + // Credentials in chromedriver's fetch-failure entries never reach logs. + expect(output, contains('signUp?key= - Failed to load')); + expect(output, contains('"idToken":""')); + expect(output, isNot(contains('AIzaSyFAKE'))); + expect(output, isNot(contains('eyJhbGciOi'))); + expect(output, isNot(contains('All tests passed.'))); + }, + ); + + test('all 16 report_test_results.dart copies are identical', () { + // The reporter must live next to each app's entrypoint: the web build + // cannot resolve imports above the package root. Keep the copies in + // lockstep instead of sharing a file. + final canonical = File( + '${Directory.current.path}/integration_test/report_test_results.dart', + ); + // Shallow enumeration (no recursive walk through build/ or Pods/, which + // sibling `melos run test` jobs may be writing at the same time). + final packagesDir = Directory('${Directory.current.parent.path}/packages'); + final copies = []; + for (final product in packagesDir.listSync().whereType()) { + for (final package in product.listSync().whereType()) { + for (final app in package.listSync().whereType()) { + for (final rel in [ + 'integration_test/report_test_results.dart', + 'integration_test/pipeline/report_test_results.dart', + ]) { + final copy = File('${app.path}/$rel'); + if (copy.existsSync()) copies.add(copy); + } + } + } + } + copies.sort((a, b) => a.path.compareTo(b.path)); + expect(copies, hasLength(15), reason: copies.map((f) => f.path).join('\n')); + + final expected = _withoutLicenseHeader(canonical.readAsStringSync()); + for (final copy in copies) { + expect( + _withoutLicenseHeader(copy.readAsStringSync()), + expected, + reason: '${copy.path} differs from ${canonical.path}', + ); + } + }); +} + +String _withoutLicenseHeader(String source) => + source.replaceFirst(RegExp(r'^(// Copyright[^\n]*\n(?://[^\n]*\n)*)'), ''); + +Future> _runBindingProbe(String suiteBody) async { + final probeDir = Directory( + '${Directory.current.path}/test', + ).createTempSync('_web_e2e_probe_'); + try { + final probeFile = File('${probeDir.path}/probe_test.dart'); + probeFile.writeAsStringSync(''' +import 'dart:convert'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import '../../integration_test/report_test_results.dart'; + +void main() { + late final IntegrationTestWidgetsFlutterBinding binding; + tearDownAll(() async { + // Registered BEFORE ensureInitialized() so LIFO tearDownAll order runs this + // after both reportTestResultsToDriver and the binding's own tearDownAll. + final passed = await binding.allTestsPassed.future; + final failures = [ + for (final f in binding.failureMethodsDetails) f.methodName, + ]; + final encoded = jsonEncode({ + 'allTestsPassed': passed, + 'failures': failures, + }); + // ignore: avoid_print + print('BINDING_VERDICT:\$encoded'); + }); + binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + reportTestResultsToDriver(binding); + +$suiteBody +} +'''); + + final relProbePath = + 'test/${probeDir.uri.pathSegments.where((s) => s.isNotEmpty).last}' + '/probe_test.dart'; + final result = await Process.run('flutter', [ + 'test', + '--no-pub', + '--reporter=expanded', + relProbePath, + ], workingDirectory: Directory.current.path); + + final combined = '${result.stdout}\n${result.stderr}'; + final match = RegExp(r'BINDING_VERDICT:(\{.*\})').firstMatch(combined); + expect( + match, + isNotNull, + reason: 'Probe did not emit BINDING_VERDICT:\n$combined', + ); + return jsonDecode(match!.group(1)!) as Map; + } finally { + if (probeDir.existsSync()) { + probeDir.deleteSync(recursive: true); + } + } +} diff --git a/tests/test_driver/integration_test.dart b/tests/test_driver/integration_test.dart index 9ccbcc26ab97..0a9571fc4562 100644 --- a/tests/test_driver/integration_test.dart +++ b/tests/test_driver/integration_test.dart @@ -2,37 +2,100 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// This is a CLI program run by `flutter drive`; printing is its interface. +// ignore_for_file: avoid_print + +import 'dart:convert'; import 'dart:io'; import 'package:integration_test/integration_test_driver.dart'; -Future main() => integrationDriver( - writeResponseOnFailure: true, - responseDataCallback: (Map? data) async { - final results = - (data?['testResults'] as Map?)?.cast() ?? - const {}; - var passed = 0; - var failed = 0; - for (final entry in results.entries) { - final ok = entry.value == 'success'; - ok ? passed++ : failed++; - // ignore: avoid_print - print('${ok ? '✅' : '❌'} ${entry.key}'); - } - // ignore: avoid_print - print( - 'Web e2e summary: $passed passed, $failed failed, ' - '${results.length} total', +/// Shared `flutter drive` entrypoint for FlutterFire web e2e suites. +/// +/// Verdicts and exit codes come natively from [integrationDriver] (populated +/// via `reportTestResultsToDriver`); this wrapper additionally drains the +/// WebDriver browser console so assertion messages and `[E]` lines appear in CI +/// logs under `-d web-server`, including when the driver never got a result +/// from the app (startup crash, connection failure, timeout). +Future main() async { + try { + await integrationDriver( + writeResponseOnFailure: true, + responseDataCallback: (Map? data) async { + await _printBrowserConsole(); + await writeResponseData(data); + }, + ); + } catch (_) { + // integrationDriver exits the process on both verdicts, so this only runs + // when connecting to the app or requesting its result failed. + await _printBrowserConsole(); + rethrow; + } +} + +const Duration _webDriverTimeout = Duration(seconds: 30); + +/// Query-string and token values that must not reach public CI logs: the live +/// tier runs with real project credentials and chromedriver logs failed +/// fetches with their full URL. +final RegExp _secretValue = RegExp( + r'([?&](?:key|access_token|id_token|refresh_token|oobCode)=)[^&\s"]+', +); +final RegExp _secretField = RegExp( + r'("(?:idToken|refreshToken|accessToken|oauthAccessToken)"\s*:\s*")[^"]+', +); + +Future _printBrowserConsole() async { + final sessionId = Platform.environment['DRIVER_SESSION_ID']; + final sessionUri = Platform.environment['DRIVER_SESSION_URI']; + if (sessionId == null || sessionUri == null) { + return; + } + final client = HttpClient()..connectionTimeout = const Duration(seconds: 10); + try { + // chromedriver rejects chunked request bodies, so set Content-Length. + final body = utf8.encode(jsonEncode({'type': 'browser'})); + final request = await client + .postUrl(Uri.parse(sessionUri).resolve('session/$sessionId/se/log')) + .timeout(_webDriverTimeout); + request.headers.contentType = ContentType.json; + request.headers.contentLength = body.length; + request.add(body); + final response = await request.close().timeout(_webDriverTimeout); + final decoded = jsonDecode( + await response.transform(utf8.decoder).join().timeout(_webDriverTimeout), ); - if (results.isEmpty) { - // ignore: avoid_print + final entries = + ((decoded as Map)['value'] as List?) ?? + const []; + print('===== browser console (${entries.length} entries) ====='); + for (final entry in entries.cast>()) { print( - '[E] No tests reported by the app - treating as ' - 'infrastructure failure.', + '[${entry['level']}] ${_redact(_consoleText('${entry['message']}'))}', ); - exit(1); } - await writeResponseData(data); - }, -); + print('===== end of browser console ====='); + } catch (error) { + print('Could not read the browser console: $error'); + } finally { + client.close(force: true); + } +} + +String _redact(String text) => text + .replaceAllMapped(_secretValue, (m) => '${m[1]}') + .replaceAllMapped(_secretField, (m) => '${m[1]}'); + +String _consoleText(String message) { + final match = RegExp(r'^\S+ \d+:\d+ (.*)$', dotAll: true).firstMatch(message); + final text = match?.group(1) ?? message; + if (text.length >= 2 && text.startsWith('"') && text.endsWith('"')) { + try { + return jsonDecode(text) as String; + } on FormatException { + return text; + } + } + return text; +}