Skip to content

Commit 9ee4996

Browse files
authored
Implementing integration tests using TypeScript, Mocha and Chai (#183)
* Experimental TypeScript integration tests * Ported auth and database tests * Added Firestore tests * Added storage() tests * Ported rest of the tests * Renamed to .spec.ts files * Linter fixes * DB rule update * Added license header * Cleaned up test names * Addressed all linter issues * Covering other corner cases * Replaced old integration test sources * Reverting version change * Addressing code review comments * Addressing some code review comments * Increasing timeout for Firestore tests to 5s
1 parent 795ff13 commit 9ee4996

20 files changed

+1094
-1760
lines changed

createReleaseTarball.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fi
152152
echo
153153

154154
echo "[INFO] Running integration tests..."
155-
npm run test:integration -- --overwrite yes
155+
npm run test:integration -- --updateRules
156156
if [[ $? -ne 0 ]]; then
157157
echo "Error: Integration tests failed."
158158
exit 1

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint": "tslint --project tsconfig-lint.json --format stylish",
1111
"test": "run-s lint test:unit",
1212
"integration": "run-s build test:integration",
13-
"test:unit": "mocha test/**/*.spec.ts --compilers ts:ts-node/register",
14-
"test:integration": "node test/integration",
13+
"test:unit": "mocha test/unit/*.spec.ts --compilers ts:ts-node/register",
14+
"test:integration": "mocha test/integration/*.ts --slow 5000 --compilers ts:ts-node/register",
1515
"test:coverage": "nyc npm run test:unit"
1616
},
1717
"nyc": {
@@ -22,8 +22,7 @@
2222
"src"
2323
],
2424
"exclude": [
25-
"**/*.d.ts",
26-
"**/database.js"
25+
"**/*.d.ts"
2726
],
2827
"all": true
2928
},
@@ -84,6 +83,7 @@
8483
"gulp-typescript": "^3.1.2",
8584
"lodash": "^4.6.1",
8685
"merge2": "^1.0.2",
86+
"minimist": "^1.2.0",
8787
"mocha": "^3.5.0",
8888
"nock": "^9.1.0",
8989
"npm-run-all": "^4.1.2",

test/integration/app.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

test/integration/app.spec.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*!
2+
* Copyright 2018 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+
import * as admin from '../../lib/index';
18+
import {expect} from 'chai';
19+
import {
20+
defaultApp, nullApp, nonNullApp, databaseUrl, projectId, storageBucket,
21+
} from './setup';
22+
23+
describe('admin', () => {
24+
it('populates required test parameters', () => {
25+
expect(databaseUrl).to.be.not.empty;
26+
expect(projectId).to.be.not.empty;
27+
expect(storageBucket).to.be.not.empty;
28+
});
29+
30+
it('does not load Firestore by default', () => {
31+
let gcloud = require.cache[require.resolve('@google-cloud/firestore')];
32+
expect(gcloud).to.be.undefined;
33+
});
34+
35+
it('loads Firestore when calling admin.firestore', () => {
36+
const firestoreNamespace = admin.firestore;
37+
expect(firestoreNamespace).to.not.be.null;
38+
let gcloud = require.cache[require.resolve('@google-cloud/firestore')];
39+
expect(gcloud).to.not.be.undefined;
40+
});
41+
});
42+
43+
describe('admin.app', () => {
44+
it('admin.app() returns the default App', () => {
45+
let app = admin.app();
46+
expect(app).to.deep.equal(defaultApp);
47+
expect(app.name).to.equal('[DEFAULT]');
48+
expect(app.options.databaseURL).to.equal(databaseUrl);
49+
expect(app.options.databaseAuthVariableOverride).to.be.undefined;
50+
expect(app.options.storageBucket).to.equal(storageBucket);
51+
});
52+
53+
it('admin.app("null") returns the App named "null"', () => {
54+
let app = admin.app('null');
55+
expect(app).to.deep.equal(nullApp);
56+
expect(app.name).to.equal('null');
57+
expect(app.options.databaseURL).to.equal(databaseUrl);
58+
expect(app.options.databaseAuthVariableOverride).to.be.null;
59+
expect(app.options.storageBucket).to.equal(storageBucket);
60+
});
61+
62+
it('admin.app("nonNull") returns the App named "nonNull"', () => {
63+
let app = admin.app('nonNull');
64+
expect(app).to.deep.equal(nonNullApp);
65+
expect(app.name).to.equal('nonNull');
66+
expect(app.options.databaseURL).to.equal(databaseUrl);
67+
expect((app.options.databaseAuthVariableOverride as any).uid).to.be.ok;
68+
expect(app.options.storageBucket).to.equal(storageBucket);
69+
});
70+
71+
it('namespace services are attached to the default App', () => {
72+
let app = admin.app();
73+
expect(admin.auth(app).app).to.deep.equal(app);
74+
expect(admin.database(app).app).to.deep.equal(app);
75+
expect(admin.messaging(app).app).to.deep.equal(app);
76+
expect(admin.storage(app).app).to.deep.equal(app);
77+
});
78+
79+
it('namespace services are attached to the named App', () => {
80+
let app = admin.app('null');
81+
expect(admin.auth(app).app).to.deep.equal(app);
82+
expect(admin.database(app).app).to.deep.equal(app);
83+
expect(admin.messaging(app).app).to.deep.equal(app);
84+
expect(admin.storage(app).app).to.deep.equal(app);
85+
});
86+
});

0 commit comments

Comments
 (0)