Skip to content

Commit 4097d31

Browse files
committed
Add tests
1 parent b03c38f commit 4097d31

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

packages-exp/performance-exp/src/index.test.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
*/
1717

1818
import { expect } from 'chai';
19-
import { stub } from 'sinon';
2019
import { initializePerformance } from './index';
2120
import { ERROR_FACTORY, ErrorCode } from './utils/errors';
22-
import * as firebase from '@firebase/app-exp';
23-
import { Provider } from '@firebase/component';
2421
import '../test/setup';
22+
import { deleteApp, FirebaseApp, initializeApp } from '@firebase/app-exp';
2523

2624
const fakeFirebaseConfig = {
2725
apiKey: 'api-key',
@@ -33,17 +31,44 @@ const fakeFirebaseConfig = {
3331
appId: '1:111:web:a1234'
3432
};
3533

36-
const fakeFirebaseApp = ({
37-
options: fakeFirebaseConfig
38-
} as unknown) as firebase.FirebaseApp;
34+
// const fakeFirebaseApp = ({
35+
// options: fakeFirebaseConfig
36+
// } as unknown) as firebase.FirebaseApp;
3937

4038
describe('Firebase Performance > initializePerformance()', () => {
41-
it('throws if a perf instance has already been created', () => {
42-
stub(firebase, '_getProvider').returns(({
43-
isInitialized: () => true
44-
} as unknown) as Provider<'performance-exp'>);
39+
let app: FirebaseApp;
40+
beforeEach(() => {
41+
app = initializeApp(fakeFirebaseConfig);
42+
});
43+
afterEach(() => {
44+
return deleteApp(app);
45+
});
46+
it('returns same instance if given same (no) params a second time', () => {
47+
const performanceInstance = initializePerformance(app);
48+
expect(initializePerformance(app)).to.equal(performanceInstance);
49+
});
50+
it('returns same instance if given same params a second time', () => {
51+
const performanceInstance = initializePerformance(app, { dataCollectionEnabled: false });
52+
expect(initializePerformance(app, { dataCollectionEnabled: false })).to.equal(performanceInstance);
53+
});
54+
it('throws if called with params after being called with no params', () => {
55+
initializePerformance(app);
56+
const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_INITIALIZED);
57+
expect(() => initializePerformance(app, { dataCollectionEnabled: false })).to.throw(
58+
expectedError.message
59+
);
60+
});
61+
it('throws if called with no params after being called with params', () => {
62+
initializePerformance(app, { instrumentationEnabled: false });
63+
const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_INITIALIZED);
64+
expect(() => initializePerformance(app)).to.throw(
65+
expectedError.message
66+
);
67+
});
68+
it('throws if called a second time with different params', () => {
69+
initializePerformance(app, { instrumentationEnabled: true });
4570
const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_INITIALIZED);
46-
expect(() => initializePerformance(fakeFirebaseApp)).to.throw(
71+
expect(() => initializePerformance(app, { instrumentationEnabled: false })).to.throw(
4772
expectedError.message
4873
);
4974
});

tools/gitHooks/prettier.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
const { resolve } = require('path');
19-
const { spawn } = require('child-process-promise');
19+
const { exec, spawn } = require('child-process-promise');
2020
const fs = require('mz/fs');
2121
const glob = require('glob');
2222
const simpleGit = require('simple-git/promise');
@@ -101,7 +101,7 @@ async function doPrettier(changedFiles) {
101101
}
102102

103103
const gitSpinner = ora(' Git staging prettier formatting changes.').start();
104-
await git.add(targetFiles);
104+
await exec('git add -u .', {stdio: 'inherit'});
105105
gitSpinner.stopAndPersist({
106106
symbol: '▶️'
107107
});

0 commit comments

Comments
 (0)