Skip to content

Commit 869b9a5

Browse files
committed
WIP: fix node tests
1 parent 58f8bff commit 869b9a5

File tree

7 files changed

+36
-37
lines changed

7 files changed

+36
-37
lines changed

src/database/core/util/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const buildLogMessage_ = function(var_args) {
114114
* Use this for all debug messages in Firebase.
115115
* @type {?function(string)}
116116
*/
117-
export var logger = console.log.bind(console);
117+
export var logger = null;
118118

119119

120120
/**

tests/database/browser/connection.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { expect } from "chai";
22
import { TEST_PROJECT, testRepoInfo } from "../helpers/util";
33
import { Connection } from "../../../src/database/realtime/Connection";
44

5-
describe.only('Connection', function() {
6-
this.timeout(10000);
5+
describe('Connection', function() {
76
it('return the session id', function(done) {
87
new Connection('1',
98
testRepoInfo(TEST_PROJECT.databaseURL),

tests/database/helpers/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ export function buildObjFromKey(key) {
215215
};
216216

217217
export function testRepoInfo(url) {
218-
const regex = /https:\/\/(.*).firebaseio.com/;
218+
const regex = /https?:\/\/(.*).firebaseio.com/;
219219
const match = url.match(regex);
220220
if (!match) throw new Error('Couldnt get Namespace from passed URL');
221221
const [,ns] = match;
222-
return new ConnectionTarget(`${ns}.firebaseio.com`, false, ns, false);
222+
return new ConnectionTarget(`${ns}.firebaseio.com`, true, ns, false);
223223
}

tests/database/info.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ describe(".info Tests", function () {
4141
expect(function() {f2.set('hi');}).to.throw;
4242
});
4343

44-
it("Can watch .info/connected.", function (done) {
45-
var f = (getRandomNode() as Reference).root;
46-
f.child('.info/connected').on('value', function(snap) {
47-
if (snap.val() === true) done();
48-
});
44+
it("Can watch .info/connected.", function() {
45+
return new Promise(resolve => {
46+
var f = (getRandomNode() as Reference).root;
47+
f.child('.info/connected').on('value', function(snap) {
48+
if (snap.val() === true) resolve();
49+
});
50+
})
4951
});
5052

5153

tests/database/node/connection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { TEST_PROJECT, testRepoInfo } from "../helpers/util";
33
import { Connection } from "../../../src/database/realtime/Connection";
44
import "../../../src/utils/nodePatches";
55

6-
describe.only('Connection', () => {
6+
describe('Connection', () => {
77
it('return the session id', function(done) {
8+
debugger;
89
new Connection('1',
910
testRepoInfo(TEST_PROJECT.databaseURL),
1011
message => {},
@@ -20,7 +21,6 @@ describe.only('Connection', () => {
2021
// TODO(koss) - Flakey Test. When Dev Tools is closed on my Mac, this test
2122
// fails about 20% of the time (open - it never fails). In the failing
2223
// case a long-poll is opened first.
23-
// https://app.asana.com/0/58926111402292/101921715724749
2424
it('disconnect old session on new connection', function(done) {
2525
const info = testRepoInfo(TEST_PROJECT.databaseURL);
2626
new Connection('1', info,

tests/database/repoinfo.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { expect } from "chai";
44

55
describe('RepoInfo', function() {
66
it('should return the correct URL', function() {
7-
var repoInfo = testRepoInfo('test-ns');
7+
var repoInfo = testRepoInfo('https://test-ns.firebaseio.com');
88

99
var urlParams = {};
1010
urlParams[CONSTANTS.VERSION_PARAM] = CONSTANTS.PROTOCOL_VERSION;
1111
urlParams[CONSTANTS.LAST_SESSION_PARAM] = 'test';
1212

1313
var websocketUrl = repoInfo.connectionURL(CONSTANTS.WEBSOCKET, urlParams);
14-
expect(websocketUrl).to.equal('ws://test-ns.fblocal.com:9000/.ws?v=5&ls=test');
14+
expect(websocketUrl).to.equal('wss://test-ns.firebaseio.com/.ws?v=5&ls=test');
1515

1616
var longPollingUrl = repoInfo.connectionURL(CONSTANTS.LONG_POLLING, urlParams);
17-
expect(longPollingUrl).to.equal('http://test-ns.fblocal.com:9000/.lp?v=5&ls=test');
17+
expect(longPollingUrl).to.equal('https://test-ns.firebaseio.com/.lp?v=5&ls=test');
1818
});
1919
});

tests/database/transaction.test.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -760,28 +760,26 @@ describe('Transaction Tests', function() {
760760
});
761761
});
762762

763-
it('Transaction runs on null only once after reconnect (Case 1981).', function(done) {
763+
it('Transaction runs on null only once after reconnect (Case 1981).', async function() {
764764
if (!canCreateExtraConnections()) return;
765765

766766
var ref = (getRandomNode() as Reference);
767-
ref.set(42, function() {
768-
var newRef = getFreshRepoFromReference(ref);
769-
var run = 0;
770-
newRef.transaction(function(curr) {
771-
run++;
772-
if (run === 1) {
773-
expect(curr).to.equal(null);
774-
} else if (run === 2) {
775-
expect(curr).to.equal(42);
776-
}
777-
return 3.14;
778-
}, function(error, committed, resultSnapshot) {
779-
expect(error).to.equal(null);
780-
expect(committed).to.equal(true);
781-
expect(run).to.equal(2);
782-
expect(resultSnapshot.val()).to.equal(3.14);
783-
done();
784-
});
767+
await ref.set(42);
768+
var newRef = getFreshRepoFromReference(ref);
769+
var run = 0;
770+
return newRef.transaction(function(curr) {
771+
run++;
772+
if (run === 1) {
773+
expect(curr).to.equal(null);
774+
} else if (run === 2) {
775+
expect(curr).to.equal(42);
776+
}
777+
return 3.14;
778+
}, function(error, committed, resultSnapshot) {
779+
expect(error).to.equal(null);
780+
expect(committed).to.equal(true);
781+
expect(run).to.equal(2);
782+
expect(resultSnapshot.val()).to.equal(3.14);
785783
});
786784
});
787785

@@ -950,9 +948,9 @@ describe('Transaction Tests', function() {
950948
return 12;
951949
});
952950

953-
return ref.once('value', function(s) {
954-
expect(s.exportVal()).to.deep.equal({ '.value': 12, '.priority': 7});
955-
});
951+
const snap = await ref.once('value');
952+
953+
expect(snap.exportVal()).to.deep.equal({ '.value': 12, '.priority': 7});
956954
});
957955

958956
it('Transaction and priority: Transaction can change priority on non-empty node.', async function() {

0 commit comments

Comments
 (0)