Skip to content

Commit c653f95

Browse files
committed
Add emulator-based integration tests.
1 parent 6ce98e2 commit c653f95

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ jobs:
1717
uses: actions/setup-node@v1
1818
with:
1919
node-version: ${{ matrix.node-version }}
20-
- name: Install, build and test
20+
- name: Install and build
2121
run: |
2222
npm ci
2323
npm run build
2424
npm run build:tests
25+
- name: Lint and run unit tests
26+
run: |
2527
npm test
2628
npm run api-extractor
29+
- name: Run emulator-based integration tests
30+
run: |
31+
npm install -g firebase-tools
32+
npm integration:emulator

CONTRIBUTING.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ There are two test suites: unit and integration. The unit test suite is intended
123123
development, and the integration test suite is intended to be run before packaging up release
124124
candidates.
125125

126+
#### Unit Tests
127+
126128
To run the unit test suite:
127129

128130
```bash
@@ -135,7 +137,25 @@ If you wish to skip the linter, and only run the unit tests:
135137
$ npm run test:unit
136138
```
137139

138-
The integration tests run against an actual Firebase project. Create a new
140+
#### Integration Tests with Emulator Suite
141+
142+
Some of the integration tests work with the Emulator Suite and you can run them
143+
without an actual Firebase project.
144+
145+
First, make sure to [install Firebase CLI](https://firebase.google.com/docs/cli#install_the_firebase_cli).
146+
And then:
147+
148+
```bash
149+
npm integration:emulator
150+
```
151+
152+
Currently, only the Auth, Database, and Firestore test suites work. Some test
153+
cases will be automatically skipped due to lack of emulator support. The section
154+
below covers how to run the full test suite against an actual Firebase project.
155+
156+
#### Integration Tests with an actual Firebase project
157+
158+
Other integration tests require an actual Firebase project. Create a new
139159
project in the [Firebase Console](https://console.firebase.google.com), if you
140160
do not already have one suitable for running the tests against. Then obtain the
141161
following credentials from the project:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"lint": "run-p lint:src lint:test",
1616
"test": "run-s lint test:unit",
1717
"integration": "run-s build test:integration",
18+
"integration:emulator": "run-s build test:integration:emulator",
1819
"test:unit": "mocha test/unit/*.spec.ts --require ts-node/register",
1920
"test:integration": "mocha test/integration/*.ts --slow 5000 --timeout 20000 --require ts-node/register",
21+
"test:integration:emulator": "firebase emulators:exec --project fake-project-id --only auth,database,firestore 'mocha \"test/integration/{auth,database,firestore}.spec.ts\" --slow 5000 --timeout 20000 --require ts-node/register'",
2022
"test:coverage": "nyc npm run test:unit",
2123
"lint:src": "eslint src/ --ext .ts",
2224
"lint:test": "eslint test/ --ext .ts",

test/integration/database.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as admin from '../../lib/index';
1818
import * as chai from 'chai';
1919
import * as chaiAsPromised from 'chai-as-promised';
20-
import { defaultApp, nullApp, nonNullApp, cmdArgs, databaseUrl } from './setup';
20+
import { defaultApp, nullApp, nonNullApp, cmdArgs, databaseUrl, isEmulator } from './setup';
2121

2222
// eslint-disable-next-line @typescript-eslint/no-var-requires
2323
const chalk = require('chalk');
@@ -64,7 +64,13 @@ describe('admin.database', () => {
6464
.should.eventually.be.fulfilled;
6565
});
6666

67-
it('App with null auth overrides is blocked by security rules', () => {
67+
it('App with null auth overrides is blocked by security rules', function () {
68+
if (isEmulator) {
69+
// RTDB emulator has open security rules by default and won't block this.
70+
// TODO(https://github.com/firebase/firebase-admin-node/issues/1149):
71+
// remove this once updating security rules through admin is in place.
72+
return this.skip();
73+
}
6874
return nullApp.database().ref('blocked').set(admin.database.ServerValue.TIMESTAMP)
6975
.should.eventually.be.rejectedWith('PERMISSION_DENIED: Permission denied');
7076
});
@@ -157,13 +163,21 @@ describe('admin.database', () => {
157163
});
158164
});
159165

160-
it('admin.database().getRules() returns currently defined rules as a string', () => {
166+
it('admin.database().getRules() returns currently defined rules as a string', function () {
167+
if (isEmulator) {
168+
// https://github.com/firebase/firebase-admin-node/issues/1149
169+
return this.skip();
170+
}
161171
return admin.database().getRules().then((result) => {
162172
return expect(result).to.be.not.empty;
163173
});
164174
});
165175

166-
it('admin.database().getRulesJSON() returns currently defined rules as an object', () => {
176+
it('admin.database().getRulesJSON() returns currently defined rules as an object', function () {
177+
if (isEmulator) {
178+
// https://github.com/firebase/firebase-admin-node/issues/1149
179+
return this.skip();
180+
}
167181
return admin.database().getRulesJSON().then((result) => {
168182
return expect(result).to.be.not.undefined;
169183
});

0 commit comments

Comments
 (0)