Skip to content

Commit 1e1ccd3

Browse files
committed
Used warning instead of throwing error
1 parent af11311 commit 1e1ccd3

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

packages/database/src/api/Database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { RepoInfo } from '../core/RepoInfo';
4141
import { parseRepoInfo } from '../core/util/libs/parser';
4242
import { newEmptyPath, pathIsEmpty } from '../core/util/Path';
4343
import {
44+
warn,
4445
fatal,
4546
log,
4647
enableLogging as enableLoggingImpl
@@ -276,7 +277,7 @@ export class Database implements _FirebaseService {
276277

277278
function checkTransportInit() {
278279
if (TransportManager.IS_TRANSPORT_INITIALIZED) {
279-
fatal(
280+
warn(
280281
'Transport has already been initialized. Please call this function before calling ref or setting up a listener'
281282
);
282283
}

packages/database/test/transport.test.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,30 @@
1515
* limitations under the License.
1616
*/
1717

18+
19+
1820
import { CONSTANTS } from '@firebase/util';
19-
import { expect } from 'chai';
21+
import { expect, use } from 'chai';
22+
import { createSandbox, SinonSandbox, SinonSpy } from 'sinon';
23+
import sinonChai from 'sinon-chai';
2024

2125
import { forceLongPolling, forceWebSockets } from '../src';
26+
import * as Util from '../src/core/util/util';
2227
import { BrowserPollConnection } from '../src/realtime/BrowserPollConnection';
2328
import { TransportManager } from '../src/realtime/TransportManager';
2429
import { WebSocketConnection } from '../src/realtime/WebSocketConnection';
2530

31+
use(sinonChai);
2632
const transportInitError =
2733
'Transport has already been initialized. Please call this function before calling ref or setting up a listener';
2834
describe('Force Transport', () => {
2935
const oldNodeValue = CONSTANTS.NODE_CLIENT;
36+
let mySandbox: SinonSandbox;
37+
let spyWarn: SinonSpy;
3038
beforeEach(() => {
3139
CONSTANTS.NODE_CLIENT = false;
40+
mySandbox = createSandbox();
41+
spyWarn = mySandbox.spy(Util, 'warn');
3242
});
3343
afterEach(() => {
3444
// Resetting to old values
@@ -37,27 +47,32 @@ describe('Force Transport', () => {
3747
BrowserPollConnection.forceAllow_ = false;
3848
BrowserPollConnection.forceDisallow_ = true;
3949
WebSocketConnection.forceDisallow_ = false;
50+
mySandbox.restore();
4051
});
4152
it('should enable websockets and disable longPolling', () => {
42-
expect(forceWebSockets).to.not.throw();
53+
forceWebSockets();
54+
expect(spyWarn.called).to.equal(false);
4355
expect(WebSocketConnection.isAvailable()).to.equal(true);
4456
expect(BrowserPollConnection.isAvailable()).to.equal(false);
4557
});
4658
it('should throw an error when calling forceWebsockets() if TransportManager has already been initialized', () => {
4759
TransportManager.globalTransportInitialized_ = true;
48-
expect(forceWebSockets).to.throw(transportInitError);
60+
forceWebSockets();
61+
expect(spyWarn).to.have.been.calledWith(transportInitError);
4962
expect(WebSocketConnection.isAvailable()).to.equal(true);
5063
expect(BrowserPollConnection.isAvailable()).to.equal(false);
5164
});
5265
it('should enable longPolling and disable websockets', () => {
53-
expect(forceLongPolling).to.not.throw();
66+
forceLongPolling();
67+
expect(spyWarn.called).to.equal(false);
5468
expect(WebSocketConnection.isAvailable()).to.equal(false);
5569
expect(BrowserPollConnection.isAvailable()).to.equal(true);
5670
});
5771
it('should throw an error when calling forceLongPolling() if TransportManager has already been initialized', () => {
5872
TransportManager.globalTransportInitialized_ = true;
59-
expect(forceLongPolling).to.throw(transportInitError);
60-
expect(WebSocketConnection.isAvailable()).to.equal(true);
61-
expect(BrowserPollConnection.isAvailable()).to.equal(false);
73+
forceLongPolling();
74+
expect(spyWarn).to.have.been.calledWith(transportInitError);
75+
expect(WebSocketConnection.isAvailable()).to.equal(false);
76+
expect(BrowserPollConnection.isAvailable()).to.equal(true);
6277
});
6378
});

0 commit comments

Comments
 (0)