Skip to content

Commit fe3c5db

Browse files
authored
Applying Linter on Tests (#201)
* Upgraded tslint to latest * Addressing more lint errors * Addressed all linter errors * Added align rule back * Further tweaks to rules * Fixing test compilation error * Fixing more test compilation errors * More minor improvements to typings * Replacing remaining references to Object type * Updated packages and merged with master * Fixing lint errors in unit tests * Fixing remaining lint errors in unit tests * Updating configuration to lint all source and test files at npm lint * Running different lint targets in parallel
1 parent c8f2ae7 commit fe3c5db

26 files changed

+366
-342
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
"homepage": "https://firebase.google.com/",
88
"scripts": {
99
"build": "gulp build",
10-
"lint": "tslint --project tsconfig-lint.json --format stylish",
10+
"lint": "run-p lint:src lint:unit lint:integration",
1111
"test": "run-s lint test:unit",
1212
"integration": "run-s build test:integration",
1313
"test:unit": "mocha test/unit/*.spec.ts --compilers ts:ts-node/register",
1414
"test:integration": "mocha test/integration/*.ts --slow 5000 --compilers ts:ts-node/register",
15-
"test:coverage": "nyc npm run test:unit"
15+
"test:coverage": "nyc npm run test:unit",
16+
"lint:src": "tslint --format stylish -p tsconfig.json",
17+
"lint:unit": "tslint -c tslint-test.json --format stylish test/unit/*.ts test/unit/**/*.ts",
18+
"lint:integration": "tslint -c tslint-test.json --format stylish test/integration/*.ts"
1619
},
1720
"nyc": {
1821
"extension": [

test/integration/app.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ describe('admin', () => {
2828
});
2929

3030
it('does not load Firestore by default', () => {
31-
let gcloud = require.cache[require.resolve('@google-cloud/firestore')];
31+
const gcloud = require.cache[require.resolve('@google-cloud/firestore')];
3232
expect(gcloud).to.be.undefined;
3333
});
3434

3535
it('loads Firestore when calling admin.firestore', () => {
3636
const firestoreNamespace = admin.firestore;
3737
expect(firestoreNamespace).to.not.be.null;
38-
let gcloud = require.cache[require.resolve('@google-cloud/firestore')];
38+
const gcloud = require.cache[require.resolve('@google-cloud/firestore')];
3939
expect(gcloud).to.not.be.undefined;
4040
});
4141
});
4242

4343
describe('admin.app', () => {
4444
it('admin.app() returns the default App', () => {
45-
let app = admin.app();
45+
const app = admin.app();
4646
expect(app).to.deep.equal(defaultApp);
4747
expect(app.name).to.equal('[DEFAULT]');
4848
expect(app.options.databaseURL).to.equal(databaseUrl);
@@ -51,7 +51,7 @@ describe('admin.app', () => {
5151
});
5252

5353
it('admin.app("null") returns the App named "null"', () => {
54-
let app = admin.app('null');
54+
const app = admin.app('null');
5555
expect(app).to.deep.equal(nullApp);
5656
expect(app.name).to.equal('null');
5757
expect(app.options.databaseURL).to.equal(databaseUrl);
@@ -60,7 +60,7 @@ describe('admin.app', () => {
6060
});
6161

6262
it('admin.app("nonNull") returns the App named "nonNull"', () => {
63-
let app = admin.app('nonNull');
63+
const app = admin.app('nonNull');
6464
expect(app).to.deep.equal(nonNullApp);
6565
expect(app.name).to.equal('nonNull');
6666
expect(app.options.databaseURL).to.equal(databaseUrl);
@@ -69,15 +69,15 @@ describe('admin.app', () => {
6969
});
7070

7171
it('namespace services are attached to the default App', () => {
72-
let app = admin.app();
72+
const app = admin.app();
7373
expect(admin.auth(app).app).to.deep.equal(app);
7474
expect(admin.database(app).app).to.deep.equal(app);
7575
expect(admin.messaging(app).app).to.deep.equal(app);
7676
expect(admin.storage(app).app).to.deep.equal(app);
7777
});
7878

7979
it('namespace services are attached to the named App', () => {
80-
let app = admin.app('null');
80+
const app = admin.app('null');
8181
expect(admin.auth(app).app).to.deep.equal(app);
8282
expect(admin.database(app).app).to.deep.equal(app);
8383
expect(admin.messaging(app).app).to.deep.equal(app);

test/integration/auth.spec.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import * as admin from '../../lib/index';
18-
import {expect} from 'chai';
1918
import * as chai from 'chai';
2019
import * as chaiAsPromised from 'chai-as-promised';
2120
import firebase = require('firebase');
@@ -25,6 +24,8 @@ import {generateRandomString, projectId, apiKey} from './setup';
2524
chai.should();
2625
chai.use(chaiAsPromised);
2726

27+
const expect = chai.expect;
28+
2829
const newUserUid = generateRandomString(20);
2930
const nonexistentUid = generateRandomString(20);
3031
const testPhoneNumber = '+11234567890';
@@ -64,7 +65,7 @@ describe('admin.auth', () => {
6465
});
6566

6667
it('createUser() creates a new user when called without a UID', () => {
67-
let newUserData = clone(mockUserData);
68+
const newUserData = clone(mockUserData);
6869
newUserData.email = generateRandomString(20) + '@example.com';
6970
newUserData.phoneNumber = testPhoneNumber2;
7071
return admin.auth().createUser(newUserData)
@@ -79,7 +80,7 @@ describe('admin.auth', () => {
7980
});
8081

8182
it('createUser() creates a new user with the specified UID', () => {
82-
let newUserData: any = clone(mockUserData);
83+
const newUserData: any = clone(mockUserData);
8384
newUserData.uid = newUserUid;
8485
return admin.auth().createUser(newUserData)
8586
.then((userRecord) => {
@@ -92,7 +93,7 @@ describe('admin.auth', () => {
9293
});
9394

9495
it('createUser() fails when the UID is already in use', () => {
95-
let newUserData: any = clone(mockUserData);
96+
const newUserData: any = clone(mockUserData);
9697
newUserData.uid = newUserUid;
9798
return admin.auth().createUser(newUserData)
9899
.should.eventually.be.rejected.and.have.property('code', 'auth/uid-already-exists');
@@ -120,7 +121,7 @@ describe('admin.auth', () => {
120121
});
121122

122123
it('listUsers() returns up to the specified number of users', () => {
123-
let promises: Promise<admin.auth.UserRecord>[] = [];
124+
const promises: Array<Promise<admin.auth.UserRecord>> = [];
124125
uids.forEach((uid) => {
125126
const tempUserData = {
126127
uid,
@@ -168,7 +169,7 @@ describe('admin.auth', () => {
168169
.then((decodedIdToken) => {
169170
// Verification should succeed. Revoke that user's session.
170171
return new Promise((resolve) => setTimeout(() => resolve(
171-
admin.auth().revokeRefreshTokens(decodedIdToken.sub)
172+
admin.auth().revokeRefreshTokens(decodedIdToken.sub),
172173
), 1000));
173174
})
174175
.then(() => {
@@ -224,7 +225,7 @@ describe('admin.auth', () => {
224225
})
225226
.then((decodedIdToken) => {
226227
// Confirm expected claims set on the user's ID token.
227-
for (let key in customClaims) {
228+
for (const key in customClaims) {
228229
if (customClaims.hasOwnProperty(key)) {
229230
expect(decodedIdToken[key]).to.equal(customClaims[key]);
230231
}
@@ -331,12 +332,12 @@ function deletePhoneNumberUser(phoneNumber) {
331332
/**
332333
* Runs cleanup routine that could affect outcome of tests and removes any
333334
* intermediate users created.
334-
*
335+
*
335336
* @return {Promise} A promise that resolves when test preparations are ready.
336337
*/
337338
function cleanup() {
338339
// Delete any existing users that could affect the test outcome.
339-
let promises: Promise<void>[] = [
340+
const promises: Array<Promise<void>> = [
340341
deletePhoneNumberUser(testPhoneNumber),
341342
deletePhoneNumberUser(testPhoneNumber2),
342343
deletePhoneNumberUser(nonexistentPhoneNumber),
@@ -351,7 +352,7 @@ function cleanup() {
351352
if (error.code !== 'auth/user-not-found') {
352353
throw error;
353354
}
354-
})
355+
}),
355356
);
356357
});
357358
return Promise.all(promises);

test/integration/database.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import * as admin from '../../lib/index';
18-
import {expect} from 'chai';
1918
import * as chai from 'chai';
2019
import * as chaiAsPromised from 'chai-as-promised';
2120
import url = require('url');
@@ -29,6 +28,8 @@ const chalk = require('chalk');
2928
chai.should();
3029
chai.use(chaiAsPromised);
3130

31+
const expect = chai.expect;
32+
3233
const path = 'adminNodeSdkManualTest';
3334

3435
describe('admin.database', () => {
@@ -99,7 +100,7 @@ describe('admin.database', () => {
99100
it('once() returns the current value of the reference', () => {
100101
return ref.once('value')
101102
.then((snapshot) => {
102-
let value = snapshot.val();
103+
const value = snapshot.val();
103104
expect(value.success).to.be.true;
104105
expect(typeof value.timestamp).to.equal('number');
105106
});
@@ -141,7 +142,7 @@ describe('admin.database', () => {
141142
it('once() returns the current value of the reference', () => {
142143
return refWithUrl.once('value')
143144
.then((snapshot) => {
144-
let value = snapshot.val();
145+
const value = snapshot.val();
145146
expect(value.success).to.be.true;
146147
expect(typeof value.timestamp).to.equal('number');
147148
});
@@ -165,6 +166,6 @@ function addValueEventListener(
165166
callback: (s: admin.database.DataSnapshot) => any) {
166167
// Check for type compilation. This method is not invoked by any tests. But it will
167168
// trigger a TS compilation failure if the RTDB typings were not loaded correctly.
168-
let eventType: admin.database.EventType = 'value';
169+
const eventType: admin.database.EventType = 'value';
169170
db.ref().on(eventType, callback);
170171
}

test/integration/firestore.spec.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import * as admin from '../../lib/index';
18-
import {expect} from 'chai';
1918
import * as chai from 'chai';
2019
import * as chaiAsPromised from 'chai-as-promised';
2120
import {clone} from 'lodash';
@@ -24,6 +23,8 @@ import {DocumentReference} from '@google-cloud/firestore';
2423
chai.should();
2524
chai.use(chaiAsPromised);
2625

26+
const expect = chai.expect;
27+
2728
const mountainView = {
2829
name: 'Mountain View',
2930
population: 77846,
@@ -49,31 +50,31 @@ describe('admin.firestore', () => {
4950

5051
it('supports basic data access', () => {
5152
return reference.set(mountainView)
52-
.then(result => {
53+
.then((result) => {
5354
return reference.get();
5455
})
55-
.then(snapshot => {
56-
let data = snapshot.data();
56+
.then((snapshot) => {
57+
const data = snapshot.data();
5758
expect(data).to.deep.equal(mountainView);
5859
return reference.delete();
5960
})
60-
.then(result => {
61+
.then((result) => {
6162
return reference.get();
6263
})
63-
.then(snapshot => {
64+
.then((snapshot) => {
6465
expect(snapshot.exists).to.be.false;
6566
});
6667
}).timeout(5000);
6768

6869
it('admin.firestore.FieldValue.serverTimestamp() provides a server-side timestamp', () => {
69-
let expected: any = clone(mountainView);
70+
const expected: any = clone(mountainView);
7071
expected.timestamp = admin.firestore.FieldValue.serverTimestamp();
7172
return reference.set(expected)
72-
.then(result => {
73+
.then((result) => {
7374
return reference.get();
7475
})
75-
.then(snapshot => {
76-
let data = snapshot.data();
76+
.then((snapshot) => {
77+
const data = snapshot.data();
7778
expect(data.timestamp).is.not.null;
7879
expect(data.timestamp instanceof Date).is.true;
7980
return reference.delete();
@@ -97,16 +98,16 @@ describe('admin.firestore', () => {
9798
const source = admin.firestore().collection('cities').doc();
9899
const target = admin.firestore().collection('cities').doc();
99100
return source.set(mountainView)
100-
.then(result => {
101+
.then((result) => {
101102
return target.set({name: 'Palo Alto', sisterCity: source});
102103
})
103-
.then(result => {
104+
.then((result) => {
104105
return target.get();
105106
})
106-
.then(snapshot => {
107-
let data = snapshot.data();
107+
.then((snapshot) => {
108+
const data = snapshot.data();
108109
expect(data.sisterCity.path).to.deep.equal(source.path);
109-
let promises = [];
110+
const promises = [];
110111
promises.push(source.delete());
111112
promises.push(target.delete());
112113
return Promise.all(promises);
@@ -121,10 +122,10 @@ describe('admin.firestore', () => {
121122
logs.push(log);
122123
});
123124
return source.set({name: 'San Francisco'})
124-
.then(result => {
125+
.then((result) => {
125126
return source.delete();
126127
})
127-
.then(result => {
128+
.then((result) => {
128129
expect(logs.length).greaterThan(0);
129130
});
130131
}).timeout(5000);

test/integration/messaging.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
import * as admin from '../../lib/index';
18-
import {expect} from 'chai';
1918
import * as chai from 'chai';
2019
import * as chaiAsPromised from 'chai-as-promised';
2120

2221
chai.should();
2322
chai.use(chaiAsPromised);
2423

24+
const expect = chai.expect;
25+
2526
// The registration token and notification key have the proper format, but are not guaranteed to
2627
// work. The intention of these integration tests is that the endpoints returns the proper payload,
2728
// but it is hard to ensure these tokens will always be valid. The tests below should still pass

test/integration/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ before(() => {
4444
console.log(chalk.red(
4545
'The integration test suite requires a service account JSON file for a ' +
4646
'Firebase project to be saved to `test/resources/key.json`.',
47-
error
47+
error,
4848
));
4949
throw error;
5050
}
@@ -55,7 +55,7 @@ before(() => {
5555
console.log(chalk.red(
5656
'The integration test suite requires an API key for a ' +
5757
'Firebase project to be saved to `test/resources/apikey.txt`.',
58-
error
58+
error,
5959
));
6060
throw error;
6161
}

test/integration/storage.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import * as admin from '../../lib/index';
18-
import {expect} from 'chai';
1918
import * as chai from 'chai';
2019
import * as chaiAsPromised from 'chai-as-promised';
2120
import {Bucket, File} from '@google-cloud/storage';
@@ -25,6 +24,8 @@ import {projectId} from './setup';
2524
chai.should();
2625
chai.use(chaiAsPromised);
2726

27+
const expect = chai.expect;
28+
2829
describe('admin.storage', () => {
2930
it('bucket() returns a handle to the default bucket', () => {
3031
const bucket: Bucket = admin.storage().bucket();

0 commit comments

Comments
 (0)