Skip to content

Commit 49e265e

Browse files
authored
Add prettier to repo (#55)
1 parent d2afd7a commit 49e265e

22 files changed

+201
-127
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"arrowParens": "always",
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
}

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- '8'
4-
- '10'
5-
- stable
3+
- '8'
4+
- '10'
5+
- stable
66
sudo: false

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"lint": "node_modules/.bin/tslint src/{**/*,*}.ts spec/{**/*,*}.ts",
1111
"pretest": "node_modules/.bin/tsc",
1212
"test": "mocha .tmp/spec/index.spec.js",
13-
"posttest": "npm run lint && rm -rf .tmp"
13+
"posttest": "npm run lint && rm -rf .tmp",
14+
"format": "prettier --check '**/*.{json,ts,yml,yaml}'",
15+
"format:fix": "prettier --write '**/*.{json,ts,yml,yaml}'"
1416
},
1517
"repository": {
1618
"type": "git",
@@ -40,6 +42,7 @@
4042
"firebase-admin": "~8.9.0",
4143
"firebase-functions": "^3.3.0",
4244
"mocha": "^6.2.2",
45+
"prettier": "^1.19.1",
4346
"sinon": "^7.5.0",
4447
"tslint": "^5.20.0",
4548
"typescript": "^3.6.4"

spec/index.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { expect } from 'chai';
2525

2626
describe('index', () => {
2727
/* tslint:disable-next-line:no-var-requires */
28-
const indexExport = require('../src')({projectId: 'fakeProject'}, 'fakeServiceAccount');
28+
const indexExport = require('../src')(
29+
{ projectId: 'fakeProject' },
30+
'fakeServiceAccount'
31+
);
2932
after(() => {
3033
// Call cleanup (handles case of cleanup function not existing)
3134
indexExport.cleanup && indexExport.cleanup();
@@ -48,8 +51,12 @@ describe('index', () => {
4851
});
4952

5053
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');
54+
expect(process.env.FIREBASE_CONFIG).to.equal(
55+
JSON.stringify({ projectId: 'fakeProject' })
56+
);
57+
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal(
58+
'fakeServiceAccount'
59+
);
5360
});
5461

5562
it('should clean up env variables once cleanup is called', () => {

spec/lifecycle.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ describe('lifecycle', () => {
4040

4141
it('sets env variables appropriately if SDK initialized without parameters', () => {
4242
test.init();
43-
expect(process.env.FIREBASE_CONFIG).to.equal(JSON.stringify({
44-
databaseURL: 'https://not-a-project.firebaseio.com',
45-
storageBucket: 'not-a-project.appspot.com',
46-
projectId: 'not-a-project',
47-
}));
43+
expect(process.env.FIREBASE_CONFIG).to.equal(
44+
JSON.stringify({
45+
databaseURL: 'https://not-a-project.firebaseio.com',
46+
storageBucket: 'not-a-project.appspot.com',
47+
projectId: 'not-a-project',
48+
})
49+
);
4850
expect(process.env.GCLOUD_PROJECT).to.equal('not-a-project');
4951
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.be.undefined;
5052
});
@@ -57,9 +59,13 @@ describe('lifecycle', () => {
5759
};
5860
test.init(firebaseConfig, 'path/to/key.json');
5961

60-
expect(process.env.FIREBASE_CONFIG).to.equal(JSON.stringify(firebaseConfig));
62+
expect(process.env.FIREBASE_CONFIG).to.equal(
63+
JSON.stringify(firebaseConfig)
64+
);
6165
expect(process.env.GCLOUD_PROJECT).to.equal('my-project');
62-
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal('path/to/key.json');
66+
expect(process.env.GOOGLE_APPLICATION_CREDENTIALS).to.equal(
67+
'path/to/key.json'
68+
);
6369
});
6470
});
6571

@@ -81,7 +87,7 @@ describe('lifecycle', () => {
8187
it('deletes all the env variables if they did not previously exist', () => {
8288
let test = new FirebaseFunctionsTest();
8389
test.init();
84-
mockConfig({ foo: {bar: 'faz '}});
90+
mockConfig({ foo: { bar: 'faz ' } });
8591
test.cleanup();
8692
expect(process.env.FIREBASE_CONFIG).to.be.undefined;
8793
expect(process.env.GCLOUD_PROJECT).to.be.undefined;

spec/main.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ import { mockConfig, makeChange, _makeResourceName, wrap } from '../src/main';
2828

2929
describe('main', () => {
3030
describe('#wrap', () => {
31-
3231
const constructCF = (eventType?: string) => {
3332
const cloudFunction = (input) => input;
3433
set(cloudFunction, 'run', (data, context) => {
35-
return { data, context };
36-
});
34+
return { data, context };
35+
});
3736
set(cloudFunction, '__trigger', {
3837
eventTrigger: {
3938
resource: 'ref/{wildcard}/nested/{anotherWildcard}',
@@ -53,8 +52,11 @@ describe('main', () => {
5352
const context = wrap(constructCF())('data').context;
5453
expect(typeof context.eventId).to.equal('string');
5554
expect(context.resource.service).to.equal('service');
56-
expect(/ref\/wildcard[1-9]\/nested\/anotherWildcard[1-9]/
57-
.test(context.resource.name)).to.be.true;
55+
expect(
56+
/ref\/wildcard[1-9]\/nested\/anotherWildcard[1-9]/.test(
57+
context.resource.name
58+
)
59+
).to.be.true;
5860
expect(context.eventType).to.equal('event');
5961
expect(Date.parse(context.timestamp)).to.be.greaterThan(0);
6062
expect(context.params).to.deep.equal({});
@@ -73,7 +75,9 @@ describe('main', () => {
7375
});
7476

7577
it('should generate auth and authType for database functions', () => {
76-
const context = wrap(constructCF('google.firebase.database.ref.write'))('data').context;
78+
const context = wrap(constructCF('google.firebase.database.ref.write'))(
79+
'data'
80+
).context;
7781
expect(context.auth).to.equal(null);
7882
expect(context.authType).to.equal('UNAUTHENTICATED');
7983
});
@@ -90,10 +94,12 @@ describe('main', () => {
9094

9195
it('should throw when passed invalid options', () => {
9296
const wrapped = wrap(constructCF());
93-
expect(() => wrapped('data', {
97+
expect(() =>
98+
wrapped('data', {
9499
auth: { uid: 'abc' },
95100
isInvalid: true,
96-
} as any)).to.throw();
101+
} as any)
102+
).to.throw();
97103
});
98104

99105
it('should generate the appropriate resource based on params', () => {

spec/providers/database.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ describe('providers/database', () => {
1515
});
1616

1717
it('produces the right snapshot with makeDataSnapshot', async () => {
18-
const snapshot = makeDataSnapshot({
19-
foo: 'bar',
20-
}, 'path');
18+
const snapshot = makeDataSnapshot(
19+
{
20+
foo: 'bar',
21+
},
22+
'path'
23+
);
2124

22-
expect(snapshot.val()).to.deep.equal({foo: 'bar'});
25+
expect(snapshot.val()).to.deep.equal({ foo: 'bar' });
2326
expect(snapshot.ref.key).to.equal('path');
2427
});
2528

spec/providers/firestore.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ describe('providers/firestore', () => {
55
it('produces the right snapshot with makeDocumentSnapshot', async () => {
66
const test = fft();
77

8-
const snapshot = test.firestore.makeDocumentSnapshot({
9-
email_address: '[email protected]',
10-
}, 'collection/doc-id');
8+
const snapshot = test.firestore.makeDocumentSnapshot(
9+
{
10+
email_address: '[email protected]',
11+
},
12+
'collection/doc-id'
13+
);
1114

1215
expect(snapshot.data()).to.deep.equal({
1316
email_address: '[email protected]',
@@ -18,7 +21,10 @@ describe('providers/firestore', () => {
1821
it('should allow empty document in makeDocumentSnapshot', async () => {
1922
const test = fft();
2023

21-
const snapshot = test.firestore.makeDocumentSnapshot({}, 'collection/doc-id');
24+
const snapshot = test.firestore.makeDocumentSnapshot(
25+
{},
26+
'collection/doc-id'
27+
);
2228

2329
expect(snapshot.data()).to.deep.equal(undefined);
2430
expect(snapshot.id).to.equal('doc-id');

spec/providers/https.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ describe('providers/https', () => {
3737
it('should run the wrapped onCall function and return result', async () => {
3838
const test = fft();
3939

40-
const result = await test.wrap(cfToUpperCaseOnCall)({ message: 'lowercase' });
40+
const result = await test.wrap(cfToUpperCaseOnCall)({
41+
message: 'lowercase',
42+
});
4143

4244
expect(result).to.deep.equal({ msg: 'LOWERCASE', from: 'anonymous' });
4345
});
4446

4547
it('should accept auth params', async () => {
4648
const test = fft();
47-
const options = {auth: {uid: 'abc'}};
49+
const options = { auth: { uid: 'abc' } };
4850

49-
const result = await test.wrap(cfToUpperCaseOnCall)({ message: 'lowercase' }, options);
51+
const result = await test.wrap(cfToUpperCaseOnCall)(
52+
{ message: 'lowercase' },
53+
options
54+
);
5055

51-
expect(result).to.deep.equal({msg: 'LOWERCASE', from: 'abc'});
56+
expect(result).to.deep.equal({ msg: 'LOWERCASE', from: 'abc' });
5257
});
5358

5459
it('should accept raw request', async () => {
5560
const mockRequest: any = (sessionData) => {
5661
return {
57-
session: {data: sessionData},
62+
session: { data: sessionData },
5863
};
5964
};
6065
mockRequest.rawBody = Buffer.from('foobar');
@@ -65,7 +70,7 @@ describe('providers/https', () => {
6570

6671
const result = await test.wrap(cfToUpperCaseOnCall)(
6772
{ message: 'lowercase' },
68-
options,
73+
options
6974
);
7075

7176
expect(result).to.deep.equal({

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function testApp(): testApp.App {
3333
/** @internal */
3434
export namespace testApp {
3535
export let singleton: testApp.App;
36-
export let init = () => singleton = new testApp.App();
36+
export let init = () => (singleton = new testApp.App());
3737

3838
export class App {
3939
appSingleton: firebase.app.App;
@@ -44,7 +44,7 @@ export namespace testApp {
4444
this.appSingleton = firebase.initializeApp(
4545
JSON.parse(process.env.FIREBASE_CONFIG),
4646
// Give this app a name so it does not conflict with apps that user initialized.
47-
'firebase-functions-test',
47+
'firebase-functions-test'
4848
);
4949
}
5050
return this.appSingleton;

src/lifecycle.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,39 @@ export class FirebaseFunctionsTest {
3535

3636
/** Initialize the SDK. */
3737
init(
38-
/** Firebase config values for initializing a Firebase app for your test code to
39-
* interact with (e.g. making database writes). It is recommended that you use
40-
* a project that is specifically for testing. If omitted, mock config values will
41-
* be used and your tests will not interact with a real Firebase app, and all Firebase
42-
* methods need to be stubbed, otherwise they will fail.
43-
*/
44-
firebaseConfig?: AppOptions,
45-
/** Path to a service account key file to be used when initializing the Firebase app. */
46-
pathToServiceAccountKey?: string,
47-
) {
48-
38+
/** Firebase config values for initializing a Firebase app for your test code to
39+
* interact with (e.g. making database writes). It is recommended that you use
40+
* a project that is specifically for testing. If omitted, mock config values will
41+
* be used and your tests will not interact with a real Firebase app, and all Firebase
42+
* methods need to be stubbed, otherwise they will fail.
43+
*/
44+
firebaseConfig?: AppOptions,
45+
/** Path to a service account key file to be used when initializing the Firebase app. */
46+
pathToServiceAccountKey?: string
47+
) {
4948
this._oldEnv = {
5049
FIREBASE_CONFIG: process.env.FIREBASE_CONFIG,
51-
GOOGLE_APPLICATION_CREDENTIALS: process.env.GOOGLE_APPLICATION_CREDENTIALS,
50+
GOOGLE_APPLICATION_CREDENTIALS:
51+
process.env.GOOGLE_APPLICATION_CREDENTIALS,
5252
GCLOUD_PROJECT: process.env.GCLOUD_PROJECT,
5353
CLOUD_RUNTIME_CONFIG: process.env.CLOUD_RUNTIME_CONFIG,
5454
};
5555

5656
if (isEmpty(firebaseConfig)) {
5757
process.env.FIREBASE_CONFIG = JSON.stringify({
58-
databaseURL: 'https://not-a-project.firebaseio.com',
59-
storageBucket: 'not-a-project.appspot.com',
60-
projectId: 'not-a-project',
58+
databaseURL: 'https://not-a-project.firebaseio.com',
59+
storageBucket: 'not-a-project.appspot.com',
60+
projectId: 'not-a-project',
6161
});
6262
} else {
6363
process.env.FIREBASE_CONFIG = JSON.stringify(firebaseConfig);
6464
if (pathToServiceAccountKey) {
6565
process.env.GOOGLE_APPLICATION_CREDENTIALS = pathToServiceAccountKey;
6666
}
6767
}
68-
process.env.GCLOUD_PROJECT = JSON.parse(process.env.FIREBASE_CONFIG).projectId;
68+
process.env.GCLOUD_PROJECT = JSON.parse(
69+
process.env.FIREBASE_CONFIG
70+
).projectId;
6971
}
7072

7173
/** Complete clean up tasks. */

0 commit comments

Comments
 (0)