Skip to content

Commit 566a688

Browse files
committed
add test
1 parent 2ccc9dd commit 566a688

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/firestore/src/lite-api/database.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,21 @@ export function connectFirestoreEmulator(
302302
firestore = cast(firestore, Firestore);
303303
const settings = firestore._getSettings();
304304

305+
logWarn(`before connect emulator, settings is {JSON.stringify(settings)}`);
305306
if (settings.host !== DEFAULT_HOST && settings.host !== host) {
306307
logWarn(
307308
'Host has been set in both settings() and useEmulator(), emulator host ' +
308309
'will be used'
309310
);
310311
}
311312

312-
firestore._setSettings({
313+
const newSettings = {
313314
...settings,
314315
host: `${host}:${port}`,
315316
ssl: false
316-
});
317+
};
318+
logWarn(`after connect emulator, settings is ${JSON.stringify(newSettings)}`);
319+
firestore._setSettings(newSettings);
317320

318321
if (options.mockUserToken) {
319322
let token: string;

packages/firestore/test/integration/api/provider.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
enableIndexedDbPersistence,
3030
setDoc,
3131
memoryLocalCache,
32-
getDocFromCache
32+
getDocFromCache,
33+
persistentLocalCache,
34+
connectFirestoreEmulator
3335
} from '../util/firebase_export';
3436
import { DEFAULT_SETTINGS } from '../util/settings';
3537

@@ -141,6 +143,25 @@ describe('Firestore Provider', () => {
141143
});
142144
});
143145

146+
it.only('connectFirestoreEmulator() keeps other settings', async () => {
147+
const app = initializeApp(
148+
{ apiKey: 'fake-api-key', projectId: 'test-project' },
149+
'test-use-enablePersistence'
150+
);
151+
const db = initializeFirestore(app, {
152+
...DEFAULT_SETTINGS,
153+
localCache: persistentLocalCache()
154+
});
155+
connectFirestoreEmulator(db, "localhost", 8080);
156+
157+
// SDK still functions.
158+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
159+
setDoc(doc(db, 'coll/doc'), { field: 'foo' });
160+
expect((await getDocFromCache(doc(db, 'coll/doc'))).data()).to.deep.equal({
161+
field: 'foo'
162+
});
163+
});
164+
144165
it('cannot mix enableIndexedDbPersistence() and settings.cache', async () => {
145166
const app = initializeApp(
146167
{ apiKey: 'fake-api-key', projectId: 'test-project' },

0 commit comments

Comments
 (0)