Skip to content

Commit

Permalink
Fix bug where setting service account key file location wasn't working (
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenzlong authored Apr 26, 2018
1 parent 2da0c6e commit ee8025c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
4 changes: 3 additions & 1 deletion spec/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import { FirebaseFunctionsTest } from '../src/lifecycle';

describe('app', () => {
let appInstance;
let test = new FirebaseFunctionsTest();
let test;

before(() => {
test = new FirebaseFunctionsTest();
test.init();
appInstance = testApp();
});
Expand Down
42 changes: 26 additions & 16 deletions spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,47 @@
// SOFTWARE.

import 'mocha';
import './lifecycle.spec';
import './main.spec';
import './app.spec';
import { expect } from 'chai';

/* tslint:disable-next-line:no-var-requires */
const indexExport = require('../src')();

describe('index', () => {
/* tslint:disable-next-line:no-var-requires */
const indexExport = require('../src')({ projectId: 'fakeProject' }, 'fakeServiceAccount');
after(() => {
// Call cleanup (handles case of cleanup function not existing)
indexExport.cleanup && indexExport.cleanup();
});

it('should export wrap as a function', () => {
expect(indexExport.wrap).to.be.an('function');
it('should export the expected functions and namespaces', () => {
expect(Object.getOwnPropertyNames(indexExport).sort()).to.deep.equal([
'analytics',
'auth',
'cleanup',
'crashlytics',
'database',
'firestore',
'makeChange',
'mockConfig',
'pubsub',
'storage',
'wrap',
]);
});

it('should export makeChange as a function', () => {
expect(indexExport.makeChange).to.be.an('function');
it('should set env variables based parameters SDK was initialized with', () => {
expect(process.env.FIREBASE_CONFIG).to.equal(JSON.stringify({ projectId: 'fakeProject' }));
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal('fakeServiceAccount');
});

it('should export mockConfig as a function', () => {
expect(indexExport.mockConfig).to.be.an('function');
});

it('should export cleanup as a function', () => {
expect(indexExport.cleanup).to.be.an('function');
it('should clean up env variables once cleanup is called', () => {
indexExport.cleanup();
expect(process.env.FIREBASE_CONFIG).to.equal(undefined);
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal(undefined);
});
});

import './lifecycle.spec';
import './main.spec';
import './app.spec';
// import './providers/analytics.spec';
// import './providers/auth.spec';
// import './providers/database.spec';
Expand Down
7 changes: 6 additions & 1 deletion spec/lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import { afterEach } from 'mocha';

describe('lifecycle', () => {
describe('#init', () => {
let test = new FirebaseFunctionsTest();
let test;

before(() => {
test = new FirebaseFunctionsTest();
});

afterEach(() => {
test.cleanup();
});
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import { merge } from 'lodash';
import { FirebaseFunctionsTest } from './lifecycle';
import { features as lazyFeatures, FeaturesList } from './features';

export = (firebaseConfig?: AppOptions) => {
export = (firebaseConfig?: AppOptions, pathToServiceAccountKey?: string) => {
const test = new FirebaseFunctionsTest();
test.init(firebaseConfig);
test.init(firebaseConfig, pathToServiceAccountKey);
// Ensure other files get loaded after init function, since they load `firebase-functions`
// which will issue warning if process.env.FIREBASE_CONFIG is not yet set.
let features = require('./features').features as typeof lazyFeatures;
features = merge({}, features, {
cleanup: () => test.cleanup,
cleanup: () => test.cleanup(),
});
return features as FeaturesList;
};

0 comments on commit ee8025c

Please sign in to comment.