Repository navigation
test(e2e): make web e2e verdicts trustworthy for plain test() suites - #19023
jonathanedey wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
Code Review
This pull request refactors and consolidates the web end-to-end (e2e) test reporting mechanism across multiple Firebase packages. It replaces duplicate test drivers with a single shared driver at tests/test_driver/integration_test.dart that drains and redacts credentials from WebDriver browser console logs upon failure. It also updates the test reporting logic to correctly bridge plain test() results to the integration test binding. Feedback on the changes suggests adding safe type checks when parsing WebDriver responses and decoding console messages in the shared driver to prevent TypeError crashes, as well as making path resolution in the new reporting tests robust to being run from the workspace root.
| final entries = | ||
| ((decoded as Map<dynamic, dynamic>)['value'] as List<dynamic>?) ?? | ||
| const <dynamic>[]; |
There was a problem hiding this comment.
To prevent potential TypeError exceptions if the WebDriver response is malformed, null, or not a JSON Map, use a safe type check before casting and accessing the value field.
| final entries = | |
| ((decoded as Map<dynamic, dynamic>)['value'] as List<dynamic>?) ?? | |
| const <dynamic>[]; | |
| final entries = (decoded is Map && decoded['value'] is List) | |
| ? (decoded['value'] as List<dynamic>) | |
| : const <dynamic>[]; |
| 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'); |
There was a problem hiding this comment.
The test currently assumes that the working directory is strictly the tests package directory. If run from the workspace root (a very common workflow in monorepos), Directory.current will point to the root, causing the test to fail because it cannot find the paths. We can make the path resolution robust to the current working directory by checking if we are at the workspace root or the package root. Note that other occurrences of Directory.current.path in this file (such as in _runBindingProbe and the process execution) should also be updated to use testsPackagePath for complete robustness.
final isAtRoot = Directory('${Directory.current.path}/packages').existsSync();
final workspaceRootPath = isAtRoot ? Directory.current.path : Directory.current.parent.path;
final testsPackagePath = isAtRoot ? '${Directory.current.path}/tests' : Directory.current.path;
final canonical = File(
'$testsPackagePath/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('$workspaceRootPath/packages');| final text = match?.group(1) ?? message; | ||
| if (text.length >= 2 && text.startsWith('"') && text.endsWith('"')) { | ||
| try { | ||
| return jsonDecode(text) as String; |
There was a problem hiding this comment.
Perform a safe type check on the decoded JSON value to ensure it is indeed a String before returning, avoiding potential TypeError crashes if the console message decodes to a different type.
| return jsonDecode(text) as String; | |
| final decoded = jsonDecode(text); | |
| return decoded is String ? decoded : text; |
Description
On web,
flutter drive -d web-serverexits 0 for suites whose plaintest()cases fail:IntegrationTestWidgetsFlutterBindingonly recordstestWidgetsfailures (viareportTestException), soallTestsPassedis 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 intests/test) now records aFailureinbinding.resultsfor every executed test whoseTestHandle.shouldBeDoneis false, and for a suite that executed nothing, so the stockintegrationDriververdict 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 nativeallTestsFinishedpayload, whereflutter 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.flutter driveentrypoint is shared: the 15 per-apptest_driver/integration_test.dartcopies are deleted and CI/Melos point--driverattests/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 theflutter drivelog.Checklist
///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?