-
Notifications
You must be signed in to change notification settings - Fork 949
Add useFirestoreEmulator #4142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add useFirestoreEmulator #4142
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import { | |
cast, | ||
validateIsNotUsedTogether | ||
} from '../../../src/util/input_validation'; | ||
import { logWarn } from '../../../src/util/log'; | ||
|
||
declare module '@firebase/component' { | ||
interface NameServiceMapping { | ||
|
@@ -300,6 +301,38 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore { | |
).getImmediate() as FirebaseFirestore; | ||
} | ||
|
||
/** | ||
* Modify this instance to communicate with the Cloud Firestore emulator. | ||
* | ||
* Note: This must be called before this instance has been used to do any | ||
* operations. | ||
* | ||
* @param firestore - The Firestore instance to configure to connect to the | ||
* emulator. | ||
* @param host - the emulator host (ex: localhost). | ||
* @param port - the emulator port (ex: 9000). | ||
*/ | ||
export function useFirestoreEmulator( | ||
firestore: FirebaseFirestore, | ||
host: string, | ||
port: number | ||
): void { | ||
firestore = cast(firestore, FirebaseFirestore); | ||
|
||
if (firestore._getSettings().host !== DEFAULT_HOST) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope here but I recently realized that this warning shows up if you repeatedly call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me fix that. |
||
logWarn( | ||
'Host has been set in both settings() and useEmulator(), emulator host ' + | ||
'will be used' | ||
); | ||
} | ||
|
||
firestore._setSettings({ | ||
...firestore._getSettings(), | ||
host: `${host}:${port}`, | ||
ssl: false | ||
}); | ||
} | ||
|
||
/** | ||
* Terminates the provided Firestore instance. | ||
* | ||
|
@@ -316,6 +349,7 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore { | |
* its resources or in combination with {@link clearIndexedDbPersistence} to | ||
* ensure that all local state is destroyed between test runs. | ||
* | ||
* @param firestore - The Firestore instance to terminate. | ||
* @returns A promise that is resolved when the instance has been successfully | ||
* terminated. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
_2
intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's because we share the code from firestore-lite and firestore-exp. This should go away once #4140 is merged.