Skip to content

Commit f49c8b5

Browse files
committed
Add Cloud Firestore Support
1 parent da87982 commit f49c8b5

File tree

201 files changed

+44501
-37
lines changed

Some content is hidden

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

201 files changed

+44501
-37
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Shared editor configurations that track the way prettier formats source.
2+
#
3+
# To use this in vscode:
4+
#
5+
# ext install EditorConfig
6+
7+
root = true
8+
9+
# Source files look unixy by default
10+
[*]
11+
end_of_line = lf
12+
insert_final_newline = true
13+
14+
# Javascript and Typescript look like Google-style
15+
[*.{js,json,ts}]
16+
charset = utf-8
17+
indent_style = space
18+
indent_size = 2
19+
20+
# Not currently supported by vscode, but is supported others, e.g. vim.
21+
max_line_length = 80

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
src/database @mikelehen @schmidt-sebastian
1616
tests/database @mikelehen @schmidt-sebastian
1717

18+
# Firestore Code
19+
src/firestore @mikelehen @schmidt-sebastian
20+
tests/firestore @mikelehen @schmidt-sebastian
21+
integration/firestore @mikelehen @schmidt-sebastian
22+
1823
# Storage Code
1924
src/storage @sphippen
2025
tests/storage @sphippen

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- script: ./integration/serviceWorker/runner.sh
3131
- script: ./integration/quickstart/runner.sh
3232
- script: ./integration/messaging/runner.sh
33+
- script: ./integration/firestore/runner.sh
3334

3435
# Misc Addons/Configs
3536
dist: trusty
@@ -45,4 +46,4 @@ addons:
4546

4647
branches:
4748
only:
48-
- master
49+
- master

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Firestore Unit Tests (Node)",
11+
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
12+
"args": ["test", "--suite=firestore/unit/", "--env=node"],
13+
"port": 9229,
14+
"protocol": "inspector"
15+
},
16+
{
17+
"type": "node",
18+
"request": "launch",
19+
"name": "Firestore Unit Tests (Browser)",
20+
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
21+
"args": ["test", "--suite=firestore/unit/", "--env=browser", "--debug"]
22+
},
23+
{
24+
"type": "node",
25+
"request": "launch",
26+
"name": "Firestore Integration Tests (Browser)",
27+
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
28+
"args": ["test", "--suite=firestore/integration", "--env=browser", "--debug"]
29+
}
30+
]
31+
}

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// Ruler can't be specified via editorconfig
3+
"editor.rulers": [80],
4+
5+
"search.exclude": {
6+
// Exclude gulp build outputs from search results
7+
"dist": true,
8+
9+
// Exclude installed dependencies from searches too
10+
"**/node_modules": true
11+
}
12+
}

README.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ To get started using Firebase, see
1616

1717
### Prerequisites
1818

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

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

5959
## Testing the SDK
6060

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

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

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

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

76-
- Unit Tests (`gulp test:unit`)
77-
- Integration Tests (`gulp test:integration`)
77+
#### Database Rules
7878

79-
_NOTE: You can execute each of these tasks on their own (e.g. you can run
80-
`gulp test:unit` to run exclusively the smoke tests from your CLI)_
79+
_i.e._
80+
81+
```json
82+
{
83+
"rules": {
84+
".read": "true",
85+
".write": "true"
86+
}
87+
}
88+
```
89+
90+
#### Authentiaction Support
91+
92+
Enable the `Anonymous` sign-in provider.
93+
94+
### Running the tests
95+
96+
After you have the `project.json` and have properly configured the project,
97+
simply run: `npm test` at the root of this package.
98+
99+
You can also run the tests by calling `gulp test` if you have gulp installed.
100+
101+
You can decrease the testing scope by providing the optional `suite`/`env` arguments to `npm/gulp test`.
102+
103+
_e.g._
104+
105+
```bash
106+
$ gulp test --suite=firestore --env=node
107+
```
108+
109+
Any directory path in the tests directory serves as a valid value for the `--suite` flag.
110+
111+
Valid values for the `--env` flag are `node`/`browser`.
112+
113+
### Integration Tests
114+
115+
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):
81116

82117
## Building the SDK
83118

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

123158
#### Legacy Files

gulp/config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ const configObj = {
5757
]
5858
},
5959
karma: {
60+
autoWatch: false,
61+
6062
// base path that will be used to resolve all patterns (eg. files, exclude)
6163
basePath: '',
62-
64+
65+
browserNoActivityTimeout: 30000,
66+
6367
customHeaders: [{
6468
match: '.*',
6569
name: 'Service-Worker-Allowed',
@@ -127,4 +131,4 @@ const configObj = {
127131
configObj.karma.client.mocha.timeout = configObj.testConfig.timeout;
128132
configObj.karma.client.mocha.retries = configObj.testConfig.retries;
129133

130-
module.exports = configObj;
134+
module.exports = configObj;

gulp/tasks/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function compileIndvES2015ModulesToBrowser() {
120120
'firebase-storage': './src/storage.ts',
121121
'firebase-messaging': './src/messaging.ts',
122122
'firebase-database': './src/database.ts',
123+
'firebase-firestore': './src/firestore.ts',
123124
},
124125
output: {
125126
filename: '[name].js',
@@ -168,7 +169,8 @@ function compileIndvES2015ModulesToBrowser() {
168169
mangle: {
169170
props: {
170171
ignore_quoted: true,
171-
regex: /^_|_$/,
172+
// NOTE: Firestore uses __foo__ variables that must not be mangled.
173+
regex: /^_[^_]|[^_]_$/
172174
}
173175
},
174176
compress: {
@@ -189,7 +191,11 @@ function compileIndvES2015ModulesToBrowser() {
189191
}
190192

191193
function buildBrowserFirebaseJs() {
192-
return gulp.src('./dist/browser/*.js')
194+
// Exclude firebase-firestore from combined firebase.js
195+
return gulp.src([
196+
'./dist/browser/*.js',
197+
'!./dist/browser/firebase-firestore.js'
198+
])
193199
.pipe(sourcemaps.init({ loadMaps: true }))
194200
.pipe(concat('firebase.js'))
195201
.pipe(sourcemaps.write('.'))
@@ -431,4 +437,4 @@ const buildSDK = exports.buildSDK = gulp.series([
431437
logFileSize
432438
]);
433439

434-
gulp.task('build', buildSDK);
440+
gulp.task('build', buildSDK);

gulp/tasks/dev.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@
1515
*/
1616
const gulp = require('gulp');
1717
const config = require('../config');
18+
const argv = require('yargs').argv;
1819

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

2223
function watchDevFiles() {
24+
// Default to just running browser tests
25+
if (!argv.env) {
26+
argv.env = 'browser';
27+
}
28+
2329
const stream = gulp.watch([
2430
`${config.root}/src/**/*.ts`,
2531
'tests/**/*.test.ts'
26-
], testFxns.runBrowserUnitTests(true));
32+
], testFxns.runTests);
2733

2834
stream.on('error', err => {});
2935
return stream;
3036
}
3137

3238
gulp.task('dev', gulp.parallel([
3339
watchDevFiles
34-
]));
40+
]));

gulp/tasks/test.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function runNodeTest(suite = '**') {
2727
*/
2828
return gulp.src([
2929
`tests/**/${suite}/**/*.test.ts`,
30+
'src/firestore/platform_node/node_init.ts',
31+
// TODO(b/66918026): Re-enable Firestore integration tests on node.
32+
'!tests/firestore/integration/**/*.test.ts',
3033
'!tests/**/browser/**/*.test.ts',
3134
'!tests/**/binary/**/*.test.ts',
3235
'!src/firebase-*.ts',
@@ -38,21 +41,23 @@ function runNodeTest(suite = '**') {
3841
reporter: 'spec',
3942
compilers: 'ts:ts-node/register',
4043
timeout: config.testConfig.timeout,
41-
retries: config.testConfig.retries
44+
retries: config.testConfig.retries,
45+
inspect: true
4246
}))
4347
.on('error', err => {
4448
if (err && err.message && ~err.message.indexOf('No test files found')) return;
4549
throw err;
4650
});
4751
}
4852

49-
function runBrowserTest(suite = '**') {
53+
function runBrowserTest(suite = '.*', debug) {
5054
return new Promise((resolve, reject) => {
51-
const karmaConfig = Object.assign({}, config.karma, {
55+
let karmaConfig = Object.assign({}, config.karma, {
5256
// list of files / patterns to load in the browser
5357
files: [
5458
`./src/**/*.ts`,
55-
`./tests/**/${suite}/**/*.ts`
59+
`./tests/**/*.ts`,
60+
{ pattern: `./tests/config/**/*`, included: false, served: true }
5661
],
5762

5863
// list of files to exclude from the included globs above
@@ -70,28 +75,53 @@ function runBrowserTest(suite = '**') {
7075
'./tests/**/binary/**/*.test.ts',
7176
],
7277
});
78+
79+
Object.assign(karmaConfig.karmaTypescriptConfig, {
80+
bundlerOptions: {
81+
entrypoints: new RegExp(`^.*tests/${suite}.*\.test\.ts$|^.*src/firestore/platform_browser/browser_init.ts$`)
82+
}
83+
});
84+
85+
if (debug) {
86+
karmaConfig = Object.assign({}, karmaConfig, {
87+
autoWatch: true,
88+
singleRun: false,
89+
browsers: ['Chrome']
90+
});
91+
92+
Object.assign(karmaConfig.karmaTypescriptConfig, {
93+
coverageOptions: {
94+
instrumentation: false
95+
}
96+
});
97+
}
98+
7399
new karma.Server(karmaConfig, exitcode => {
74100
if (exitcode) return reject(exitcode);
75101
resolve();
76102
}).start();
77103
});
78104
}
79105

80-
function runTests() {
81-
const suite = argv.suite || '**';
106+
function runTests(devMode) {
107+
const suite = argv.suite || '';
82108
const env = argv.env || '*';
109+
const debug = !!argv.debug || false;
110+
console.log('debug:', debug);
83111
console.log(`Values: ${suite}:${env}`);
84112

85113
switch(env) {
86114
case 'node': return runNodeTest(suite);
87-
case 'browser': return runBrowserTest(suite);
115+
case 'browser': return runBrowserTest(suite, debug);
88116
default:
89117
// Incidentally this works returning a stream and promise value
90118
return Promise.all([
91119
runNodeTest(suite),
92-
runBrowserTest(suite),
120+
runBrowserTest(suite, debug),
93121
]);
94122
}
95123
}
96124

125+
exports.runTests = runTests;
126+
97127
gulp.task('test', runTests);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Replacement for tests/firestore/integration/util/firebase_export.ts,
18+
// loading firebase from the npm module instead of from sources.
19+
import * as firebase from 'firebase';
20+
import 'firebase/firestore';
21+
22+
export default firebase;

0 commit comments

Comments
 (0)