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 all commits
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
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ 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
npm test
npm run api-extractor
- name: Lint and run unit tests
run: npm test
- name: Run api-extractor
run: 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
firebase emulators:exec --project fake-project-id --only auth,database,firestore \
'npx mocha \"test/integration/{auth,database,firestore}.spec.ts\" --slow 5000 --timeout 20000 --require ts-node/register'
23 changes: 22 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,26 @@ 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
firebase emulators:exec --project fake-project-id --only auth,database,firestore \
'npx mocha \"test/integration/{auth,database,firestore}.spec.ts\" --slow 5000 --timeout 20000 --require ts-node/register'
```

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
10 changes: 8 additions & 2 deletions test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,10 @@ describe('admin.auth', () => {
});
});

it('can link/unlink with a federated provider', async () => {
it('can link/unlink with a federated provider', async function () {
if (authEmulatorHost) {
return this.skip(); // Not yet supported in Auth Emulator.
}
const googleFederatedUid = 'google_uid_' + generateRandomString(10);
let userRecord = await admin.auth().updateUser(updateUser.uid, {
providerToLink: {
Expand All @@ -707,7 +710,10 @@ describe('admin.auth', () => {
expect(providerIds).to.not.deep.include('google.com');
});

it('can unlink multiple providers at once, incl a non-federated provider', async () => {
it('can unlink multiple providers at once, incl a non-federated provider', async function () {
if (authEmulatorHost) {
return this.skip(); // Not yet supported in Auth Emulator.
}
await deletePhoneNumberUser('+15555550001');

const googleFederatedUid = 'google_uid_' + generateRandomString(10);
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