import { Firestore } from '../src/types' ; import { apps , firestore , initializeTestApp , clearFirestoreData } from '@firebase/rules-unit-testing' ; import crypto from 'crypto' ; export const FieldValue = firestore . FieldValue ; export class WebFirestoreTestUtil { projectId : string ; uid : string ; webFirestore : Firestore ; constructor ( ) { const randomStr = crypto . randomBytes ( 10 ) . toString ( 'hex' ) ; this . projectId = `test-${ randomStr }` ; this . uid = 'test-user' ; this . webFirestore = initializeTestApp ( { projectId : this . projectId , auth : { uid : this . uid } } ) . firestore ( ) ; } async clearFirestoreData ( ) { await clearFirestoreData ( { projectId : this . projectId } ) ; } async deleteApps ( ) { await Promise . all ( apps ( ) . map ( app => app . delete ( ) ) ) ; } }