From 438a1889679d1e548c6618e4af518f80a54fd4aa Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 5 Apr 2021 10:48:34 -0600 Subject: [PATCH 1/3] Re-enable database@exp tests --- .../database/test/exp/integration.test.ts | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/packages/database/test/exp/integration.test.ts b/packages/database/test/exp/integration.test.ts index 36f90e971d3..299d62cbb82 100644 --- a/packages/database/test/exp/integration.test.ts +++ b/packages/database/test/exp/integration.test.ts @@ -27,15 +27,15 @@ import { ref, refFromURL } from '../../exp/index'; -import { set } from '../../src/exp/Reference_impl'; +import { onValue, set } from '../../src/exp/Reference_impl'; import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util'; +import { EventAccumulatorFactory } from '../helpers/EventAccumulator'; export function createTestApp() { return initializeApp({ databaseURL: DATABASE_URL }); } -// TODO(database-exp): Re-enable these tests -describe.skip('Database Tests', () => { +describe('Database@exp Tests', () => { let defaultApp; beforeEach(() => { @@ -65,7 +65,7 @@ describe.skip('Database Tests', () => { expect(db.app).to.equal(defaultApp); }); - it('Can set and ge tref', async () => { + it('Can set and get ref', async () => { const db = getDatabase(defaultApp); await set(ref(db, 'foo/bar'), 'foobar'); const snap = await get(ref(db, 'foo/bar')); @@ -77,6 +77,60 @@ describe.skip('Database Tests', () => { await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`)); }); + it('Can get updates', async () => { + const db = getDatabase(defaultApp); + const fooRef = ref(db, 'foo'); + + const ea = EventAccumulatorFactory.waitsForCount(2); + onValue(fooRef, snap => { + ea.addEvent(snap.val()); + }); + + await set(fooRef, 'a'); + await set(fooRef, 'b'); + + const [snap1, snap2] = await ea.promise; + expect(snap1).to.equal('a'); + expect(snap2).to.equal('b'); + }); + + it('Can use once()', async () => { + const db = getDatabase(defaultApp); + const fooRef = ref(db, 'foo'); + + const ea = EventAccumulatorFactory.waitsForCount(1); + onValue( + fooRef, + snap => { + ea.addEvent(snap.val()); + }, + { onlyOnce: true } + ); + + await set(fooRef, 'a'); + await set(fooRef, 'b'); + + const [snap1] = await ea.promise; + expect(snap1).to.equal('a'); + }); + + it('Can unsubscribe', async () => { + const db = getDatabase(defaultApp); + const fooRef = ref(db, 'foo'); + + const ea = EventAccumulatorFactory.waitsForCount(1); + const unsubscribe = onValue(fooRef, snap => { + ea.addEvent(snap.val()); + }); + + await set(fooRef, 'a'); + unsubscribe(); + await set(fooRef, 'b'); + + const [snap1] = await ea.promise; + expect(snap1).to.equal('a'); + }); + it('Can goOffline/goOnline', async () => { const db = getDatabase(defaultApp); goOffline(db); From d80d32b710be9473985189fdf50e32f7558d7f5c Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 5 Apr 2021 10:50:07 -0600 Subject: [PATCH 2/3] Update test name --- packages/database/test/exp/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/database/test/exp/integration.test.ts b/packages/database/test/exp/integration.test.ts index 299d62cbb82..be78bd3a70e 100644 --- a/packages/database/test/exp/integration.test.ts +++ b/packages/database/test/exp/integration.test.ts @@ -94,7 +94,7 @@ describe('Database@exp Tests', () => { expect(snap2).to.equal('b'); }); - it('Can use once()', async () => { + it('Can use onlyOnce', async () => { const db = getDatabase(defaultApp); const fooRef = ref(db, 'foo'); From 3630d1540a54c5a7beb802aeec67329940b912c1 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 5 Apr 2021 18:42:46 -0600 Subject: [PATCH 3/3] Update integration.test.ts --- packages/database/test/exp/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/database/test/exp/integration.test.ts b/packages/database/test/exp/integration.test.ts index be78bd3a70e..9790c88d24c 100644 --- a/packages/database/test/exp/integration.test.ts +++ b/packages/database/test/exp/integration.test.ts @@ -28,8 +28,8 @@ import { refFromURL } from '../../exp/index'; import { onValue, set } from '../../src/exp/Reference_impl'; -import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util'; import { EventAccumulatorFactory } from '../helpers/EventAccumulator'; +import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util'; export function createTestApp() { return initializeApp({ databaseURL: DATABASE_URL });