Skip to content

Commit 1a895a7

Browse files
committed
test: robustness try
1 parent 470a8bb commit 1a895a7

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

firebase.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"storage": {
2525
"port": 9199
2626
},
27+
"hosting": {
28+
"port": 5050
29+
},
2730
"ui": {
2831
"enabled": true
2932
},

tests/firestore/refs-in-collections.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ describe('Firestore refs in collections', async () => {
9292
await addDoc(listRef, { ref: bRef })
9393
// wait a bit for the nested ref to be bound
9494
await sleep(20)
95+
await promise.value
9596

9697
expect(data.value).toHaveLength(2)
9798
expect(data.value).toContainEqual({ ref: { name: 'a' } })

tests/utils.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ export function setupFirestoreRefs() {
4949
const testsCollection = collection(firestore, `__tests`)
5050
const itemRef = doc(testsCollection)
5151
// let firestore generate the id
52-
const forItemsRef = doc(testsCollection)
52+
const forCollectionRefs = doc(testsCollection)
53+
const forDocRefs = collection(forCollectionRefs, 'docs')
5354

54-
const listRef = collection(forItemsRef, 'list')
55+
const listRef = collection(forCollectionRefs, 'list')
5556
const orderedListRef = firestoreQuery(listRef, orderBy('name'))
5657

5758
afterAll(async () => {
59+
// cleaning up creates unexpected errors and is only necessary during dev
60+
if (process.env.CI) {
61+
return
62+
}
5863
// clean up the tests data
5964
await Promise.all([
6065
deleteDoc(itemRef),
@@ -63,12 +68,13 @@ export function setupFirestoreRefs() {
6368
await Promise.all(
6469
[...collectionsToClean].map((collection) => clearCollection(collection))
6570
)
71+
await clearCollection(forDocRefs)
6672
// must be done after the cleanup of its docs
67-
await deleteDoc(forItemsRef),
68-
await Promise.all([
69-
clearCollection(listRef),
70-
clearCollection(testsCollection),
71-
])
73+
await deleteDoc(forCollectionRefs)
74+
await Promise.all([
75+
clearCollection(listRef),
76+
clearCollection(testsCollection),
77+
])
7278
})
7379

7480
// for automatically generated collections
@@ -80,7 +86,7 @@ export function setupFirestoreRefs() {
8086
) {
8187
path = path || `col_${collectionId++}`
8288

83-
const col = collection(forItemsRef, path, ...pathSegments)
89+
const col = collection(forCollectionRefs, path, ...pathSegments)
8490
collectionsToClean.add(col)
8591
// to avoid having to pass a converter for types
8692
return col as CollectionReference<T>
@@ -91,7 +97,7 @@ export function setupFirestoreRefs() {
9197
const docsToClean = new Set<DocumentReference<any>>()
9298
function _doc<T = unknown>(path?: string, ...pathSegments: string[]) {
9399
path = path || `doc_${docId++}`
94-
const d = doc(testsCollection, path, ...pathSegments)
100+
const d = doc(forDocRefs, path, ...pathSegments)
95101
docsToClean.add(d)
96102
// to avoid having to pass a converter for types
97103
return d as DocumentReference<T>
@@ -130,7 +136,7 @@ export function setupFirestoreRefs() {
130136
listRef,
131137
orderedListRef,
132138
testId,
133-
col: forItemsRef,
139+
col: forCollectionRefs,
134140
collection: _collection,
135141
doc: _doc,
136142
query: firestoreQuery,

0 commit comments

Comments
 (0)