Skip to content

Commit 8916e19

Browse files
committed
test(firestore, e2e): de-flake more firestore tests
one in particular was enabled and failing CI, the rest should work now that I correctly handle callback delay and local firestore persistence by using random collections
1 parent 96f17a7 commit 8916e19

File tree

6 files changed

+64
-35
lines changed

6 files changed

+64
-35
lines changed

packages/firestore/e2e/DocumentSnapshot/data.e2e.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ describe('firestore().doc() -> snapshot.data()', function () {
5151
await ref.delete();
5252
});
5353

54-
xit('handles SnapshotOptions', function () {
55-
// TODO
56-
});
54+
// it('handles SnapshotOptions', function () {
55+
// // TODO
56+
// });
5757

5858
it('handles all data types', async function () {
5959
const types = {

packages/firestore/e2e/Query/endBefore.e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('firestore().collection().endBefore()', function () {
101101
qs.docs[0].id.should.eql('doc3');
102102
});
103103

104-
xit('ends before snapshot field values', async function () {
104+
it('ends before snapshot field values', async function () {
105105
const colRef = firebase.firestore().collection(`${COLLECTION}/endBefore/snapshotFields`);
106106
const doc1 = colRef.doc('doc1');
107107
const doc2 = colRef.doc('doc2');

packages/firestore/e2e/Query/limitToLast.e2e.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@ describe('firestore().collection().limitToLast()', function () {
4343
should(colRef._modifiers.options.limit).equal(undefined);
4444
});
4545

46-
// FIXME flaky on local tests
47-
xit('removes limitToLast query if limit is set afterwards', function () {
48-
const colRef = firebase.firestore().collection(COLLECTION).limitToLast(123).limit(2);
46+
it('removes limitToLast query if limit is set afterwards', function () {
47+
const colRef = firebase
48+
.firestore()
49+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
50+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
51+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/limitToLast-limit-after`);
52+
const colRef2 = colRef.limitToLast(123).limit(2);
4953

50-
should(colRef._modifiers.options.limitToLast).equal(undefined);
54+
should(colRef2._modifiers.options.limitToLast).equal(undefined);
5155
});
5256

53-
// FIXME flaky on local tests
54-
xit('limitToLast the number of documents', async function () {
55-
const subCol = `${COLLECTION}/limitToLast/count`;
57+
it('limitToLast the number of documents', async function () {
58+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
59+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
60+
const subCol = `${COLLECTION}/${Utils.randString(12, '#aA')}/limitToLast-count`;
5661
const colRef = firebase.firestore().collection(subCol);
5762

5863
// Add 3

packages/firestore/e2e/Query/onSnapshot.e2e.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ describe('firestore().collection().onSnapshot()', function () {
173173
it('calls next with snapshot when successful', async function () {
174174
const onNext = sinon.spy();
175175
const onError = sinon.spy();
176-
const unsub = firebase.firestore().collection(`${COLLECTION}/foo/bar6`).onSnapshot(
176+
const colRef = firebase
177+
.firestore()
178+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
179+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
180+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/next-with-snapshot`);
181+
const unsub = colRef.onSnapshot(
177182
{
178183
includeMetadataChanges: false,
179184
},
@@ -297,18 +302,23 @@ describe('firestore().collection().onSnapshot()', function () {
297302

298303
// FIXME test disabled due to flakiness in CI E2E tests.
299304
// Registered 4 of 3 expected calls once (!?), 3 of 2 expected calls once.
300-
xit('unsubscribes from further updates', async function () {
305+
it('unsubscribes from further updates', async function () {
301306
const callback = sinon.spy();
302307

303-
const collection = firebase.firestore().collection(`${COLLECTION}/foo/bar7`);
308+
const collection = firebase
309+
.firestore()
310+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
311+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
312+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/unsubscribe-updates`);
304313

305314
const unsub = collection.onSnapshot(callback);
306-
await Utils.sleep(800);
315+
await Utils.sleep(2000);
307316
await collection.add({});
308317
await collection.add({});
309318
unsub();
310-
await Utils.sleep(800);
319+
await Utils.sleep(2000);
311320
await collection.add({});
321+
await Utils.sleep(2000);
312322
callback.should.be.callCount(3);
313323
});
314324
});

packages/firestore/e2e/Query/orderBy.e2e.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ describe('firestore().collection().orderBy()', function () {
8888
}
8989
});
9090

91-
// FIXME flaky in local tests
92-
xit('orders by a value ASC', async function () {
93-
const colRef = firebase.firestore().collection(`${COLLECTION}/order/asc`);
91+
it('orders by a value ASC', async function () {
92+
const colRef = firebase
93+
.firestore()
94+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
95+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
96+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/order-asc`);
9497

9598
await colRef.add({ value: 1 });
9699
await colRef.add({ value: 3 });
@@ -104,9 +107,12 @@ describe('firestore().collection().orderBy()', function () {
104107
});
105108
});
106109

107-
// FIXME flaky in local tests
108-
xit('orders by a value DESC', async function () {
109-
const colRef = firebase.firestore().collection(`${COLLECTION}/order/desc`);
110+
it('orders by a value DESC', async function () {
111+
const colRef = firebase
112+
.firestore()
113+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
114+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
115+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/order-desc`);
110116

111117
await colRef.add({ value: 1 });
112118
await colRef.add({ value: 3 });

packages/firestore/e2e/QuerySnapshot.e2e.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,21 @@ describe('firestore.QuerySnapshot', function () {
125125

126126
it('returns an array of DocumentChange instances', async function () {
127127
const colRef = firebase.firestore().collection(COLLECTION);
128-
colRef.add({});
128+
await colRef.add({});
129129
const snapshot = await colRef.limit(1).get();
130130
const changes = snapshot.docChanges();
131131
changes.should.be.Array();
132132
changes.length.should.be.eql(1);
133133
changes[0].constructor.name.should.eql('FirestoreDocumentChange');
134134
});
135135

136-
// TODO: fixme @ehesp - flaky test: `AssertionError: expected 3 to equal 1` on line 155
137-
xit('returns the correct number of document changes if listening to metadata changes', async function () {
136+
it('returns the correct number of document changes if listening to metadata changes', async function () {
138137
const callback = sinon.spy();
139-
const colRef = firebase.firestore().collection('v6/metadatachanges/true-true');
138+
const colRef = firebase
139+
.firestore()
140+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
141+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
142+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/metadatachanges-true-true`);
140143
const unsub = colRef.onSnapshot({ includeMetadataChanges: true }, callback);
141144
await colRef.add({ foo: 'bar' });
142145
await Utils.spyToBeCalledTimesAsync(callback, 3);
@@ -151,10 +154,13 @@ describe('firestore.QuerySnapshot', function () {
151154
snap3.docChanges({ includeMetadataChanges: true }).length.should.be.eql(1);
152155
});
153156

154-
// TODO: fixme @ehesp - flaky test: `AssertionError: expected 5 to equal 1`
155-
xit('returns the correct number of document changes if listening to metadata changes, but not including them in docChanges', async function () {
157+
it('returns the correct number of document changes if listening to metadata changes, but not including them in docChanges', async function () {
156158
const callback = sinon.spy();
157-
const colRef = firebase.firestore().collection('v6/metadatachanges/true-false');
159+
const colRef = firebase
160+
.firestore()
161+
// Firestore caches aggressively, even if you wipe the emulator, local documents are cached
162+
// between runs, so use random collections to make sure `tests:*:test-reuse` works while iterating
163+
.collection(`${COLLECTION}/${Utils.randString(12, '#aA')}/metadatachanges-true-false`);
158164
const unsub = colRef.onSnapshot({ includeMetadataChanges: true }, callback);
159165
await colRef.add({ foo: 'bar' });
160166
await Utils.spyToBeCalledTimesAsync(callback, 3);
@@ -173,7 +179,8 @@ describe('firestore.QuerySnapshot', function () {
173179
describe('forEach()', function () {
174180
it('throws if callback is not a function', async function () {
175181
try {
176-
const colRef = firebase.firestore().collection(COLLECTION);
182+
const colRef = firebase.firestore().collection(`${COLLECTION}/callbacks/nonfunction`);
183+
await colRef.add({});
177184
const snapshot = await colRef.limit(1).get();
178185
snapshot.forEach(123);
179186
return Promise.reject(new Error('Did not throw an Error.'));
@@ -184,13 +191,14 @@ describe('firestore.QuerySnapshot', function () {
184191
});
185192

186193
it('calls back a function', async function () {
187-
const colRef = firebase.firestore().collection(COLLECTION);
188-
colRef.add({});
189-
colRef.add({});
194+
const colRef = firebase.firestore().collection(`${COLLECTION}/callbacks/function`);
195+
await colRef.add({});
196+
await colRef.add({});
190197
const snapshot = await colRef.limit(2).get();
191198
const callback = sinon.spy();
192199
snapshot.forEach.should.be.Function();
193200
snapshot.forEach(callback);
201+
await Utils.spyToBeCalledTimesAsync(callback, 2, 20000);
194202
callback.should.be.calledTwice();
195203
callback.args[0][0].constructor.name.should.eql('FirestoreDocumentSnapshot');
196204
callback.args[0][1].should.be.Number();
@@ -199,8 +207,8 @@ describe('firestore.QuerySnapshot', function () {
199207
});
200208

201209
it('provides context to the callback', async function () {
202-
const colRef = firebase.firestore().collection(COLLECTION);
203-
colRef.add({});
210+
const colRef = firebase.firestore().collection(`${COLLECTION}/callbacks/function-context`);
211+
await colRef.add({});
204212
const snapshot = await colRef.limit(1).get();
205213
const callback = sinon.spy();
206214
snapshot.forEach.should.be.Function();

0 commit comments

Comments
 (0)