Skip to content
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

Add emulator-based integration tests. #1155

Merged
merged 9 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install, build and test
- name: Install and build
run: |
npm ci
npm run build
npm run build:tests
- name: Lint and run unit tests
run: |
yuchenshi marked this conversation as resolved.
Show resolved Hide resolved
npm test
npm run api-extractor
- name: Run emulator-based integration tests
yuchenshi marked this conversation as resolved.
Show resolved Hide resolved
run: |
npm install -g firebase-tools
npm run integration:emulator
yuchenshi marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 21 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ There are two test suites: unit and integration. The unit test suite is intended
development, and the integration test suite is intended to be run before packaging up release
candidates.

#### Unit Tests

To run the unit test suite:

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

The integration tests run against an actual Firebase project. Create a new
#### Integration Tests with Emulator Suite

Some of the integration tests work with the Emulator Suite and you can run them
without an actual Firebase project.

First, make sure to [install Firebase CLI](https://firebase.google.com/docs/cli#install_the_firebase_cli).
And then:

```bash
npm integration:emulator
```

Currently, only the Auth, Database, and Firestore test suites work. Some test
cases will be automatically skipped due to lack of emulator support. The section
below covers how to run the full test suite against an actual Firebase project.

#### Integration Tests with an actual Firebase project

Other integration tests require an actual Firebase project. Create a new
project in the [Firebase Console](https://console.firebase.google.com), if you
do not already have one suitable for running the tests against. Then obtain the
following credentials from the project:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"lint": "run-p lint:src lint:test",
"test": "run-s lint test:unit",
"integration": "run-s build test:integration",
"integration:emulator": "run-s build test:integration:emulator",
"test:unit": "mocha test/unit/*.spec.ts --require ts-node/register",
"test:integration": "mocha test/integration/*.ts --slow 5000 --timeout 20000 --require ts-node/register",
"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'",
yuchenshi marked this conversation as resolved.
Show resolved Hide resolved
"test:coverage": "nyc npm run test:unit",
"lint:src": "eslint src/ --ext .ts",
"lint:test": "eslint test/ --ext .ts",
Expand Down
22 changes: 18 additions & 4 deletions test/integration/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as admin from '../../lib/index';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { defaultApp, nullApp, nonNullApp, cmdArgs, databaseUrl } from './setup';
import { defaultApp, nullApp, nonNullApp, cmdArgs, databaseUrl, isEmulator } from './setup';

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

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

it('admin.database().getRules() returns currently defined rules as a string', () => {
it('admin.database().getRules() returns currently defined rules as a string', function () {
if (isEmulator) {
// https://github.com/firebase/firebase-admin-node/issues/1149
return this.skip();
}
return admin.database().getRules().then((result) => {
return expect(result).to.be.not.empty;
});
});

it('admin.database().getRulesJSON() returns currently defined rules as an object', () => {
it('admin.database().getRulesJSON() returns currently defined rules as an object', function () {
if (isEmulator) {
// https://github.com/firebase/firebase-admin-node/issues/1149
return this.skip();
}
return admin.database().getRulesJSON().then((result) => {
return expect(result).to.be.not.undefined;
});
Expand Down