Skip to content

Commit 890207a

Browse files
authored
WIP: refactor(database): Add migrated test harness [Part 3/3] (#71)
* refactor(database): add typescript implementation * refactor(database): update build process to include database.ts All integration tests pass at this point * refactor(*): refactor environment builds to be based on separate .ts files * WIP: patch database code in nodeJS * refactor(database): classes for typescript database implementation (#55) * refactor(database): classes for typescript database implementation * refactor(database): requested changes & other improvements * WIP: add the /tests/config dir to the .gitignore * WIP: add test harness * WIP: add query tests There are some tests that have weird timing issues, and because of the polling nature of the original implementation, we never caught the issue. These should be resolved when able * WIP: add database.test.ts * WIP: add node.test.ts * WIP: add sortedmap.test.ts * WIP: add datasnapshot.test.ts * WIP: add sparsesnapshottree.test.ts * refactor(database): refactor query.test.ts to better preserve original test meaning * WIP: add crawler_support.test.ts * WIP: refactor EventAccumulator.ts for data.test.ts * WIP: fix issue with query.test.ts * WIP: add connection.test.ts * WIP: add info.test.ts * WIP: add order_by.test.ts I only migrated some of these tests as there was a dependency on the server for several tests * WIP: fix several code signature problems, add test files * WIP: add transaction.test.ts * WIP: working on the broken npm test command * WIP: working on fixes * WIP: remove logging * WIP: fix node tests * fix(*): fixing test files and CI integration * WIP: tEMP: Allow branch builds * WIP: escape string * refactor(CI): use ChromeHeadless launcher * WIP: fixes from review. * WIP: skip flakey test * WIP: remove unneeded debugger statement * WIP: fixing nits
1 parent bb80d31 commit 890207a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7982
-267
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
npm-debug.log
55
/coverage
66
/.nyc_output
7-
/tests/integration/config
7+
/tests/config
88
/temp
9-
/.vscode
9+
/.vscode
10+
/.ts-node

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ addons:
1616
- g++-4.8
1717
before_script:
1818
- "export DISPLAY=:99.0"
19+
- "mkdir -p tests/config && echo \"$PROJECT_CONFIG\" > tests/config/project.json"
1920
script:
2021
- xvfb-run npm test
21-
branches:
22-
only:
23-
- master

gulp/config.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ const path = require('path');
1717
const cwd = process.cwd();
1818
const karma = require('karma');
1919

20-
module.exports = {
20+
const configObj = {
2121
root: path.resolve(cwd),
2222
pkg: require(path.resolve(cwd, 'package.json')),
23+
testConfig: {
24+
timeout: 5000,
25+
retries: 5
26+
},
2327
tsconfig: require(path.resolve(cwd, 'tsconfig.json')),
2428
tsconfigTest: require(path.resolve(cwd, 'tsconfig.test.json')),
2529
paths: {
@@ -30,6 +34,7 @@ module.exports = {
3034
'tests/**/*.test.ts',
3135
'!tests/**/browser/**/*.test.ts',
3236
'!tests/**/binary/**/*.test.ts',
37+
'!src/firebase-*.ts',
3338
],
3439
binary: [
3540
'tests/**/binary/**/*.test.ts',
@@ -102,7 +107,7 @@ module.exports = {
102107

103108
// start these browsers
104109
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
105-
browsers: ['Chrome', 'Firefox'],
110+
browsers: ['ChromeHeadless', 'Firefox'],
106111

107112
// Continuous Integration mode
108113
// if true, Karma captures browsers, runs the tests and exits
@@ -115,6 +120,16 @@ module.exports = {
115120
// karma-typescript config
116121
karmaTypescriptConfig: {
117122
tsconfig: `./tsconfig.test.json`
123+
},
124+
125+
// Stub for client config
126+
client: {
127+
mocha: {}
118128
}
119129
}
120-
};
130+
};
131+
132+
configObj.karma.client.mocha.timeout = configObj.testConfig.timeout;
133+
configObj.karma.client.mocha.retries = configObj.testConfig.retries;
134+
135+
module.exports = configObj;

gulp/tasks/dev.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ const gulp = require('gulp');
1717
const config = require('../config');
1818

1919
// Ensure that the test tasks get set up
20-
require('./test');
20+
const testFxns = require('./test');
2121

2222
function watchDevFiles() {
2323
const stream = gulp.watch([
2424
`${config.root}/src/**/*.ts`,
25-
config.paths.test.unit
26-
], gulp.parallel('test:unit'));
25+
'tests/**/*.test.ts'
26+
], testFxns.runBrowserUnitTests(true));
2727

28-
stream.on('error', () => {});
28+
stream.on('error', err => {});
2929
return stream;
3030
}
3131

3232
gulp.task('dev', gulp.parallel([
33-
'test:unit',
3433
watchDevFiles
3534
]));

gulp/tasks/test.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ function runNodeUnitTests() {
3232
.pipe(envs)
3333
.pipe(mocha({
3434
reporter: 'spec',
35-
compilers: 'ts:ts-node/register'
35+
compilers: 'ts:ts-node/register',
36+
timeout: config.testConfig.timeout,
37+
retries: config.testConfig.retries
3638
}));
3739
}
3840

@@ -47,33 +49,41 @@ function runNodeBinaryTests() {
4749
.pipe(envs)
4850
.pipe(mocha({
4951
reporter: 'spec',
50-
compilers: 'ts:ts-node/register'
52+
compilers: 'ts:ts-node/register',
53+
timeout: config.testConfig.timeout,
54+
retries: config.testConfig.retries
5155
}));
5256
}
5357

5458
/**
5559
* Runs all of the browser unit tests in karma
5660
*/
57-
function runBrowserUnitTests(done) {
58-
const karmaConfig = Object.assign({}, config.karma, {
59-
// list of files / patterns to load in the browser
60-
files: [
61-
'./+(src|tests)/**/*.ts'
62-
],
63-
64-
// list of files to exclude from the included globs above
65-
exclude: [
66-
// we don't want this file as it references files that only exist once compiled
67-
`./src/firebase.ts`,
61+
function runBrowserUnitTests(dev) {
62+
return (done) => {
63+
const karmaConfig = Object.assign({}, config.karma, {
64+
// list of files / patterns to load in the browser
65+
files: [
66+
'./+(src|tests)/**/*.ts'
67+
],
68+
69+
// list of files to exclude from the included globs above
70+
exclude: [
71+
// we don't want this file as it references files that only exist once compiled
72+
`./src/firebase-*.ts`,
6873

69-
// Don't include node test files
70-
'./tests/**/node/**/*.test.ts',
74+
// We don't want to load the node env
75+
`./src/utils/nodePatches.ts`,
7176

72-
// Don't include binary test files
73-
'./tests/**/binary/**/*.test.ts',
74-
],
75-
});
76-
new karma.Server(karmaConfig, done).start();
77+
// Don't include node test files
78+
'./tests/**/node/**/*.test.ts',
79+
80+
// Don't include binary test files
81+
'./tests/**/binary/**/*.test.ts',
82+
],
83+
browsers: !!dev ? ['ChromeHeadless'] : config.karma.browsers,
84+
});
85+
new karma.Server(karmaConfig, done).start();
86+
};
7787
}
7888

7989
/**
@@ -111,7 +121,10 @@ function runAllKarmaTests(done) {
111121
// list of files to exclude from the included globs above
112122
exclude: [
113123
// we don't want this file as it references files that only exist once compiled
114-
`./src/firebase.ts`,
124+
`./src/firebase-*.ts`,
125+
126+
// We don't want to load the node env
127+
`./src/utils/nodePatches.ts`,
115128

116129
// Don't include node test files
117130
'./tests/**/node/**/*.test.ts',
@@ -121,9 +134,9 @@ function runAllKarmaTests(done) {
121134
}
122135

123136
gulp.task('test:unit:node', runNodeUnitTests);
124-
gulp.task('test:unit:browser', runBrowserUnitTests);
137+
gulp.task('test:unit:browser', runBrowserUnitTests());
125138

126-
const unitTestSuite = gulp.parallel(runNodeUnitTests, runBrowserUnitTests);
139+
const unitTestSuite = gulp.parallel(runNodeUnitTests, runBrowserUnitTests());
127140
gulp.task('test:unit', unitTestSuite);
128141

129142
gulp.task('test:binary:browser', runBrowserBinaryTests);
@@ -137,3 +150,6 @@ gulp.task('test', gulp.parallel([
137150
runNodeBinaryTests,
138151
runAllKarmaTests
139152
]));
153+
154+
exports.runNodeUnitTests = runNodeUnitTests;
155+
exports.runBrowserUnitTests = runBrowserUnitTests;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"babel-preset-env": "^1.2.1",
4040
"chai": "^3.5.0",
4141
"child-process-promise": "^2.2.1",
42+
"cross-env": "^5.0.1",
4243
"cz-customizable": "^5.0.0",
4344
"filesize": "^3.5.6",
4445
"git-rev-sync": "^1.9.0",

src/database.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ declare module './app/firebase_app' {
5858

5959
declare module './app/firebase_app' {
6060
interface FirebaseNamespace {
61-
database?(app: FirebaseApp): Database
61+
database?: {
62+
(app?: FirebaseApp): Database,
63+
Database,
64+
enableLogging,
65+
INTERNAL,
66+
Query,
67+
Reference,
68+
ServerValue,
69+
}
6270
}
6371
}
6472

src/database/api/Database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Database {
5151
* @param {string=} pathString
5252
* @return {!Firebase} Firebase reference.
5353
*/
54-
ref(pathString?): Reference {
54+
ref(pathString?: string): Reference {
5555
this.checkDeleted_('ref');
5656
validateArgCount('database.ref', 0, 1, arguments.length);
5757

src/database/api/Query.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ export class Query {
221221
* @param context
222222
* @return {!firebase.Promise}
223223
*/
224-
once(eventType: string, userCallback: SnapshotCallback,
225-
cancelOrContext?, context?: Object) {
224+
once(eventType: string,
225+
userCallback?: SnapshotCallback,
226+
cancelOrContext?, context?: Object): Promise<DataSnapshot> {
226227
validateArgCount('Query.once', 1, 4, arguments.length);
227228
validateEventType('Query.once', 1, eventType, false);
228229
validateCallback('Query.once', 2, userCallback, true);

src/database/api/onDisconnect.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class OnDisconnect {
2626
}
2727

2828
/**
29-
* @param {function(?Error)=} opt_onComplete
29+
* @param {function(?Error)=} onComplete
3030
* @return {!firebase.Promise}
3131
*/
3232
cancel(onComplete?) {
@@ -38,7 +38,7 @@ export class OnDisconnect {
3838
}
3939

4040
/**
41-
* @param {function(?Error)=} opt_onComplete
41+
* @param {function(?Error)=} onComplete
4242
* @return {!firebase.Promise}
4343
*/
4444
remove(onComplete?) {
@@ -52,7 +52,7 @@ export class OnDisconnect {
5252

5353
/**
5454
* @param {*} value
55-
* @param {function(?Error)=} opt_onComplete
55+
* @param {function(?Error)=} onComplete
5656
* @return {!firebase.Promise}
5757
*/
5858
set(value, onComplete?) {
@@ -68,7 +68,7 @@ export class OnDisconnect {
6868
/**
6969
* @param {*} value
7070
* @param {number|string|null} priority
71-
* @param {function(?Error)=} opt_onComplete
71+
* @param {function(?Error)=} onComplete
7272
* @return {!firebase.Promise}
7373
*/
7474
setWithPriority(value, priority, onComplete?) {
@@ -86,7 +86,7 @@ export class OnDisconnect {
8686

8787
/**
8888
* @param {!Object} objectToMerge
89-
* @param {function(?Error)=} opt_onComplete
89+
* @param {function(?Error)=} onComplete
9090
* @return {!firebase.Promise}
9191
*/
9292
update(objectToMerge, onComplete?) {

src/database/core/Repo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ export class Repo {
286286
* @param {number|string|null} newPriority
287287
* @param {?function(?Error, *=)} onComplete
288288
*/
289-
setWithPriority(path: Path, newVal: any, newPriority: number | string | null,
290-
onComplete: ((status: Error | null, errorReason?: string) => any) | null) {
289+
setWithPriority(path: Path, newVal: any,
290+
newPriority: number | string | null,
291+
onComplete: ((status: Error | null, errorReason?: string) => any) | null) {
291292
this.log_('set', {path: path.toString(), value: newVal, priority: newPriority});
292293

293294
// TODO: Optimize this behavior to either (a) store flag to skip resolving where possible and / or

src/database/core/util/SortedMap.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,35 +714,35 @@ export class SortedMap {
714714
* @param {(function(K, V):T)=} opt_resultGenerator
715715
* @return {SortedMapIterator.<K, V, T>} The iterator.
716716
*/
717-
getIterator(opt_resultGenerator) {
717+
getIterator(resultGenerator?) {
718718
return new SortedMapIterator(this.root_,
719719
null,
720720
this.comparator_,
721721
false,
722-
opt_resultGenerator);
722+
resultGenerator);
723723
}
724724

725-
getIteratorFrom(key, opt_resultGenerator) {
725+
getIteratorFrom(key, resultGenerator?) {
726726
return new SortedMapIterator(this.root_,
727727
key,
728728
this.comparator_,
729729
false,
730-
opt_resultGenerator);
730+
resultGenerator);
731731
}
732732

733-
getReverseIteratorFrom(key, opt_resultGenerator) {
733+
getReverseIteratorFrom(key, resultGenerator?) {
734734
return new SortedMapIterator(this.root_,
735735
key,
736736
this.comparator_,
737737
true,
738-
opt_resultGenerator);
738+
resultGenerator);
739739
}
740740

741-
getReverseIterator(opt_resultGenerator) {
741+
getReverseIterator(resultGenerator?) {
742742
return new SortedMapIterator(this.root_,
743743
null,
744744
this.comparator_,
745745
true,
746-
opt_resultGenerator);
746+
resultGenerator);
747747
}
748748
}; // end SortedMap

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
/**

src/database/core/view/filter/RangedFilter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IndexedFilter } from "./IndexedFilter";
22
import { PRIORITY_INDEX } from "../../../core/snap/indexes/PriorityIndex";
3-
import { NamedNode } from "../../../core/snap/Node";
3+
import { Node, NamedNode } from "../../../core/snap/Node";
44
import { ChildrenNode } from "../../../core/snap/ChildrenNode";
55
/**
66
* Filters nodes by range and uses an IndexFilter to track any changes after filtering the node

0 commit comments

Comments
 (0)