@@ -20,6 +20,7 @@ import { Deferred } from '@firebase/util';
20
20
import { expect , use } from 'chai' ;
21
21
import chaiAsPromised from 'chai-as-promised' ;
22
22
23
+ import { connectDatabaseEmulator } from '../../src/api/Database' ;
23
24
import {
24
25
child ,
25
26
get ,
@@ -48,6 +49,7 @@ import {
48
49
DATABASE_URL ,
49
50
getFreshRepo ,
50
51
getRWRefs ,
52
+ isEmulatorActive ,
51
53
waitFor ,
52
54
waitUntil ,
53
55
writeAndValidate
@@ -138,6 +140,43 @@ describe('Database@exp Tests', () => {
138
140
unsubscribe ( ) ;
139
141
} ) ;
140
142
143
+ it ( 'can connected to emulator' , async ( ) => {
144
+ if ( isEmulatorActive ( ) ) {
145
+ const db = getDatabase ( defaultApp ) ;
146
+ connectDatabaseEmulator ( db , 'localhost' , 9000 ) ;
147
+ await get ( refFromURL ( db , `${ DATABASE_ADDRESS } /foo/bar` ) ) ;
148
+ }
149
+ } ) ;
150
+
151
+ it ( 'can chnage emulator config before network operations' , async ( ) => {
152
+ if ( isEmulatorActive ( ) ) {
153
+ const db = getDatabase ( defaultApp ) ;
154
+ connectDatabaseEmulator ( db , 'localhost' , 9001 ) ;
155
+ connectDatabaseEmulator ( db , 'localhost' , 9000 ) ;
156
+ await get ( refFromURL ( db , `${ DATABASE_ADDRESS } /foo/bar` ) ) ;
157
+ }
158
+ } ) ;
159
+
160
+ it ( 'can connected to emulator after network operations with same parameters' , async ( ) => {
161
+ if ( isEmulatorActive ( ) ) {
162
+ const db = getDatabase ( defaultApp ) ;
163
+ connectDatabaseEmulator ( db , 'localhost' , 9000 ) ;
164
+ await get ( refFromURL ( db , `${ DATABASE_ADDRESS } /foo/bar` ) ) ;
165
+ connectDatabaseEmulator ( db , 'localhost' , 9000 ) ;
166
+ }
167
+ } ) ;
168
+
169
+ it ( 'cannot connect to emulator after network operations with different parameters' , async ( ) => {
170
+ if ( isEmulatorActive ( ) ) {
171
+ const db = getDatabase ( defaultApp ) ;
172
+ connectDatabaseEmulator ( db , 'localhost' , 9000 ) ;
173
+ await get ( refFromURL ( db , `${ DATABASE_ADDRESS } /foo/bar` ) ) ;
174
+ expect ( ( ) => {
175
+ connectDatabaseEmulator ( db , 'localhost' , 9001 ) ;
176
+ } ) . to . throw ( ) ;
177
+ }
178
+ } ) ;
179
+
141
180
it ( 'can properly handle unknown deep merges' , async ( ) => {
142
181
// Note: This test requires `testIndex` to be added as an index.
143
182
// Please run `yarn test:setup` to ensure that this gets added.
0 commit comments