Skip to content

Commit fc4f2b9

Browse files
committed
Added integration tests
1 parent 4c24b18 commit fc4f2b9

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/database/test/exp/integration.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Deferred } from '@firebase/util';
2020
import { expect, use } from 'chai';
2121
import chaiAsPromised from 'chai-as-promised';
2222

23+
import { connectDatabaseEmulator } from '../../src/api/Database';
2324
import {
2425
child,
2526
get,
@@ -48,6 +49,7 @@ import {
4849
DATABASE_URL,
4950
getFreshRepo,
5051
getRWRefs,
52+
isEmulatorActive,
5153
waitFor,
5254
waitUntil,
5355
writeAndValidate
@@ -138,6 +140,43 @@ describe('Database@exp Tests', () => {
138140
unsubscribe();
139141
});
140142

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+
141180
it('can properly handle unknown deep merges', async () => {
142181
// Note: This test requires `testIndex` to be added as an index.
143182
// Please run `yarn test:setup` to ensure that this gets added.

packages/database/test/helpers/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,7 @@ export async function waitUntil(cb: () => boolean, maxRetries = 5) {
143143
}
144144
});
145145
}
146+
147+
export function isEmulatorActive(): boolean {
148+
return USE_EMULATOR;
149+
}

0 commit comments

Comments
 (0)