Skip to content

Commit

Permalink
Merge branch 'main' into firestore-13289
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Nov 19, 2024
2 parents 5c563ce + 1ef2044 commit 4355ea4
Show file tree
Hide file tree
Showing 27 changed files with 605 additions and 554 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ jobs:
ccache -s
- name: Start Firebase Emulator
run: sudo chown -R 501:20 "/Users/runner/.npm" && cd ./.github/workflows/scripts && ./start-firebase-emulator.sh
- uses: futureware-tech/simulator-action@48e51da14445b3eedca643bba4b78d9d8332ff31
id: simulator
with:
# List of available simulators: https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md#installed-simulators
model: "iPhone 15"
- name: 'E2E Tests'
working-directory: ${{ matrix.working_directory }}
env:
SIMULATOR: ${{ steps.simulator.outputs.udid }}
run: |
# Boot simulator and wait for System app to be ready.
# List of available simulators: https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md#installed-simulators
SIMULATOR="iPhone 15"
xcrun simctl bootstatus "$SIMULATOR" -b
xcrun simctl logverbose "$SIMULATOR" enable
# Sleep to allow simulator to settle.
sleep 15
# Uncomment following line to have simulator logs printed out for debugging purposes.
# xcrun simctl spawn booted log stream --predicate 'eventMessage contains "flutter"' &
flutter test integration_test/e2e_test.dart -d "$SIMULATOR" --dart-define=CI=true
2 changes: 1 addition & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ scripts:
test:e2e:web:
run: |
melos exec -c 1 --fail-fast -- \
"flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome --dart-define=APP_CHECK_E2E=true"
"flutter drive --target=./integration_test/e2e_test.dart --driver=./test_driver/integration_test.dart -d chrome --dart-define=LOCAL_WEB_E2E=true"
description: |
Run all e2e tests on web platform. Please ensure you have "chromedriver" installed and running.
packageFilters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ protected static void setCachedFirebaseFirestoreInstanceForKey(

protected static FirebaseFirestore getFirestoreInstanceByNameAndDatabaseUrl(
String appName, String databaseURL) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
if (entry.getValue().getInstance().getApp().getName().equals(appName)
&& entry.getValue().getDatabaseURL().equals(databaseURL)) {
return entry.getKey();
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
if (entry.getValue().getInstance().getApp().getName().equals(appName)
&& entry.getValue().getDatabaseURL().equals(databaseURL)) {
return entry.getKey();
}
}
}
return null;
Expand Down Expand Up @@ -200,12 +202,14 @@ public Task<Void> didReinitializeFirebaseCore() {
() -> {
try {
// Context is ignored by API so we don't send it over even though annotated non-null.
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
firestore);
synchronized (firestoreInstanceCache) {
for (Map.Entry<FirebaseFirestore, FlutterFirebaseFirestoreExtension> entry :
firestoreInstanceCache.entrySet()) {
FirebaseFirestore firestore = entry.getKey();
Tasks.await(firestore.terminate());
FlutterFirebaseFirestorePlugin.destroyCachedFirebaseFirestoreInstanceForKey(
firestore);
}
}
removeEventListeners();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void runCollectionReferenceTests() {
return collection;
}

testWidgets('add() adds a document', (_) async {
test('add() adds a document', () async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('collection-reference-add');
var rand = Random();
Expand All @@ -42,9 +42,9 @@ void runCollectionReferenceTests() {
expect(randNum, equals(snapshot.data()!['value']));
});

testWidgets(
test(
'snapshots() can be reused',
(_) async {
() async {
final foo = await initializeTest('foo');

final snapshot = foo.snapshots();
Expand Down Expand Up @@ -86,9 +86,9 @@ void runCollectionReferenceTests() {
group(
'withConverter',
() {
testWidgets(
test(
'add/snapshot',
(_) async {
() async {
final foo = await initializeTest('foo');
final fooConverter = foo.withConverter<int>(
fromFirestore: (snapshots, _) =>
Expand Down Expand Up @@ -179,9 +179,9 @@ void runCollectionReferenceTests() {
timeout: const Timeout.factor(3),
);

testWidgets(
test(
'returning null from `fromFirestore` should not throw a null check error',
(_) async {
() async {
final foo = await initializeTest('foo');
await foo.add({'value': 42});
final fooConverter = foo.withConverter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void runDocumentChangeTests() {
return collection;
}

testWidgets(
test(
'can add/update values to null in the document',
(_) async {
() async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('null-test');
DocumentReference<Map<String, dynamic>> doc1 = collection.doc('doc1');
Expand Down Expand Up @@ -84,9 +84,9 @@ void runDocumentChangeTests() {
skip: defaultTargetPlatform == TargetPlatform.windows,
);

testWidgets(
test(
'returns the correct metadata when adding and removing',
(_) async {
() async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('add-remove-document');
DocumentReference<Map<String, dynamic>> doc1 = collection.doc('doc1');
Expand Down Expand Up @@ -141,9 +141,9 @@ void runDocumentChangeTests() {
skip: defaultTargetPlatform == TargetPlatform.windows,
);

testWidgets(
test(
'returns the correct metadata when modifying',
(_) async {
() async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('add-modify-document');
DocumentReference<Map<String, dynamic>> doc1 = collection.doc('doc1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ void runDocumentReferenceTests() {
group(
'DocumentReference.snapshots()',
() {
testWidgets('returns a [Stream]', (_) async {
test('returns a [Stream]', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-snapshot');
Stream<DocumentSnapshot<Map<String, dynamic>>> stream =
document.snapshots();
expect(stream, isA<Stream<DocumentSnapshot<Map<String, dynamic>>>>());
});

testWidgets('can be reused', (_) async {
test('can be reused', () async {
final foo = await initializeTest('foo');

final snapshot = foo.snapshots();
Expand Down Expand Up @@ -66,7 +66,7 @@ void runDocumentReferenceTests() {
);
});

testWidgets('listens to a single response', (_) async {
test('listens to a single response', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-snapshot');
Stream<DocumentSnapshot<Map<String, dynamic>>> stream =
Expand All @@ -88,7 +88,7 @@ void runDocumentReferenceTests() {
});
});

testWidgets('listens to a single response from cache', (_) async {
test('listens to a single response from cache', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-snapshot');
Stream<DocumentSnapshot<Map<String, dynamic>>> stream =
Expand All @@ -110,7 +110,7 @@ void runDocumentReferenceTests() {
});
});

testWidgets('listens to a document from cache', (_) async {
test('listens to a document from cache', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-snapshot-cache');
await document.set({'foo': 'bar'});
Expand All @@ -134,7 +134,7 @@ void runDocumentReferenceTests() {
});
});

testWidgets('listens to multiple documents', (_) async {
test('listens to multiple documents', () async {
DocumentReference<Map<String, dynamic>> doc1 =
await initializeTest('document-snapshot-1');
DocumentReference<Map<String, dynamic>> doc2 =
Expand All @@ -150,7 +150,7 @@ void runDocumentReferenceTests() {
await expectLater(value2, completion('value2'));
});

testWidgets('listens to a multiple changes response', (_) async {
test('listens to a multiple changes response', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-snapshot-multiple');
Stream<DocumentSnapshot<Map<String, dynamic>>> stream =
Expand Down Expand Up @@ -197,7 +197,7 @@ void runDocumentReferenceTests() {
);
});

testWidgets('listeners throws a [FirebaseException]', (_) async {
test('listeners throws a [FirebaseException]', () async {
DocumentReference<Map<String, dynamic>> document =
firestore.doc('not-allowed/document');
Stream<DocumentSnapshot<Map<String, dynamic>>> stream =
Expand All @@ -220,7 +220,7 @@ void runDocumentReferenceTests() {
);

group('DocumentReference.delete()', () {
testWidgets('delete() deletes a document', (_) async {
test('delete() deletes a document', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-delete');
await document.set({
Expand All @@ -233,9 +233,9 @@ void runDocumentReferenceTests() {
expect(snapshot2.exists, isFalse);
});

testWidgets(
test(
'throws a [FirebaseException] on error',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
firestore.doc('not-allowed/document');

Expand All @@ -257,7 +257,7 @@ void runDocumentReferenceTests() {
});

group('DocumentReference.get()', () {
testWidgets('gets a document from server', (_) async {
test('gets a document from server', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-get-server');
await document.set({'foo': 'bar'});
Expand All @@ -267,9 +267,9 @@ void runDocumentReferenceTests() {
expect(snapshot.metadata.isFromCache, isFalse);
});

testWidgets(
test(
'gets a document from cache',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-get-cache');
await document.set({'foo': 'bar'});
Expand All @@ -281,9 +281,9 @@ void runDocumentReferenceTests() {
skip: kIsWeb,
);

testWidgets(
test(
'throws a [FirebaseException] on error',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
firestore.doc('not-allowed/document');

Expand All @@ -303,7 +303,7 @@ void runDocumentReferenceTests() {
});

group('DocumentReference.set()', () {
testWidgets('sets data', (_) async {
test('sets data', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-set');
await document.set({'foo': 'bar'});
Expand All @@ -314,7 +314,7 @@ void runDocumentReferenceTests() {
expect(snapshot2.data(), equals({'bar': 'baz'}));
});

testWidgets('set() merges data', (_) async {
test('set() merges data', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-set-merge');
await document.set({'foo': 'bar'});
Expand All @@ -326,9 +326,9 @@ void runDocumentReferenceTests() {
expect(snapshot2.data(), equals({'foo': 'ben', 'bar': 'baz'}));
});

testWidgets(
test(
'set() merges fields',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-set-merge-fields');
Map<String, dynamic> initialData = {
Expand Down Expand Up @@ -363,9 +363,9 @@ void runDocumentReferenceTests() {
},
);

testWidgets(
test(
'throws a [FirebaseException] on error',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
firestore.doc('not-allowed/document');

Expand All @@ -383,7 +383,7 @@ void runDocumentReferenceTests() {
},
);

testWidgets('set and return all possible datatypes', (_) async {
test('set and return all possible datatypes', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-types');

Expand Down Expand Up @@ -453,7 +453,7 @@ void runDocumentReferenceTests() {
});

group('DocumentReference.update()', () {
testWidgets('updates data', (_) async {
test('updates data', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-update');
await document.set({'foo': 'bar'});
Expand All @@ -464,7 +464,7 @@ void runDocumentReferenceTests() {
expect(snapshot2.data(), equals({'foo': 'bar', 'bar': 'baz'}));
});

testWidgets('updates nested data using dots', (_) async {
test('updates nested data using dots', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-update-field-path');
await document.set({
Expand All @@ -488,7 +488,7 @@ void runDocumentReferenceTests() {
);
});

testWidgets('updates nested data using FieldPath', (_) async {
test('updates nested data using FieldPath', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-update-field-path');
await document.set({
Expand All @@ -514,8 +514,7 @@ void runDocumentReferenceTests() {
);
});

testWidgets('updates nested data containing a dot using FieldPath',
(_) async {
test('updates nested data containing a dot using FieldPath', () async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-update-field-path');
await document.set({'foo.bar': 'baz'});
Expand All @@ -535,9 +534,9 @@ void runDocumentReferenceTests() {
);
});

testWidgets(
test(
'throws if document does not exist',
(_) async {
() async {
DocumentReference<Map<String, dynamic>> document =
await initializeTest('document-update-not-exists');
try {
Expand All @@ -555,9 +554,9 @@ void runDocumentReferenceTests() {
});

group('withConverter', () {
testWidgets(
test(
'set/snapshot/get',
(_) async {
() async {
final foo = await initializeTest('foo');
final fooConverter = foo.withConverter<int>(
fromFirestore: (snapshots, _) => snapshots.data()!['value']! as int,
Expand Down
Loading

0 comments on commit 4355ea4

Please sign in to comment.