Skip to content

Commit

Permalink
Add Cloud Firestore Support
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcrowthe committed Oct 3, 2017
1 parent da87982 commit f49c8b5
Show file tree
Hide file tree
Showing 201 changed files with 44,501 additions and 37 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Shared editor configurations that track the way prettier formats source.
#
# To use this in vscode:
#
# ext install EditorConfig

root = true

# Source files look unixy by default
[*]
end_of_line = lf
insert_final_newline = true

# Javascript and Typescript look like Google-style
[*.{js,json,ts}]
charset = utf-8
indent_style = space
indent_size = 2

# Not currently supported by vscode, but is supported others, e.g. vim.
max_line_length = 80
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
src/database @mikelehen @schmidt-sebastian
tests/database @mikelehen @schmidt-sebastian

# Firestore Code
src/firestore @mikelehen @schmidt-sebastian
tests/firestore @mikelehen @schmidt-sebastian
integration/firestore @mikelehen @schmidt-sebastian

# Storage Code
src/storage @sphippen
tests/storage @sphippen
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- script: ./integration/serviceWorker/runner.sh
- script: ./integration/quickstart/runner.sh
- script: ./integration/messaging/runner.sh
- script: ./integration/firestore/runner.sh

# Misc Addons/Configs
dist: trusty
Expand All @@ -45,4 +46,4 @@ addons:

branches:
only:
- master
- master
31 changes: 31 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Firestore Unit Tests (Node)",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": ["test", "--suite=firestore/unit/", "--env=node"],
"port": 9229,
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Firestore Unit Tests (Browser)",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": ["test", "--suite=firestore/unit/", "--env=browser", "--debug"]
},
{
"type": "node",
"request": "launch",
"name": "Firestore Integration Tests (Browser)",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": ["test", "--suite=firestore/integration", "--env=browser", "--debug"]
}
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// Ruler can't be specified via editorconfig
"editor.rulers": [80],

"search.exclude": {
// Exclude gulp build outputs from search results
"dist": true,

// Exclude installed dependencies from searches too
"**/node_modules": true
}
}
57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ To get started using Firebase, see

### Prerequisites

Before you can start working on the Firebase JS SDK, you need to have Node.js 6.0 or
greater installed on your machine. After doing this, you must also install the
Before you can start working on the Firebase JS SDK, you need to have Node.js 6.0 or
greater installed on your machine. After doing this, you must also install the
dependencies for this package.

To download Node.js visit https://nodejs.org/en/download/.
Expand Down Expand Up @@ -58,8 +58,8 @@ gulp --tasks

## Testing the SDK

To run all tests for the SDK you must first supply a firebase project config for
your tests. This is done by creating a file called `project.json` and at the
To run all tests for the SDK you must first supply a firebase project config for
your tests. This is done by creating a file called `project.json` and at the
following path:

```
Expand All @@ -69,15 +69,50 @@ tests/config/project.json
This file should contain a JSON object with your app information (i.e. the same
information you would pass to `firebase.initializeApp`).

After you have done this, simply run: `npm test` at the root of this package.
### Project Config

There are several types of available tests:
The project supplied in your `project.json` needs to be properly configured to
succesfully run the tests.

- Unit Tests (`gulp test:unit`)
- Integration Tests (`gulp test:integration`)
#### Database Rules

_NOTE: You can execute each of these tasks on their own (e.g. you can run
`gulp test:unit` to run exclusively the smoke tests from your CLI)_
_i.e._

```json
{
"rules": {
".read": "true",
".write": "true"
}
}
```

#### Authentiaction Support

Enable the `Anonymous` sign-in provider.

### Running the tests

After you have the `project.json` and have properly configured the project,
simply run: `npm test` at the root of this package.

You can also run the tests by calling `gulp test` if you have gulp installed.

You can decrease the testing scope by providing the optional `suite`/`env` arguments to `npm/gulp test`.

_e.g._

```bash
$ gulp test --suite=firestore --env=node
```

Any directory path in the tests directory serves as a valid value for the `--suite` flag.

Valid values for the `--env` flag are `node`/`browser`.

### Integration Tests

These tests are functionally different enough from the normal test suite that they have their own README.md. Please view it [here](./integration/README.md):

## Building the SDK

Expand Down Expand Up @@ -117,7 +152,7 @@ These files are processed in the following flow:
1. Prebuilt browser binaries are ready to consume individually in the browser
however we need to wrap them in a CJS module wrapper for node/webpack/browserify
consumption.
1. The Firebase App binary is generated (from TS) and concatenated with the
1. The Firebase App binary is generated (from TS) and concatenated with the
browser binaries of each individual module to create `firebase.js`.

#### Legacy Files
Expand Down
8 changes: 6 additions & 2 deletions gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ const configObj = {
]
},
karma: {
autoWatch: false,

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


browserNoActivityTimeout: 30000,

customHeaders: [{
match: '.*',
name: 'Service-Worker-Allowed',
Expand Down Expand Up @@ -127,4 +131,4 @@ const configObj = {
configObj.karma.client.mocha.timeout = configObj.testConfig.timeout;
configObj.karma.client.mocha.retries = configObj.testConfig.retries;

module.exports = configObj;
module.exports = configObj;
12 changes: 9 additions & 3 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function compileIndvES2015ModulesToBrowser() {
'firebase-storage': './src/storage.ts',
'firebase-messaging': './src/messaging.ts',
'firebase-database': './src/database.ts',
'firebase-firestore': './src/firestore.ts',
},
output: {
filename: '[name].js',
Expand Down Expand Up @@ -168,7 +169,8 @@ function compileIndvES2015ModulesToBrowser() {
mangle: {
props: {
ignore_quoted: true,
regex: /^_|_$/,
// NOTE: Firestore uses __foo__ variables that must not be mangled.
regex: /^_[^_]|[^_]_$/
}
},
compress: {
Expand All @@ -189,7 +191,11 @@ function compileIndvES2015ModulesToBrowser() {
}

function buildBrowserFirebaseJs() {
return gulp.src('./dist/browser/*.js')
// Exclude firebase-firestore from combined firebase.js
return gulp.src([
'./dist/browser/*.js',
'!./dist/browser/firebase-firestore.js'
])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat('firebase.js'))
.pipe(sourcemaps.write('.'))
Expand Down Expand Up @@ -431,4 +437,4 @@ const buildSDK = exports.buildSDK = gulp.series([
logFileSize
]);

gulp.task('build', buildSDK);
gulp.task('build', buildSDK);
10 changes: 8 additions & 2 deletions gulp/tasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@
*/
const gulp = require('gulp');
const config = require('../config');
const argv = require('yargs').argv;

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

function watchDevFiles() {
// Default to just running browser tests
if (!argv.env) {
argv.env = 'browser';
}

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

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

gulp.task('dev', gulp.parallel([
watchDevFiles
]));
]));
46 changes: 38 additions & 8 deletions gulp/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function runNodeTest(suite = '**') {
*/
return gulp.src([
`tests/**/${suite}/**/*.test.ts`,
'src/firestore/platform_node/node_init.ts',
// TODO(b/66918026): Re-enable Firestore integration tests on node.
'!tests/firestore/integration/**/*.test.ts',
'!tests/**/browser/**/*.test.ts',
'!tests/**/binary/**/*.test.ts',
'!src/firebase-*.ts',
Expand All @@ -38,21 +41,23 @@ function runNodeTest(suite = '**') {
reporter: 'spec',
compilers: 'ts:ts-node/register',
timeout: config.testConfig.timeout,
retries: config.testConfig.retries
retries: config.testConfig.retries,
inspect: true
}))
.on('error', err => {
if (err && err.message && ~err.message.indexOf('No test files found')) return;
throw err;
});
}

function runBrowserTest(suite = '**') {
function runBrowserTest(suite = '.*', debug) {
return new Promise((resolve, reject) => {
const karmaConfig = Object.assign({}, config.karma, {
let karmaConfig = Object.assign({}, config.karma, {
// list of files / patterns to load in the browser
files: [
`./src/**/*.ts`,
`./tests/**/${suite}/**/*.ts`
`./tests/**/*.ts`,
{ pattern: `./tests/config/**/*`, included: false, served: true }
],

// list of files to exclude from the included globs above
Expand All @@ -70,28 +75,53 @@ function runBrowserTest(suite = '**') {
'./tests/**/binary/**/*.test.ts',
],
});

Object.assign(karmaConfig.karmaTypescriptConfig, {
bundlerOptions: {
entrypoints: new RegExp(`^.*tests/${suite}.*\.test\.ts$|^.*src/firestore/platform_browser/browser_init.ts$`)
}
});

if (debug) {
karmaConfig = Object.assign({}, karmaConfig, {
autoWatch: true,
singleRun: false,
browsers: ['Chrome']
});

Object.assign(karmaConfig.karmaTypescriptConfig, {
coverageOptions: {
instrumentation: false
}
});
}

new karma.Server(karmaConfig, exitcode => {
if (exitcode) return reject(exitcode);
resolve();
}).start();
});
}

function runTests() {
const suite = argv.suite || '**';
function runTests(devMode) {
const suite = argv.suite || '';
const env = argv.env || '*';
const debug = !!argv.debug || false;
console.log('debug:', debug);
console.log(`Values: ${suite}:${env}`);

switch(env) {
case 'node': return runNodeTest(suite);
case 'browser': return runBrowserTest(suite);
case 'browser': return runBrowserTest(suite, debug);
default:
// Incidentally this works returning a stream and promise value
return Promise.all([
runNodeTest(suite),
runBrowserTest(suite),
runBrowserTest(suite, debug),
]);
}
}

exports.runTests = runTests;

gulp.task('test', runTests);
22 changes: 22 additions & 0 deletions integration/firestore/firebase_export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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.
*/

// Replacement for tests/firestore/integration/util/firebase_export.ts,
// loading firebase from the npm module instead of from sources.
import * as firebase from 'firebase';
import 'firebase/firestore';

export default firebase;
Loading

0 comments on commit f49c8b5

Please sign in to comment.