Skip to content

Commit f246e21

Browse files
committed
Fix tests
1 parent e1ab520 commit f246e21

File tree

20 files changed

+92
-82
lines changed

20 files changed

+92
-82
lines changed

integration/typescript/test/namespace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import * as firebase from 'firebase';
1919
import * as namespaceDefinition from '../../shared/namespaceDefinition.json';
20-
import * as validateNamespace from '../../shared/validator';
20+
import validateNamespace from '../../shared/validator';
2121

2222
firebase.initializeApp({
2323
apiKey: 'test-api-key',

integration/typescript/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"noImplicitAny": true,
1010
"outDir": "dist",
1111
"target": "ES5",
12-
"sourceMap": true
12+
"sourceMap": true,
13+
"esModuleInterop": true
1314
},
1415
"exclude": [
1516
"node_modules",

packages/app/test/firebaseApp.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ function executeFirebaseTests() {
161161
const [app, , instanceIdentifier] = args;
162162
return new TestService(app, instanceIdentifier);
163163
},
164-
null,
165-
null,
164+
undefined,
165+
undefined,
166166
true
167167
);
168168
firebase.initializeApp({});
@@ -200,8 +200,8 @@ function executeFirebaseTests() {
200200
const [app, , instanceIdentifier] = args;
201201
return new TestService(app, instanceIdentifier);
202202
},
203-
null,
204-
null,
203+
undefined,
204+
undefined,
205205
false // <-- multi instance flag
206206
);
207207
firebase.initializeApp({});
@@ -268,11 +268,13 @@ function executeFirebaseTests() {
268268
// service's value.
269269
return (app as _FirebaseApp).INTERNAL.getToken()
270270
.then(token => {
271-
assert.equal('tokenFor0', token.accessToken);
271+
assert.isNotNull(token);
272+
assert.equal('tokenFor0', token!.accessToken);
272273
return (app2 as _FirebaseApp).INTERNAL.getToken();
273274
})
274275
.then(token => {
275-
assert.equal('tokenFor1', token.accessToken);
276+
assert.isNotNull(token);
277+
assert.equal('tokenFor1', token!.accessToken);
276278
});
277279
});
278280
});

packages/functions/src/api/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
110110
* @param origin The origin of the local emulator, such as
111111
* "http://localhost:5005".
112112
*/
113-
useFunctionsEmulator(origin: string) {
113+
useFunctionsEmulator(origin: string | null) {
114114
this.emulatorOrigin = origin;
115115
}
116116

packages/functions/test/callable.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Firebase Functions > Call', () => {
6969
functions = new Service(app, region);
7070
if (useEmulator) {
7171
functions.useFunctionsEmulator(
72-
process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN
72+
process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN!
7373
);
7474
}
7575
});

packages/logger/test/logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('@firebase/logger', () => {
6262
} call \`console.${channel}\` if \`.${channel}\` is called`, () => {
6363
client[channel](message);
6464
expect(
65-
spies[`${channel}Spy`] && spies[`${channel}Spy`].called,
65+
spies[`${channel}Spy`]!.called,
6666
`Expected ${channel} to ${shouldLog ? '' : 'not'} log`
6767
).to.be[shouldLog ? 'true' : 'false'];
6868
});

packages/rxfire/test/database.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ let batch = (items: any[]) => {
4141
};
4242

4343
describe('RxFire Database', () => {
44-
let app: app.App = null;
45-
let database: database.Database = null;
44+
let app: app.App | null = null;
45+
let database: database.Database | null = null;
4646
let ref = (path: string) => {
47-
app.database().goOffline();
48-
return app.database().ref(path);
47+
app!.database().goOffline();
48+
return app!.database().ref(path);
4949
};
5050

5151
function prepareList(
@@ -85,7 +85,7 @@ describe('RxFire Database', () => {
8585
});
8686

8787
afterEach((done: MochaDone) => {
88-
app.delete().then(() => done());
88+
app && app.delete().then(() => done());
8989
});
9090

9191
describe('fromRef', () => {
@@ -147,7 +147,7 @@ describe('RxFire Database', () => {
147147
count = count + 1;
148148
const { event, snapshot } = change;
149149
expect(event).to.equal(ListenEvent.added);
150-
expect(snapshot.val()).to.eql(data[snapshot.key]);
150+
expect(snapshot.val()).to.eql(data[snapshot.key || '']);
151151
if (count === items.length) {
152152
done();
153153
sub.unsubscribe();
@@ -396,7 +396,7 @@ describe('RxFire Database', () => {
396396
expect(data.length).to.eql(items.length - 1);
397397
})
398398
.add(done);
399-
app.database().goOnline();
399+
app && app.database().goOnline();
400400
aref.set(itemsObj).then(() => {
401401
aref.child(items[0].key).remove();
402402
});
@@ -419,7 +419,7 @@ describe('RxFire Database', () => {
419419
expect(data[1].name).to.eql('lol');
420420
})
421421
.add(done);
422-
app.database().goOnline();
422+
app && app.database().goOnline();
423423
aref.set(itemsObj).then(() => {
424424
aref.child(items[1].key).update({ name: 'lol' });
425425
});
@@ -444,7 +444,7 @@ describe('RxFire Database', () => {
444444
expect(data[data.length - 1]).to.eql(items[0]);
445445
})
446446
.add(done);
447-
app.database().goOnline();
447+
app && app.database().goOnline();
448448
aref.set(itemsObj).then(() => {
449449
aref.child(items[0].key).setPriority('a', () => {});
450450
});
@@ -542,7 +542,7 @@ describe('RxFire Database', () => {
542542
expect(data).to.eql(copy);
543543
})
544544
.add(done);
545-
app.database().goOnline();
545+
app && app.database().goOnline();
546546
ref.set(itemsObj).then(() => {
547547
ref.child(items[0].key).update({ name });
548548
});

packages/rxfire/test/firestore.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const seedTest = firestore => {
6767
};
6868

6969
describe('RxFire Firestore', () => {
70-
let app: app.App = null;
71-
let firestore: firestore.Firestore = null;
70+
let app: app.App | null = null;
71+
let firestore: firestore.Firestore | null = null;
7272

7373
/**
7474
* Each test runs inside it's own app instance and the app
@@ -88,7 +88,7 @@ describe('RxFire Firestore', () => {
8888
});
8989

9090
afterEach((done: MochaDone) => {
91-
app.delete().then(() => done());
91+
app && app.delete().then(() => done());
9292
});
9393

9494
describe('collection', () => {

packages/rxfire/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"declaration": true
66
},
77
"exclude": [
8-
"dist/**/*",
9-
"test/**/*"
8+
"dist/**/*"
109
]
1110
}

packages/storage/src/implementation/observer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
* limitations under the License.
1616
*/
1717
import * as type from './type';
18+
import { FirebaseStorageError } from './error';
1819

1920
type NextFn<T> = (value: T) => void;
20-
type ErrorFn = (error: Error) => void;
21+
type ErrorFn = (error: Error | FirebaseStorageError) => void;
2122
type CompleteFn = () => void;
2223
type Unsubscribe = () => void;
2324

2425
type Subscribe<T> = (
25-
next: NextFn<T> | { [name: string]: string | null } | null,
26-
error?: ErrorFn,
27-
complete?: CompleteFn
26+
next: NextFn<T> | { [name: string]: string | null } | null | undefined,
27+
error: ErrorFn | null | undefined,
28+
complete: CompleteFn | null | undefined
2829
) => Unsubscribe;
2930

3031
export { NextFn, ErrorFn, CompleteFn, Unsubscribe, Subscribe };
@@ -34,12 +35,12 @@ export { NextFn, ErrorFn, CompleteFn, Unsubscribe, Subscribe };
3435
*/
3536
export class Observer<T> {
3637
next: NextFn<T> | null;
37-
error: ErrorFn | null;
38+
error: ErrorFn | null | undefined;
3839
complete: CompleteFn | null;
3940

4041
constructor(
41-
nextOrObserver: NextFn<T> | { [name: string]: string | null } | null,
42-
opt_error?: ErrorFn | null,
42+
nextOrObserver: NextFn<T> | { [name: string]: string | null } | null | undefined,
43+
opt_error?: ErrorFn | null | undefined,
4344
opt_complete?: CompleteFn | null
4445
) {
4546
let asFunctions =

packages/storage/src/task.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ export class UploadTask {
455455
*/
456456
on(
457457
type: TaskEvent,
458-
nextOrObserver = null,
459-
error = undefined,
460-
completed = undefined
458+
nextOrObserver: NextFn<UploadTaskSnapshot> | { [name: string]: any } | null | undefined = undefined,
459+
error: ErrorFn | null | undefined = undefined,
460+
completed: CompleteFn | null | undefined = undefined
461461
): Unsubscribe | Subscribe<UploadTaskSnapshot> {
462462
function typeValidator(_p: any) {
463463
if (type !== TaskEvent.STATE_CHANGED) {
@@ -505,9 +505,10 @@ export class UploadTask {
505505
nextOrObserver:
506506
| NextFn<UploadTaskSnapshot>
507507
| { [name: string]: string | null }
508-
| null,
509-
error?: ErrorFn | null,
510-
opt_complete?: CompleteFn | null
508+
| null
509+
| undefined,
510+
error?: ErrorFn | null | undefined,
511+
opt_complete?: CompleteFn | null | undefined
511512
) {
512513
if (specs !== null) {
513514
fbsArgs.validate('on', specs, arguments);
@@ -633,13 +634,13 @@ export class UploadTask {
633634
break;
634635
case TaskState.CANCELED:
635636
case TaskState.ERROR:
636-
if (observer.error !== null) {
637+
if (observer.error) {
637638
fbsAsync(observer.error.bind(observer, this.error_ as Error))();
638639
}
639640
break;
640641
default:
641642
// TODO(andysoto): assert(false);
642-
if (observer.error !== null) {
643+
if (observer.error) {
643644
fbsAsync(observer.error.bind(observer, this.error_ as Error))();
644645
}
645646
}

packages/storage/test/blob.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as type from '../src/implementation/type';
2222
import * as testShared from './testshared';
2323

2424
describe('Firebase Storage > Blob', () => {
25-
let stubs = [];
25+
let stubs: Array<sinon.SinonStub> = [];
2626
before(() => {
2727
const definedStub = sinon.stub(type, 'isNativeBlobDefined');
2828
definedStub.returns(false);
@@ -42,16 +42,18 @@ describe('Firebase Storage > Blob', () => {
4242
it('Slicing works', () => {
4343
const blob = new FbsBlob(new Uint8Array([1, 2, 3, 4, 5, 6, 7]));
4444
const sliced = blob.slice(1, 5);
45+
assert.isNotNull(sliced);
4546
testShared.assertUint8ArrayEquals(
46-
sliced.uploadData() as Uint8Array,
47+
sliced!.uploadData() as Uint8Array,
4748
new Uint8Array([2, 3, 4, 5])
4849
);
4950
});
5051
it('Blobs are merged with strings correctly', () => {
5152
const blob = new FbsBlob(new Uint8Array([1, 2, 3, 4]));
5253
const merged = FbsBlob.getBlob('what', blob, '\ud83d\ude0a ');
54+
assert.isNotNull(merged);
5355
testShared.assertUint8ArrayEquals(
54-
merged.uploadData() as Uint8Array,
56+
merged!.uploadData() as Uint8Array,
5557
new Uint8Array([
5658
0x77,
5759
0x68,
@@ -80,6 +82,7 @@ describe('Firebase Storage > Blob', () => {
8082

8183
const concatenated = FbsBlob.getBlob(blob1, blob2);
8284

83-
assert.equal(20, concatenated.size());
85+
assert.isNotNull(concatenated);
86+
assert.equal(20, concatenated!.size());
8487
});
8588
});

packages/storage/test/reference.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function makeFakeService(app: FirebaseApp, sendHook: SendHook): Service {
3131
return new Service(app, testShared.makePool(sendHook));
3232
}
3333

34-
function makeStorage(url: string) {
34+
function makeStorage(url: string): Reference {
3535
function maker(wrapper, loc) {
3636
return ({} as any) as Reference;
3737
}
@@ -106,11 +106,11 @@ describe('Firebase Storage > Reference', () => {
106106
assert.isNull(root.parent);
107107
});
108108
it('Returns root one level down', () => {
109-
assert.equal(child.parent.toString(), 'gs://test-bucket/');
109+
assert.equal(child.parent!.toString(), 'gs://test-bucket/');
110110
});
111111
it('Works correctly with empty levels', () => {
112112
const s = makeStorage('gs://test-bucket/a///');
113-
assert.equal(s.parent.toString(), 'gs://test-bucket/a/');
113+
assert.equal(s.parent!.toString(), 'gs://test-bucket/a/');
114114
});
115115
});
116116

@@ -185,7 +185,7 @@ describe('Firebase Storage > Reference', () => {
185185
headers?: Headers
186186
) {
187187
assert.isDefined(headers);
188-
assert.isUndefined(headers['Authorization']);
188+
assert.isUndefined(headers!['Authorization']);
189189
done();
190190
}
191191

@@ -205,7 +205,7 @@ describe('Firebase Storage > Reference', () => {
205205
) {
206206
assert.isDefined(headers);
207207
assert.equal(
208-
headers['Authorization'],
208+
headers!['Authorization'],
209209
'Firebase ' + testShared.authToken
210210
);
211211
done();
@@ -222,15 +222,15 @@ describe('Firebase Storage > Reference', () => {
222222
const task = child.putString('hello', StringFormat.RAW, {
223223
contentType: 'lol/wut'
224224
} as Metadata);
225-
assert.equal(task.snapshot.metadata.contentType, 'lol/wut');
225+
assert.equal(task.snapshot.metadata!.contentType, 'lol/wut');
226226
task.cancel();
227227
});
228228
it('Uses embedded content type in DATA_URL format', () => {
229229
const task = child.putString(
230230
'data:lol/wat;base64,aaaa',
231231
StringFormat.DATA_URL
232232
);
233-
assert.equal(task.snapshot.metadata.contentType, 'lol/wat');
233+
assert.equal(task.snapshot.metadata!.contentType, 'lol/wat');
234234
task.cancel();
235235
});
236236
it('Lets metadata.contentType override embedded content type in DATA_URL format', () => {
@@ -239,7 +239,7 @@ describe('Firebase Storage > Reference', () => {
239239
StringFormat.DATA_URL,
240240
{ contentType: 'tomato/soup' } as Metadata
241241
);
242-
assert.equal(task.snapshot.metadata.contentType, 'tomato/soup');
242+
assert.equal(task.snapshot.metadata!.contentType, 'tomato/soup');
243243
task.cancel();
244244
});
245245
});

0 commit comments

Comments
 (0)