diff --git a/.github/workflows/e2e_tests.yaml b/.github/workflows/e2e_tests.yaml index 2083bdf3e82e..7898b43a3573 100644 --- a/.github/workflows/e2e_tests.yaml +++ b/.github/workflows/e2e_tests.yaml @@ -237,6 +237,8 @@ jobs: runs-on: macos-latest timeout-minutes: 15 strategy: + # Temp measure for testing web tests. Please remove as soon as e2e tests are stable. + fail-fast: false matrix: working_directory: ['tests', 'packages/cloud_firestore/cloud_firestore/example'] diff --git a/packages/_flutterfire_internals/lib/_flutterfire_internals.dart b/packages/_flutterfire_internals/lib/_flutterfire_internals.dart index 01c8931b6d58..81cc3079a56c 100644 --- a/packages/_flutterfire_internals/lib/_flutterfire_internals.dart +++ b/packages/_flutterfire_internals/lib/_flutterfire_internals.dart @@ -82,7 +82,9 @@ bool _testException(Object? objectException) { final exception = objectException! as core_interop.JSError; // ignore: unnecessary_cast final message = exception.message as String; - return message.contains('Firebase'); + // Firestore web does not contain `Firebase` in the message so we check the exception itself. + return message.contains('Firebase') || + exception.toString().contains('FirebaseError'); } /// Transforms internal errors in something more readable for end-users. diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart index d582f5bee789..5813804e63b2 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/document_reference_e2e.dart @@ -172,8 +172,6 @@ void runDocumentReferenceTests() { fail('Should have thrown a [FirebaseException]'); }); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); group('DocumentReference.delete()', () { @@ -255,9 +253,7 @@ void runDocumentReferenceTests() { return; } fail('Should have thrown a [FirebaseException]'); - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 }, - skip: kIsWeb, ); }); @@ -320,7 +316,6 @@ void runDocumentReferenceTests() { equals({'foo': 'bar', 'bar': 456, 'baz': 'foo'}), ); }, - skip: kIsWeb, ); testWidgets( @@ -340,9 +335,7 @@ void runDocumentReferenceTests() { return; } fail('Should have thrown a [FirebaseException]'); - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 }, - skip: kIsWeb, ); testWidgets('set and return all possible datatypes', (_) async { @@ -513,8 +506,6 @@ void runDocumentReferenceTests() { ); } }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); }); diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/load_bundle_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/load_bundle_e2e.dart index f38c375adbdc..a5859d019a39 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/load_bundle_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/load_bundle_e2e.dart @@ -97,9 +97,7 @@ void runLoadBundleTests() { .having((e) => e.code, 'code', 'load-bundle-error'), ), ); - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 }, - skip: kIsWeb, ); testWidgets( @@ -181,16 +179,13 @@ void runLoadBundleTests() { 'wrong-name', options: const GetOptions(source: Source.cache), ), - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - // expect(error, isA()); throwsA( isA() .having((e) => e.code, 'code', 'non-existent-named-query'), ), ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows, + skip: defaultTargetPlatform == TargetPlatform.windows, ); }); @@ -241,8 +236,7 @@ void runLoadBundleTests() { ), ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows, + skip: defaultTargetPlatform == TargetPlatform.windows, ); }); }); diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart index b5d3a4b95306..92a7d9806ea0 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart @@ -7,7 +7,6 @@ import 'dart:math'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; void runQueryTests() { @@ -210,8 +209,6 @@ void runQueryTests() { } fail('Should have thrown a [FirebaseException]'); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); testWidgets( @@ -234,8 +231,6 @@ void runQueryTests() { ); } }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); }); @@ -378,9 +373,7 @@ void runQueryTests() { } fail('Should have thrown a [FirebaseException]'); - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 }, - skip: kIsWeb, ); }); @@ -2221,8 +2214,8 @@ void runQueryTests() { CollectionReference> collection = await initializeTest('multiple-conjunctive-queries'); - try { - await collection + await expectLater( + collection .where( Filter.and( Filter('rating1', isEqualTo: 3.8), @@ -2259,22 +2252,13 @@ void runQueryTests() { ), ) .orderBy('rating1', descending: true) - .get(); - } catch (e) { - expect( - (e as FirebaseException) - .message! - .contains('Client specified an invalid argument.') || - e.message!.contains( - 'An error occurred while parsing query arguments', - ), - isTrue, - ); - expect(e, isA()); - } + .get(), + throwsA( + isA() + .having((e) => e.code, 'code', 'invalid-argument'), + ), + ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); testWidgets('allow multiple disjunctive queries', (_) async { @@ -2398,8 +2382,8 @@ void runQueryTests() { CollectionReference> collection = await initializeTest('multiple-disjunctive-queries'); - try { - await collection + await expectLater( + collection .where( Filter.or( Filter('rating', isEqualTo: 3.8), @@ -2442,22 +2426,13 @@ void runQueryTests() { ), ) .orderBy('rating', descending: true) - .get(); - } catch (e) { - expect( - (e as FirebaseException) - .message! - .contains('Client specified an invalid argument.') || - e.message!.contains( - 'An error occurred while parsing query arguments', - ), - isTrue, - ); - expect(e, isA()); - } + .get(), + throwsA( + isA() + .having((e) => e.code, 'code', 'invalid-argument'), + ), + ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); testWidgets( diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/second_app_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/second_app_e2e.dart index 0f1b3539100e..73a853071869 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/second_app_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/second_app_e2e.dart @@ -47,8 +47,7 @@ void runSecondAppTests() { ), ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows, + skip: defaultTargetPlatform == TargetPlatform.windows, ); }, ); diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/second_database.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/second_database.dart index 80197b2de3fc..f3d5c08e12e6 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/second_database.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/second_database.dart @@ -49,10 +49,11 @@ void runSecondDatabaseTests() { ); QuerySnapshot> snapshot = await collection.get(); - await Future.forEach(snapshot.docs, - (QueryDocumentSnapshot> documentSnapshot) { + List deleteFutures = snapshot.docs.map((documentSnapshot) { return documentSnapshot.reference.delete(); - }); + }).toList(); + + await Future.wait(deleteFutures); return collection; } @@ -185,8 +186,6 @@ void runSecondDatabaseTests() { } fail('Should have thrown a [FirebaseException]'); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); }); @@ -332,9 +331,7 @@ void runSecondDatabaseTests() { } fail('Should have thrown a [FirebaseException]'); - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 }, - skip: kIsWeb, ); }); @@ -1772,8 +1769,8 @@ void runSecondDatabaseTests() { CollectionReference> collection = await initializeTest('multiple-conjunctive-queries'); - try { - await collection + await expectLater( + collection .where( Filter.and( Filter('rating1', isEqualTo: 3.8), @@ -1810,22 +1807,13 @@ void runSecondDatabaseTests() { ), ) .orderBy('rating1', descending: true) - .get(); - } catch (e) { - expect( - (e as FirebaseException) - .message! - .contains('Client specified an invalid argument.') || - e.message!.contains( - 'An error occurred while parsing query arguments', - ), - isTrue, - ); - expect(e, isA()); - } + .get(), + throwsA( + isA() + .having((e) => e.code, 'code', 'invalid-argument'), + ), + ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); testWidgets( @@ -1834,8 +1822,8 @@ void runSecondDatabaseTests() { CollectionReference> collection = await initializeTest('multiple-disjunctive-queries'); - try { - await collection + await expectLater( + collection .where( Filter.or( Filter('rating', isEqualTo: 3.8), @@ -1878,22 +1866,13 @@ void runSecondDatabaseTests() { ), ) .orderBy('rating', descending: true) - .get(); - } catch (e) { - expect( - (e as FirebaseException) - .message! - .contains('Client specified an invalid argument.') || - e.message!.contains( - 'An error occurred while parsing query arguments', - ), - isTrue, - ); - expect(e, isA()); - } + .get(), + throwsA( + isA() + .having((e) => e.code, 'code', 'invalid-argument'), + ), + ); }, - // This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572 - skip: kIsWeb, ); testWidgets('isEqualTo filter', (_) async { diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/write_batch_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/write_batch_e2e.dart index 5a727194cf82..49abaaa407a7 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/write_batch_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/write_batch_e2e.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; void runWriteBatchTests() { @@ -100,14 +99,11 @@ void runWriteBatchTests() { batch.update(doc3, {'bar': 'ben'}); batch.set(doc4, {'bar': 'ben'}, SetOptions(merge: true)); - // TODO(ehesp): firebase-dart does not support mergeFields - if (!kIsWeb) { - batch.set( - doc5, - {'bar': 'ben'}, - SetOptions(mergeFields: ['bar']), - ); - } + batch.set( + doc5, + {'bar': 'ben'}, + SetOptions(mergeFields: ['bar']), + ); await batch.commit(); @@ -127,14 +123,11 @@ void runWriteBatchTests() { snapshot.docs.firstWhere((doc) => doc.id == 'doc4').data(), equals({'foo': 'bar', 'bar': 'ben'}), ); - // ignore: todo - // TODO(ehesp): firebase-dart does not support mergeFields - if (!kIsWeb) { - expect( - snapshot.docs.firstWhere((doc) => doc.id == 'doc5').data(), - equals({'foo': 'bar', 'bar': 'ben'}), - ); - } + + expect( + snapshot.docs.firstWhere((doc) => doc.id == 'doc5').data(), + equals({'foo': 'bar', 'bar': 'ben'}), + ); }); }); } diff --git a/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart b/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart index b84bf8c2e90f..2b9030895352 100644 --- a/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart +++ b/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart @@ -239,7 +239,9 @@ class LoadBundleTaskProgress LoadBundleTaskProgress._fromJsObject( firestore_interop.LoadBundleTaskProgressJsImpl jsObject, ) : taskState = convertToTaskState(jsObject.taskState.toDart.toLowerCase()), - bytesLoaded = jsObject.bytesLoaded.toDartInt, + bytesLoaded = jsObject.bytesLoaded is JSNumber + ? (jsObject.bytesLoaded as JSNumber).toDartInt + : int.parse((jsObject.bytesLoaded as JSString).toDart), documentsLoaded = jsObject.documentsLoaded.toDartInt, totalBytes = jsObject.totalBytes is JSNumber ? (jsObject.totalBytes as JSNumber).toDartInt diff --git a/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore_interop.dart b/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore_interop.dart index ca3099e4adb7..be4e852f2922 100644 --- a/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore_interop.dart +++ b/packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore_interop.dart @@ -505,7 +505,8 @@ abstract class LoadBundleTaskProgressJsImpl {} extension LoadBundleTaskProgressJsImplExtension on LoadBundleTaskProgressJsImpl { - external JSNumber get bytesLoaded; +// int or String? + external JSAny get bytesLoaded; external JSNumber get documentsLoaded; diff --git a/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/web_utils.dart b/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/web_utils.dart index 9c60bff9c1f6..660962a6ff92 100644 --- a/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/web_utils.dart +++ b/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/web_utils.dart @@ -10,7 +10,7 @@ import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_inte import '../interop/firestore.dart' as firestore_interop; import '../interop/firestore_interop.dart' hide GetOptions, SetOptions, FieldPath; -import '../utils/decode_utility.dart'; +import './decode_utility.dart'; const _kChangeTypeAdded = 'added'; const _kChangeTypeModified = 'modified'; @@ -148,10 +148,11 @@ firestore_interop.SetOptions? convertSetOptions(SetOptions? options) { parsedOptions = firestore_interop.SetOptions(merge: options.merge?.toJS); } else if (options.mergeFields != null) { parsedOptions = firestore_interop.SetOptions( - mergeFields: options.mergeFields! - .map((e) => e.components.toList().join('.').toJS) - .toList() - .toJSBox as JSArray); + mergeFields: options.mergeFields! + .map((e) => e.components.toList().join('.').toJS) + .toList() + .toJS, + ); } return parsedOptions;