Skip to content

Commit 00659ca

Browse files
Enabling TSLint for our test cases
Enabling TSLint for our test cases
2 parents 078f83a + e1d4581 commit 00659ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+103
-118
lines changed

packages/firestore/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"scripts": {
77
"build": "rollup -c",
88
"dev": "rollup -c -w",
9-
"lint": "tslint -p tsconfig.json -c tslint.json src/**/*.ts test/**/*.ts",
10-
"lint:fix": "tslint --fix -p tsconfig.json -c tslint.json src/**/*.ts test/**/*.ts",
9+
"lint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
10+
"lint:fix": "tslint --fix -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
1111
"test": "run-s lint test:all",
1212
"test:all": "run-p test:browser test:node",
1313
"test:browser": "karma start --single-run",

packages/firestore/test/integration/api/database.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
withTestDb,
2626
withTestDoc
2727
} from '../util/helpers';
28+
import { query } from '../../util/api_helpers';
2829

2930
const Timestamp = firebase.firestore.Timestamp;
3031

@@ -419,7 +420,7 @@ apiDescribe('Database', persistence => {
419420
// client-side validation but fail remotely. May need to wait until we
420421
// have security rules support or something?
421422
xdescribe('Listens are rejected remotely:', () => {
422-
let queryForRejection: firestore.Query;
423+
const queryForRejection = query('foo');
423424

424425
it('will reject listens', () => {
425426
const deferred = new Deferred();

packages/firestore/test/integration/api/fields.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
apiDescribe,
2121
DEFAULT_SETTINGS,
2222
toDataArray,
23-
toIds,
2423
withTestCollection,
2524
withTestCollectionSettings,
2625
withTestDoc
@@ -29,8 +28,11 @@ import {
2928
const FieldPath = firebase.firestore.FieldPath;
3029
const Timestamp = firebase.firestore.Timestamp;
3130

31+
// tslint:disable-next-line:no-any Allow custom types for testing.
32+
type AnyTestData = any;
33+
3234
apiDescribe('Nested Fields', persistence => {
33-
const testData = (n?: number): any => {
35+
const testData = (n?: number): AnyTestData => {
3436
n = n || 1;
3537
return {
3638
name: 'room ' + n,
@@ -235,7 +237,7 @@ apiDescribe('Nested Fields', persistence => {
235237
// Datastore currently prohibits having nested fields and fields with dots in
236238
// the same entity, so I'm separating them.
237239
apiDescribe('Fields with special characters', persistence => {
238-
const testData = (n?: number): any => {
240+
const testData = (n?: number): AnyTestData => {
239241
n = n || 1;
240242
return {
241243
field: 'field ' + n,
@@ -341,7 +343,8 @@ apiDescribe('Fields with special characters', persistence => {
341343
});
342344

343345
apiDescribe('Timestamp Fields in snapshots', persistence => {
344-
const testDataWithTimestamps = (ts: any): any => {
346+
// tslint:disable-next-line:no-any Figure out how to pass in the Timestamp type
347+
const testDataWithTimestamps = (ts: any): AnyTestData => {
345348
return { timestamp: ts, nested: { timestamp2: ts } };
346349
};
347350

packages/firestore/test/integration/api/query.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import * as firestore from '@firebase/firestore-types';
2020
import { addEqualityMatcher } from '../../util/equality_matcher';
2121
import { EventsAccumulator } from '../util/events_accumulator';
2222
import firebase from '../util/firebase_export';
23-
import {
24-
apiDescribe,
25-
toDataArray,
26-
withTestCollection,
27-
withTestDbs
28-
} from '../util/helpers';
23+
import { apiDescribe, toDataArray, withTestCollection } from '../util/helpers';
2924
import { Deferred } from '../../util/promise';
3025

3126
const Timestamp = firebase.firestore.Timestamp;

packages/firestore/test/integration/api/server_timestamp.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import { expect } from 'chai';
1818
import * as firestore from '@firebase/firestore-types';
1919

2020
import firebase from '../util/firebase_export';
21-
import { apiDescribe, DEFAULT_SETTINGS, withTestDoc } from '../util/helpers';
21+
import { apiDescribe, withTestDoc } from '../util/helpers';
2222
import { EventsAccumulator } from '../util/events_accumulator';
2323

24+
// tslint:disable-next-line:no-any Allow custom types for testing.
25+
type AnyTestData = any;
26+
2427
const Timestamp = firebase.firestore.Timestamp;
2528

2629
apiDescribe('Server Timestamps', persistence => {
@@ -49,7 +52,7 @@ apiDescribe('Server Timestamps', persistence => {
4952
let listenerRegistration: () => void;
5053

5154
// Returns the expected data, with an arbitrary timestamp substituted in.
52-
function expectedDataWithTimestamp(timestamp: object | null) {
55+
function expectedDataWithTimestamp(timestamp: object | null): AnyTestData {
5356
return { a: 42, when: timestamp, deep: { when: timestamp } };
5457
}
5558

packages/firestore/test/integration/api/transactions.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,16 @@ apiDescribe('Database transactions', persistence => {
375375
return integrationHelpers.withTestDb(persistence, db => {
376376
const doc1 = db.collection('counters').doc();
377377
const doc2 = db.collection('counters').doc();
378-
let tries = 0;
378+
// let tries = 0;
379379
return (
380380
doc1
381381
.set({
382382
count: 15
383383
})
384384
.then(() => {
385385
return db.runTransaction(transaction => {
386-
tries++;
386+
// ++tries;
387+
387388
// Get the first doc.
388389
return (
389390
transaction

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ const validationIt: ValidationIt = Object.assign(
6666
});
6767
},
6868
{
69-
skip: function(
69+
skip(
7070
persistence: boolean,
7171
message: string,
7272
_: (db: firestore.FirebaseFirestore) => void | Promise<any>
73-
) {
73+
): void {
74+
// tslint:disable-next-line:ban
7475
it.skip(message, () => {});
7576
},
76-
only: function(
77+
only(
7778
persistence: boolean,
7879
message: string,
7980
testFunction: (db: firestore.FirebaseFirestore) => void | Promise<any>
80-
) {
81+
): void {
82+
// tslint:disable-next-line:ban
8183
it.only(message, () => {
8284
return withTestDb(persistence, async db => {
8385
const maybePromise = testFunction(db);
@@ -305,7 +307,7 @@ apiDescribe('Validation:', persistence => {
305307
describe('Writes', () => {
306308
/** Class used to verify custom classes can't be used in writes. */
307309
class TestClass {
308-
constructor(public readonly property: string) {}
310+
constructor(readonly property: string) {}
309311
}
310312

311313
validationIt(persistence, 'must be objects.', db => {

packages/firestore/test/integration/remote/stream.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
} from '../../../src/remote/watch_change';
3131
import { AsyncQueue, TimerId } from '../../../src/util/async_queue';
3232
import { Deferred } from '../../../src/util/promise';
33-
import { Datastore } from '../../../src/remote/datastore';
3433
import { setMutation } from '../../util/helpers';
3534
import { withTestDatastore } from '../util/internal_helpers';
3635
import { FirestoreError } from '@firebase/firestore-types';
@@ -50,7 +49,7 @@ const SINGLE_MUTATION = [setMutation('docs/1', { foo: 'bar' })];
5049

5150
class StreamStatusListener implements WatchStreamListener, WriteStreamListener {
5251
private pendingCallbacks: StreamEventType[] = [];
53-
private pendingPromises: Deferred<StreamEventType>[] = [];
52+
private pendingPromises: Array<Deferred<StreamEventType>> = [];
5453

5554
/**
5655
* Returns a Promise that resolves when the next callback fires. Resolves the
@@ -63,7 +62,7 @@ class StreamStatusListener implements WatchStreamListener, WriteStreamListener {
6362
let promise: Promise<StreamEventType>;
6463

6564
if (this.pendingCallbacks.length > 0) {
66-
let pendingCallback = this.pendingCallbacks.shift();
65+
const pendingCallback = this.pendingCallbacks.shift();
6766
promise = Promise.resolve(pendingCallback);
6867
} else {
6968
const deferred = new Deferred<StreamEventType>();
@@ -114,7 +113,7 @@ class StreamStatusListener implements WatchStreamListener, WriteStreamListener {
114113

115114
private async resolvePending(actualCallback: StreamEventType): Promise<void> {
116115
if (this.pendingPromises.length > 0) {
117-
let pendingPromise = this.pendingPromises.shift();
116+
const pendingPromise = this.pendingPromises.shift();
118117
pendingPromise.resolve(actualCallback);
119118
} else {
120119
this.pendingCallbacks.push(actualCallback);
@@ -154,11 +153,9 @@ describe('Watch Stream', () => {
154153
});
155154

156155
describe('Write Stream', () => {
157-
let queue: AsyncQueue;
158156
let streamListener: StreamStatusListener;
159157

160158
beforeEach(() => {
161-
queue = new AsyncQueue();
162159
streamListener = new StreamStatusListener();
163160
});
164161

@@ -213,10 +210,10 @@ describe('Write Stream', () => {
213210
});
214211

215212
it('closes when idle', () => {
216-
let queue = new AsyncQueue();
213+
const queue = new AsyncQueue();
217214

218215
return withTestDatastore(ds => {
219-
let writeStream = ds.newPersistentWriteStream();
216+
const writeStream = ds.newPersistentWriteStream();
220217
writeStream.start(streamListener);
221218
return streamListener
222219
.awaitCallback('open')
@@ -240,10 +237,10 @@ describe('Write Stream', () => {
240237
});
241238

242239
it('cancels idle on write', () => {
243-
let queue = new AsyncQueue();
240+
const queue = new AsyncQueue();
244241

245242
return withTestDatastore(ds => {
246-
let writeStream = ds.newPersistentWriteStream();
243+
const writeStream = ds.newPersistentWriteStream();
247244
writeStream.start(streamListener);
248245
return streamListener
249246
.awaitCallback('open')

packages/firestore/test/integration/util/events_accumulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class EventsAccumulator<T> {
6161
});
6262
}
6363

64-
private checkFulfilled() {
64+
private checkFulfilled(): void {
6565
if (this.deferred !== null && this.events.length >= this.waitingFor) {
6666
const events = this.events.splice(0, this.waitingFor);
6767
this.deferred.resolve(events);

packages/firestore/test/integration/util/firebase_export.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020
// instead.
2121

2222
import firebase from '@firebase/app';
23+
24+
// tslint:disable-next-line:no-default-export
2325
export default firebase;

packages/firestore/test/integration/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function toDataArray(
8888
}
8989

9090
/** Converts a DocumentSet to an array with the id of each document */
91-
export function toIds(docSet: firestore.QuerySnapshot): String[] {
91+
export function toIds(docSet: firestore.QuerySnapshot): string[] {
9292
return docSet.docs.map(d => d.id);
9393
}
9494

packages/firestore/test/integration/util/internal_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Datastore } from '../../../src/remote/datastore';
2121

2222
import { EmptyCredentialsProvider } from '../../../src/api/credentials';
2323
import { PlatformSupport } from '../../../src/platform/platform';
24-
import { AsyncQueue, TimerId } from '../../../src/util/async_queue';
24+
import { AsyncQueue } from '../../../src/util/async_queue';
2525
import { DEFAULT_SETTINGS, DEFAULT_PROJECT_ID } from './helpers';
2626
import { Firestore } from '../../../src/api/database';
2727

packages/firestore/test/unit/api/database.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { expect } from 'chai';
18-
import {
19-
CollectionReference,
20-
DocumentReference,
21-
DocumentSnapshot,
22-
Query,
23-
QuerySnapshot
24-
} from '../../../src/api/database';
2517
import {
2618
collectionReference,
2719
documentReference,

packages/firestore/test/unit/api/document_change.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('DocumentChange:', () => {
3939
query: Query,
4040
initialDocs: Document[],
4141
updates: Array<Document | DocumentKey>
42-
) {
42+
): void {
4343
const view = new View(query, documentKeySet());
4444
const initialSnapshot = applyDocChanges(view, ...initialDocs).snapshot!;
4545
const updatedSnapshot = applyDocChanges(view, ...updates).snapshot;

packages/firestore/test/unit/api/field_path.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { expect } from 'chai';
18-
import { FieldPath } from '../../../src/api/field_path';
1917
import { field, expectEqual, expectNotEqual } from '../../util/helpers';
2018

2119
describe('FieldPath', () => {

packages/firestore/test/unit/api/field_value.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { expect } from 'chai';
1817
import { PublicFieldValue as FieldValue } from '../../../src/api/field_value';
1918
import { expectEqual, expectNotEqual } from '../../util/helpers';
2019

packages/firestore/test/unit/core/query.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { DOCUMENT_KEY_NAME, ResourcePath } from '../../../src/model/path';
2020
import { addEqualityMatcher } from '../../util/equality_matcher';
2121
import {
2222
bound,
23-
dbId,
2423
doc,
2524
expectCorrectComparisons,
2625
expectEqualitySets,

packages/firestore/test/unit/local/encoded_resource_path.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616

1717
import { expect } from 'chai';
1818
import * as EncodedResourcePath from '../../../src/local/encoded_resource_path';
19-
import { PersistenceTransaction } from '../../../src/local/persistence';
20-
import { Persistence } from '../../../src/local/persistence';
2119
import { PersistencePromise } from '../../../src/local/persistence_promise';
2220
import {
2321
SimpleDb,
2422
SimpleDbStore,
2523
SimpleDbTransaction
2624
} from '../../../src/local/simple_db';
2725
import { ResourcePath } from '../../../src/model/path';
28-
import { fail } from '../../../src/util/assert';
2926
import { path } from '../../util/helpers';
3027

31-
import * as persistenceHelpers from './persistence_test_helpers';
32-
3328
let db: SimpleDb;
3429
const sep = '\u0001\u0001';
3530

@@ -202,8 +197,8 @@ function runTransaction<T>(
202197
store: SimpleDbStore<string, boolean>,
203198
transaction: SimpleDbTransaction
204199
) => PersistencePromise<T>
205-
) {
206-
return db.runTransaction('readwrite', ['test'], txn => {
200+
): Promise<T> {
201+
return db.runTransaction<T>('readwrite', ['test'], txn => {
207202
return fn(txn.store<string, boolean>('test'), txn);
208203
});
209204
}

packages/firestore/test/unit/local/indexeddb_schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function withDb(
5959
});
6060
}
6161

62-
function getAllObjectStores(db: IDBDatabase): String[] {
63-
const objectStores: String[] = [];
62+
function getAllObjectStores(db: IDBDatabase): string[] {
63+
const objectStores: string[] = [];
6464
for (let i = 0; i < db.objectStoreNames.length; ++i) {
6565
objectStores.push(db.objectStoreNames.item(i));
6666
}

packages/firestore/test/unit/local/local_store.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ describe('LocalStore w/ IndexedDB Persistence', () => {
270270
genericLocalStoreTests(persistenceHelpers.testIndexedDbPersistence);
271271
});
272272

273-
function genericLocalStoreTests(getPersistence: () => Promise<Persistence>) {
273+
function genericLocalStoreTests(
274+
getPersistence: () => Promise<Persistence>
275+
): void {
274276
let persistence: Persistence;
275277
let localStore: LocalStore;
276278

packages/firestore/test/unit/local/mutation_queue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('IndexedDbMutationQueue', () => {
120120
* Defines the set of tests to run against both mutation queue
121121
* implementations.
122122
*/
123-
function genericMutationQueueTests() {
123+
function genericMutationQueueTests(): void {
124124
addEqualityMatcher();
125125

126126
beforeEach(() => {

0 commit comments

Comments
 (0)