Skip to content

Commit ee8025c

Browse files
authored
Fix bug where setting service account key file location wasn't working (#15)
1 parent 2da0c6e commit ee8025c

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

spec/app.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import { FirebaseFunctionsTest } from '../src/lifecycle';
2929

3030
describe('app', () => {
3131
let appInstance;
32-
let test = new FirebaseFunctionsTest();
32+
let test;
33+
3334
before(() => {
35+
test = new FirebaseFunctionsTest();
3436
test.init();
3537
appInstance = testApp();
3638
});

spec/index.spec.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,47 @@
2121
// SOFTWARE.
2222

2323
import 'mocha';
24-
import './lifecycle.spec';
25-
import './main.spec';
26-
import './app.spec';
2724
import { expect } from 'chai';
2825

29-
/* tslint:disable-next-line:no-var-requires */
30-
const indexExport = require('../src')();
31-
3226
describe('index', () => {
27+
/* tslint:disable-next-line:no-var-requires */
28+
const indexExport = require('../src')({ projectId: 'fakeProject' }, 'fakeServiceAccount');
3329
after(() => {
3430
// Call cleanup (handles case of cleanup function not existing)
3531
indexExport.cleanup && indexExport.cleanup();
3632
});
3733

38-
it('should export wrap as a function', () => {
39-
expect(indexExport.wrap).to.be.an('function');
34+
it('should export the expected functions and namespaces', () => {
35+
expect(Object.getOwnPropertyNames(indexExport).sort()).to.deep.equal([
36+
'analytics',
37+
'auth',
38+
'cleanup',
39+
'crashlytics',
40+
'database',
41+
'firestore',
42+
'makeChange',
43+
'mockConfig',
44+
'pubsub',
45+
'storage',
46+
'wrap',
47+
]);
4048
});
4149

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

46-
it('should export mockConfig as a function', () => {
47-
expect(indexExport.mockConfig).to.be.an('function');
48-
});
49-
50-
it('should export cleanup as a function', () => {
51-
expect(indexExport.cleanup).to.be.an('function');
55+
it('should clean up env variables once cleanup is called', () => {
56+
indexExport.cleanup();
57+
expect(process.env.FIREBASE_CONFIG).to.equal(undefined);
58+
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal(undefined);
5259
});
5360
});
5461

62+
import './lifecycle.spec';
63+
import './main.spec';
64+
import './app.spec';
5565
// import './providers/analytics.spec';
5666
// import './providers/auth.spec';
5767
// import './providers/database.spec';

spec/lifecycle.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ import { afterEach } from 'mocha';
2828

2929
describe('lifecycle', () => {
3030
describe('#init', () => {
31-
let test = new FirebaseFunctionsTest();
31+
let test;
32+
33+
before(() => {
34+
test = new FirebaseFunctionsTest();
35+
});
36+
3237
afterEach(() => {
3338
test.cleanup();
3439
});

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import { merge } from 'lodash';
2626
import { FirebaseFunctionsTest } from './lifecycle';
2727
import { features as lazyFeatures, FeaturesList } from './features';
2828

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

0 commit comments

Comments
 (0)