Skip to content

test(e2e): make web e2e verdicts trustworthy for plain test() suites - #19023

Draft
jonathanedey wants to merge 1 commit into
mainfrom
agent/web-e2e-reporting-gap
Draft

jonathanedey wants to merge 1 commit into
mainfrom
agent/web-e2e-reporting-gap

Conversation

@jonathanedey

Copy link
Copy Markdown
Contributor

Description

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.
  • Product e2e workflows also trigger on changes to the shared driver.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +69 to +71
final entries =
((decoded as Map<dynamic, dynamic>)['value'] as List<dynamic>?) ??
const <dynamic>[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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>[];

Comment on lines +150 to +155
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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

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.

Suggested change
return jsonDecode(text) as String;
final decoded = jsonDecode(text);
return decoded is String ? decoded : text;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant