|
1 | | -const { initializeApp } = require("firebase/app"); |
2 | | -const { getFirestore, CACHE_SIZE_UNLIMITED } = require("firebase/firestore"); |
3 | 1 | const { expect } = require('chai'); |
4 | 2 |
|
5 | 3 | // [START city_custom_object] |
@@ -31,26 +29,39 @@ var cityConverter = { |
31 | 29 | // [END city_custom_object] |
32 | 30 |
|
33 | 31 | describe("firestore", () => { |
| 32 | + const { FirebaseFirestore } = require("firebase/firestore"); |
| 33 | + |
| 34 | + /** @type {FirebaseFirestore} */ |
34 | 35 | let db; |
| 36 | + let app; |
| 37 | + |
35 | 38 | before(() => { |
| 39 | + const { initializeApp } = require("firebase/app"); |
| 40 | + const { getFirestore } = require("firebase/firestore"); |
| 41 | + |
36 | 42 | const config = { |
37 | 43 | apiKey: "AIzaSyCM61mMr_iZnP1DzjT1PMB5vDGxfyWNM64", |
38 | 44 | authDomain: "firestore-snippets.firebaseapp.com", |
39 | 45 | projectId: "firestore-snippets" |
40 | 46 | }; |
41 | | - const app = initializeApp(config); |
| 47 | + app = initializeApp(config); |
42 | 48 | db = getFirestore(app); |
43 | 49 | }); |
44 | 50 |
|
45 | 51 | it("should be able to set the cache size", () => { |
46 | 52 | // [START fs_setup_cache] |
47 | | - db.settings({ |
48 | | - cacheSizeBytes: CACHE_SIZE_UNLIMITED |
| 53 | + const { initializeFirestore, CACHE_SIZE_UNLIMITED } = require("firebase/firestore"); |
| 54 | + |
| 55 | + const firestoreDb = initializeFirestore(app, { |
| 56 | + cacheSizeBytes: CACHE_SIZE_UNLIMITED |
49 | 57 | }); |
50 | 58 | // [END fs_setup_cache] |
51 | 59 | }); |
52 | 60 |
|
53 | 61 | it("should be initializable with persistence", () => { |
| 62 | + const { initializeApp } = require("firebase/app"); |
| 63 | + const { getFirestore } = require("firebase/firestore"); |
| 64 | + |
54 | 65 | const app = initializeApp({ |
55 | 66 | apiKey: '### FIREBASE API KEY ###', |
56 | 67 | authDomain: '### FIREBASE AUTH DOMAIN ###', |
@@ -140,9 +151,9 @@ describe("firestore", () => { |
140 | 151 |
|
141 | 152 | it("should get all users", async () => { |
142 | 153 | // [START get_all_users] |
143 | | - const { getDocs } = require("firebase/firestore"); |
| 154 | + const { collection, getDocs } = require("firebase/firestore"); |
144 | 155 |
|
145 | | - const querySnapshot = await getDocs(db.collection("users")); |
| 156 | + const querySnapshot = await getDocs(collection(db, "users")); |
146 | 157 | querySnapshot.forEach((doc) => { |
147 | 158 | console.log(`${doc.id} => ${doc.data()}`); |
148 | 159 | }); |
|
0 commit comments