Skip to content

Commit 94cf316

Browse files
Fix Integration tests against 'minified' sources (#2445)
1 parent e4d0455 commit 94cf316

File tree

14 files changed

+358
-318
lines changed

14 files changed

+358
-318
lines changed

integration/firestore/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function copyTests() {
5757
* differences, as well as different paths to a valid firebase_export
5858
*/
5959
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
60-
'declare var firebase;'
60+
"import * as firebase from 'firebase';"
6161
)
6262
)
6363
.pipe(

packages/firestore/src/api/credentials.ts

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

18-
import { _FirebaseApp } from '@firebase/app-types/private';
1918
import { User } from '../auth/user';
2019
import { assert } from '../util/assert';
2120
import { Code, FirestoreError } from '../util/error';

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import * as integrationHelpers from '../util/helpers';
2525
// tslint:disable:no-floating-promises
2626

2727
const apiDescribe = integrationHelpers.apiDescribe;
28-
const Timestamp = firebase.firestore!.Timestamp;
28+
const FieldPath = firebase.firestore!.FieldPath;
2929
const FieldValue = firebase.firestore!.FieldValue;
30+
const Timestamp = firebase.firestore!.Timestamp;
3031

3132
apiDescribe('Database batch writes', (persistence: boolean) => {
3233
it('supports empty batches', () => {
@@ -108,13 +109,7 @@ apiDescribe('Database batch writes', (persistence: boolean) => {
108109
return doc.firestore
109110
.batch()
110111
.set(doc, initialData)
111-
.update(
112-
doc,
113-
'owner.name',
114-
'Sebastian',
115-
new firebase.firestore!.FieldPath('is.admin'),
116-
true
117-
)
112+
.update(doc, 'owner.name', 'Sebastian', new FieldPath('is.admin'), true)
118113
.commit()
119114
.then(() => doc.get())
120115
.then(docSnapshot => {

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

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import * as chaiAsPromised from 'chai-as-promised';
2020
import * as firestore from '@firebase/firestore-types';
2121
import { expect, use } from 'chai';
2222

23-
import { SimpleDb } from '../../../src/local/simple_db';
24-
import { fail } from '../../../src/util/assert';
25-
import { Code } from '../../../src/util/error';
26-
import { query } from '../../util/api_helpers';
2723
import { Deferred } from '../../util/promise';
2824
import { EventsAccumulator } from '../util/events_accumulator';
2925
import firebase from '../util/firebase_export';
@@ -34,16 +30,15 @@ import {
3430
withTestDbs,
3531
withTestDoc,
3632
withTestDocAndInitialData,
37-
DEFAULT_SETTINGS,
38-
withMockCredentialProviderTestDb
33+
DEFAULT_SETTINGS
3934
} from '../util/helpers';
40-
import { User } from '../../../src/auth/user';
4135

4236
// tslint:disable:no-floating-promises
4337

4438
use(chaiAsPromised);
4539

4640
const Timestamp = firebase.firestore!.Timestamp;
41+
const FieldPath = firebase.firestore!.FieldPath;
4742
const FieldValue = firebase.firestore!.FieldValue;
4843

4944
apiDescribe('Database', (persistence: boolean) => {
@@ -134,8 +129,10 @@ apiDescribe('Database', (persistence: boolean) => {
134129
.get({ source: 'cache' })
135130
.then(doc => expect(doc.exists).to.be.true);
136131
await readerRef.get({ source: 'cache' }).then(
137-
() => fail('Expected cache miss'),
138-
err => expect(err.code).to.be.equal(Code.UNAVAILABLE)
132+
() => {
133+
expect.fail('Expected cache miss');
134+
},
135+
err => expect(err.code).to.be.equal('unavailable')
139136
);
140137
await writerRef
141138
.get()
@@ -488,8 +485,6 @@ apiDescribe('Database', (persistence: boolean) => {
488485
});
489486

490487
it('can update nested fields', () => {
491-
const FieldPath = firebase.firestore!.FieldPath;
492-
493488
return withTestDoc(persistence, doc => {
494489
const initialData = {
495490
desc: 'Description',
@@ -818,7 +813,8 @@ apiDescribe('Database', (persistence: boolean) => {
818813
// have security rules support or something?
819814
// eslint-disable-next-line no-restricted-properties
820815
describe.skip('Listens are rejected remotely:', () => {
821-
const queryForRejection = query('foo');
816+
//eslint-disable-next-line @typescript-eslint/no-explicit-any
817+
const queryForRejection : firestore.Query = null as any;
822818

823819
it('will reject listens', () => {
824820
const deferred = new Deferred();
@@ -856,7 +852,7 @@ apiDescribe('Database', (persistence: boolean) => {
856852
it('will reject gets', () => {
857853
return queryForRejection.get().then(
858854
() => {
859-
throw new Error('Promise resolved even though error was expected.');
855+
expect.fail('Promise resolved even though error was expected.');
860856
},
861857
err => {
862858
expect(err.name).to.exist;
@@ -870,7 +866,7 @@ apiDescribe('Database', (persistence: boolean) => {
870866
.get()
871867
.then(
872868
() => {
873-
throw new Error('Promise resolved even though error was expected.');
869+
expect.fail('Promise resolved even though error was expected.');
874870
},
875871
err => {
876872
expect(err.name).to.exist;
@@ -880,7 +876,7 @@ apiDescribe('Database', (persistence: boolean) => {
880876
.then(() => queryForRejection.get())
881877
.then(
882878
() => {
883-
throw new Error('Promise resolved even though error was expected.');
879+
expect.fail('Promise resolved even though error was expected.');
884880
},
885881
err => {
886882
expect(err.name).to.exist;
@@ -1051,28 +1047,6 @@ apiDescribe('Database', (persistence: boolean) => {
10511047
}
10521048
);
10531049

1054-
// eslint-disable-next-line no-restricted-properties
1055-
(persistence ? it : it.skip)(
1056-
'will reject the promise if clear persistence fails',
1057-
async () => {
1058-
await withTestDoc(persistence, async docRef => {
1059-
const oldDelete = SimpleDb.delete;
1060-
try {
1061-
SimpleDb.delete = (name: string): Promise<void> => {
1062-
return Promise.reject('Failed to delete the database.');
1063-
};
1064-
const firestore = docRef.firestore;
1065-
await firestore.app.delete();
1066-
await expect(
1067-
firestore.clearPersistence()
1068-
).to.eventually.be.rejectedWith('Failed to delete the database.');
1069-
} finally {
1070-
SimpleDb.delete = oldDelete;
1071-
}
1072-
});
1073-
}
1074-
);
1075-
10761050
it('can not clear persistence if the client has been initialized', async () => {
10771051
await withTestDoc(persistence, async docRef => {
10781052
const firestore = docRef.firestore;
@@ -1199,25 +1173,6 @@ apiDescribe('Database', (persistence: boolean) => {
11991173
});
12001174
});
12011175

1202-
it('waiting for pending writes should fail when user changes', async () => {
1203-
await withMockCredentialProviderTestDb(
1204-
persistence,
1205-
async (db, mockCredentialsProvider) => {
1206-
// Prevent pending writes receiving acknowledgement.
1207-
await db.disableNetwork();
1208-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1209-
db.doc('abc/123').set({ foo: 'bar' });
1210-
const awaitPendingWrite = db.waitForPendingWrites();
1211-
1212-
mockCredentialsProvider.triggerUserChange(new User('user_1'));
1213-
1214-
await expect(awaitPendingWrite).to.be.eventually.rejectedWith(
1215-
"'waitForPendingWrites' promise is rejected due to a user change."
1216-
);
1217-
}
1218-
);
1219-
});
1220-
12211176
it('waiting for pending writes resolves immediately when offline and no pending writes', async () => {
12221177
await withTestDoc(persistence, async docRef => {
12231178
const firestore = docRef.firestore;

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

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

1818
import { expect } from 'chai';
19-
import { LogLevel, getLogLevel, setLogLevel } from '../../../src/util/log';
2019
import firebase from '../util/firebase_export';
2120
import {
2221
apiDescribe,
@@ -354,18 +353,12 @@ apiDescribe('Timestamp Fields in snapshots', (persistence: boolean) => {
354353
};
355354

356355
it('are returned as native dates if timestampsInSnapshots set to false', () => {
357-
// Avoid the verbose log message triggered by timestampsInSnapshots ==
358-
// false.
359-
const logLevel = getLogLevel();
360-
setLogLevel(LogLevel.SILENT);
361-
362356
const settings = { ...DEFAULT_SETTINGS };
363357
settings['timestampsInSnapshots'] = false;
364358

365359
const timestamp = new Timestamp(100, 123456789);
366360
const testDocs = { a: testDataWithTimestamps(timestamp) };
367361
return withTestCollectionSettings(persistence, settings, testDocs, coll => {
368-
setLogLevel(logLevel);
369362
return coll
370363
.doc('a')
371364
.get()
@@ -420,17 +413,13 @@ apiDescribe('Timestamp Fields in snapshots', (persistence: boolean) => {
420413
});
421414

422415
it('timestampsInSnapshots affects server timestamps', () => {
423-
const logLevel = getLogLevel();
424-
setLogLevel(LogLevel.SILENT);
425-
426416
const settings = { ...DEFAULT_SETTINGS };
427417
settings['timestampsInSnapshots'] = false;
428418
const testDocs = {
429419
a: { timestamp: FieldValue.serverTimestamp() }
430420
};
431421

432422
return withTestCollectionSettings(persistence, settings, testDocs, coll => {
433-
setLogLevel(logLevel);
434423
return coll
435424
.doc('a')
436425
.get()

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

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

21-
import { querySnapshot } from '../../util/api_helpers';
2221
import { addEqualityMatcher } from '../../util/equality_matcher';
23-
import { keys } from '../../util/helpers';
2422
import { Deferred } from '../../util/promise';
2523
import { EventsAccumulator } from '../util/events_accumulator';
2624
import firebase from '../util/firebase_export';
@@ -787,18 +785,19 @@ apiDescribe('Queries', (persistence: boolean) => {
787785
});
788786

789787
it('throws custom error when using docChanges as property', () => {
790-
const querySnap = querySnapshot('foo/bar', {}, {}, keys(), false, false);
791-
792-
const expectedError =
793-
'QuerySnapshot.docChanges has been changed from a property into a method';
794-
// We are testing invalid API usage.
795-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
796-
const docChange = querySnap.docChanges as any;
797-
expect(() => docChange.length).to.throw(expectedError);
798-
expect(() => {
799-
for (const _ of docChange) {
800-
}
801-
}).to.throw(expectedError);
788+
return withTestCollection(persistence, {}, async coll => {
789+
const snapshot = await coll.get();
790+
const expectedError =
791+
'QuerySnapshot.docChanges has been changed from a property into a method';
792+
// We are testing invalid API usage.
793+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
794+
const docChange = snapshot.docChanges as any;
795+
expect(() => docChange.length).to.throw(expectedError);
796+
expect(() => {
797+
for (const _ of docChange) {
798+
}
799+
}).to.throw(expectedError);
800+
});
802801
});
803802

804803
it('can query collection groups', async () => {

0 commit comments

Comments
 (0)