Skip to content

WIP: refactor(database): Add migrated test harness [Part 3/3] #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4a0df56
refactor(database): add typescript implementation
jshcrowthe Jun 16, 2017
dcf2f5c
refactor(database): update build process to include database.ts
jshcrowthe Jun 16, 2017
7e609d6
refactor(*): refactor environment builds to be based on separate .ts …
jshcrowthe Jun 16, 2017
e72bfbe
WIP: patch database code in nodeJS
jshcrowthe Jun 16, 2017
2f6a406
refactor(database): classes for typescript database implementation (#55)
jsayol Jun 17, 2017
19519ac
WIP: add the /tests/config dir to the .gitignore
jshcrowthe Jun 19, 2017
2758ca7
WIP: add test harness
jshcrowthe Jun 19, 2017
7f78f89
WIP: add query tests
jshcrowthe Jun 19, 2017
b12a61f
WIP: add database.test.ts
jshcrowthe Jun 19, 2017
a046261
WIP: add node.test.ts
jshcrowthe Jun 19, 2017
622fed8
WIP: add sortedmap.test.ts
jshcrowthe Jun 19, 2017
d35b183
WIP: add datasnapshot.test.ts
jshcrowthe Jun 19, 2017
c81583d
WIP: add sparsesnapshottree.test.ts
jshcrowthe Jun 19, 2017
f4fc618
refactor(database): refactor query.test.ts to better preserve origina…
jshcrowthe Jun 20, 2017
342d527
WIP: add crawler_support.test.ts
jshcrowthe Jun 20, 2017
c51999a
WIP: refactor EventAccumulator.ts for data.test.ts
jshcrowthe Jun 21, 2017
c0eba9c
WIP: fix issue with query.test.ts
jshcrowthe Jun 22, 2017
e290f67
WIP: add connection.test.ts
jshcrowthe Jun 22, 2017
c0af997
WIP: add info.test.ts
jshcrowthe Jun 22, 2017
1223678
WIP: add order_by.test.ts
jshcrowthe Jun 22, 2017
9e08172
WIP: fix several code signature problems, add test files
jshcrowthe Jun 22, 2017
379a263
WIP: add transaction.test.ts
jshcrowthe Jun 26, 2017
3193651
WIP: working on the broken npm test command
jshcrowthe Jun 27, 2017
d5f99d8
WIP: working on fixes
jshcrowthe Jun 27, 2017
58f8bff
WIP: remove logging
jshcrowthe Jun 27, 2017
869b9a5
WIP: fix node tests
jshcrowthe Jun 27, 2017
ebe491c
fix(*): fixing test files and CI integration
jshcrowthe Jun 28, 2017
2b1efa4
WIP: tEMP: Allow branch builds
jshcrowthe Jun 28, 2017
c40a189
WIP: escape string
jshcrowthe Jun 28, 2017
d78d6c4
refactor(CI): use ChromeHeadless launcher
jshcrowthe Jun 28, 2017
2939025
Merge branch 'ts-database/final' into ts-database/migrate-test-harness
jshcrowthe Jun 28, 2017
d214ba0
WIP: fixes from review.
jshcrowthe Jun 29, 2017
dc5c374
WIP: skip flakey test
jshcrowthe Jun 29, 2017
71ff51c
WIP: remove unneeded debugger statement
jshcrowthe Jun 29, 2017
2531901
WIP: fixing nits
jshcrowthe Jul 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
npm-debug.log
/coverage
/.nyc_output
/tests/integration/config
/tests/config
/temp
/.vscode
2 changes: 1 addition & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
'tests/**/*.test.ts',
'!tests/**/browser/**/*.test.ts',
'!tests/**/binary/**/*.test.ts',
'!src/firebase-*.ts',
],
binary: [
'tests/**/binary/**/*.test.ts',
Expand All @@ -45,7 +46,6 @@ module.exports = {
babel: {
plugins: [
require('babel-plugin-add-module-exports'),
require('babel-plugin-minify-dead-code-elimination')
],
presets: [
[require('babel-preset-env'), {
Expand Down
58 changes: 12 additions & 46 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function compileIndvES2015ModulesToBrowser() {
'firebase-app': './src/app.ts',
'firebase-storage': './src/storage.ts',
'firebase-messaging': './src/messaging.ts',
'firebase-database': './src/database.ts',
},
output: {
path: path.resolve(__dirname, './dist/browser'),
Expand Down Expand Up @@ -192,27 +193,6 @@ function compileIndvES2015ModulesToBrowser() {
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
}

function compileSDKES2015ToBrowser() {
return gulp.src('./dist/es2015/firebase.js')
.pipe(webpackStream({
plugins: [
new webpack.DefinePlugin({
TARGET_ENVIRONMENT: JSON.stringify('browser')
})
]
}, webpack))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(through.obj(function(file, enc, cb) {
// Dont pipe through any source map files as it will be handled
// by gulp-sourcemaps
var isSourceMap = /\.map$/.test(file.path);
if (!isSourceMap) this.push(file);
cb();
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
}

function buildBrowserFirebaseJs() {
return gulp.src('./dist/browser/*.js')
.pipe(sourcemaps.init({ loadMaps: true }))
Expand All @@ -222,32 +202,18 @@ function buildBrowserFirebaseJs() {
}

function buildAltEnvFirebaseJs() {
const envs = [
'browser',
'node',
'react-native'
];

const streams = envs.map(env => {
const babelConfig = Object.assign({}, config.babel, {
plugins: [
['inline-replace-variables', {
'TARGET_ENVIRONMENT': env
}],
...config.babel.plugins
]
});
return gulp.src('./dist/es2015/firebase.js')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(babel(babelConfig))
.pipe(rename({
suffix: `-${env}`
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
const babelConfig = Object.assign({}, config.babel, {
plugins: config.babel.plugins
});

return merge(streams);
return gulp.src([
'./dist/es2015/firebase-browser.js',
'./dist/es2015/firebase-node.js',
'./dist/es2015/firebase-react-native.js',
])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(babel(babelConfig))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
}

function copyPackageContents() {
Expand Down
9 changes: 4 additions & 5 deletions gulp/tasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ const gulp = require('gulp');
const config = require('../config');

// Ensure that the test tasks get set up
require('./test');
const testFxns = require('./test');

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

stream.on('error', () => {});
stream.on('error', err => {});
return stream;
}

gulp.task('dev', gulp.parallel([
'test:unit',
watchDevFiles
]));
46 changes: 26 additions & 20 deletions gulp/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,29 @@ function runNodeBinaryTests() {
/**
* Runs all of the browser unit tests in karma
*/
function runBrowserUnitTests(done) {
const karmaConfig = Object.assign({}, config.karma, {
// list of files / patterns to load in the browser
files: [
'./+(src|tests)/**/*.ts'
],

// list of files to exclude from the included globs above
exclude: [
// we don't want this file as it references files that only exist once compiled
`./src/firebase.ts`,
function runBrowserUnitTests(dev) {
return (done) => {
const karmaConfig = Object.assign({}, config.karma, {
// list of files / patterns to load in the browser
files: [
'./+(src|tests)/**/*.ts'
],

// list of files to exclude from the included globs above
exclude: [
// we don't want this file as it references files that only exist once compiled
`./src/firebase-*.ts`,

// Don't include node test files
'./tests/**/node/**/*.test.ts',
// Don't include node test files
'./tests/**/node/**/*.test.ts',

// Don't include binary test files
'./tests/**/binary/**/*.test.ts',
],
});
new karma.Server(karmaConfig, done).start();
// Don't include binary test files
'./tests/**/binary/**/*.test.ts',
],
browsers: !!dev ? ['ChromeHeadless'] : config.karma.browsers,
});
new karma.Server(karmaConfig, done).start();
};
}

/**
Expand Down Expand Up @@ -121,9 +124,9 @@ function runAllKarmaTests(done) {
}

gulp.task('test:unit:node', runNodeUnitTests);
gulp.task('test:unit:browser', runBrowserUnitTests);
gulp.task('test:unit:browser', runBrowserUnitTests());

const unitTestSuite = gulp.parallel(runNodeUnitTests, runBrowserUnitTests);
const unitTestSuite = gulp.parallel(runNodeUnitTests, runBrowserUnitTests());
gulp.task('test:unit', unitTestSuite);

gulp.task('test:binary:browser', runBrowserBinaryTests);
Expand All @@ -137,3 +140,6 @@ gulp.task('test', gulp.parallel([
runNodeBinaryTests,
runAllKarmaTests
]));

exports.runNodeUnitTests = runNodeUnitTests;
exports.runBrowserUnitTests = runBrowserUnitTests;
73 changes: 73 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import firebase from './app';
import { FirebaseApp, FirebaseNamespace } from "./app/firebase_app";
import { Database } from "./database/api/Database";
import { Query } from "./database/api/Query";
import { Reference } from "./database/api/Reference";
import { enableLogging } from "./database/core/util/util";
import { RepoManager } from "./database/core/RepoManager";
import * as INTERNAL from './database/api/internal';
import * as TEST_ACCESS from './database/api/test_access';
import { isNodeSdk } from "./utils/environment";

export function registerDatabase(instance) {
// Register the Database Service with the 'firebase' namespace.
const namespace = instance.INTERNAL.registerService(
'database',
app => RepoManager.getInstance().databaseFromApp(app),
// firebase.database namespace properties
{
Reference,
Query,
Database,
enableLogging,
INTERNAL,
ServerValue: Database.ServerValue,
TEST_ACCESS
}
);

if (isNodeSdk()) {
module.exports = namespace;
}
}

/**
* Extensions to the FirebaseApp and FirebaseNamespaces interfaces
*/
declare module './app/firebase_app' {
interface FirebaseApp {
database?(): Database
}
}

declare module './app/firebase_app' {
interface FirebaseNamespace {
database?: {
(app?: FirebaseApp): Database,
Database,
enableLogging,
INTERNAL,
Query,
Reference,
ServerValue,
}
}
}

registerDatabase(firebase);
Loading