Skip to content

Commit a20dbea

Browse files
author
Michael Lehenbauer
authored
Enable strict mode for scripts/emulator-testing/. (#2066)
1 parent e4eea3f commit a20dbea

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

scripts/emulator-testing/emulators/database-emulator.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ export class DatabaseEmulator extends Emulator {
2323
namespace: string;
2424

2525
constructor(port = 8088, namespace = 'test-emulator') {
26-
super(port);
26+
super(
27+
'database-emulator.jar',
28+
// Use locked version of emulator for test to be deterministic.
29+
// The latest version can be found from database emulator doc:
30+
// https://firebase.google.com/docs/database/security/test-rules-emulator
31+
'https://storage.googleapis.com/firebase-preview-drop/emulator/firebase-database-emulator-v3.5.0.jar',
32+
port
33+
);
2734
this.namespace = namespace;
28-
this.binaryName = 'database-emulator.jar';
29-
// Use locked version of emulator for test to be deterministic.
30-
// The latest version can be found from database emulator doc:
31-
// https://firebase.google.com/docs/database/security/test-rules-emulator
32-
this.binaryUrl =
33-
'https://storage.googleapis.com/firebase-preview-drop/emulator/firebase-database-emulator-v3.5.0.jar';
3435
}
3536

3637
setPublicRules(): Promise<number> {

scripts/emulator-testing/emulators/emulator.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ export interface ChildProcessPromise extends Promise<void> {
2929
}
3030

3131
export abstract class Emulator {
32-
binaryName: string;
33-
binaryUrl: string;
34-
binaryPath: string;
32+
binaryPath: string | null = null;
33+
emulator: ChildProcess | null = null;
3534

36-
emulator: ChildProcess;
37-
port: number;
38-
39-
constructor(port: number) {
40-
this.port = port;
41-
}
35+
constructor(
36+
private binaryName: string,
37+
private binaryUrl: string,
38+
public port: number
39+
) {}
4240

4341
download(): Promise<void> {
4442
return new Promise<void>((resolve, reject) => {
@@ -71,6 +69,9 @@ export abstract class Emulator {
7169

7270
setUp(): Promise<void> {
7371
return new Promise<void>((resolve, reject) => {
72+
if (!this.binaryPath) {
73+
throw new Error('You must call download() before setUp()');
74+
}
7475
const promise: ChildProcessPromise = spawn(
7576
'java',
7677
['-jar', path.basename(this.binaryPath), '--port', this.port],

scripts/emulator-testing/emulators/firestore-emulator.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ export class FirestoreEmulator extends Emulator {
2121
projectId: string;
2222

2323
constructor(port: number, projectId = 'test-emulator') {
24-
super(port);
24+
super(
25+
'firestore-emulator.jar',
26+
// Use locked version of emulator for test to be deterministic.
27+
// The latest version can be found from firestore emulator doc:
28+
// https://firebase.google.com/docs/firestore/security/test-rules-emulator
29+
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.5.0.jar',
30+
port
31+
);
2532
this.projectId = projectId;
26-
this.binaryName = 'firestore-emulator.jar';
27-
// Use locked version of emulator for test to be deterministic.
28-
// The latest version can be found from firestore emulator doc:
29-
// https://firebase.google.com/docs/firestore/security/test-rules-emulator
30-
this.binaryUrl =
31-
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.6.2.jar';
3233
}
3334
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"extends": "../../config/tsconfig.base.json"
2+
"extends": "../../config/tsconfig.base.json",
3+
4+
"compilerOptions": {
5+
"strictNullChecks": true
6+
}
37
}

0 commit comments

Comments
 (0)