Skip to content

Commit d9168d5

Browse files
committed
Dynamic port for tests.
1 parent 4a49493 commit d9168d5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ import {
6565
ALT_PROJECT_ID,
6666
DEFAULT_PROJECT_ID,
6767
TARGET_DB_ID,
68-
USE_EMULATOR
68+
USE_EMULATOR,
69+
getEmulatorPort
6970
} from '../util/settings';
7071

7172
// We're using 'as any' to pass invalid values to APIs for testing purposes.
@@ -209,10 +210,11 @@ apiDescribe('Validation:', persistence => {
209210
'allows calling connectFirestoreEmulator() after use with same config',
210211
async db => {
211212
if (USE_EMULATOR) {
212-
connectFirestoreEmulator(db, '127.0.0.1', 9000);
213+
const port = getEmulatorPort();
214+
connectFirestoreEmulator(db, '127.0.0.1', port);
213215
await setDoc(doc(db, 'foo/bar'), {});
214216
expect(() =>
215-
connectFirestoreEmulator(db, '127.0.0.1', 9000)
217+
connectFirestoreEmulator(db, '127.0.0.1', port)
216218
).to.not.throw();
217219
}
218220
}
@@ -225,10 +227,11 @@ apiDescribe('Validation:', persistence => {
225227
if (USE_EMULATOR) {
226228
const errorMsg =
227229
'Firestore has already been started and its settings can no longer be changed.';
228-
connectFirestoreEmulator(db, '127.0.0.1', 9000);
230+
const port = getEmulatorPort();
231+
connectFirestoreEmulator(db, '127.0.0.1', port);
229232
await setDoc(doc(db, 'foo/bar'), {});
230233
expect(() =>
231-
connectFirestoreEmulator(db, '127.0.0.1', 9001)
234+
connectFirestoreEmulator(db, '127.0.0.1', port + 1)
232235
).to.throw(errorMsg);
233236
}
234237
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ function getFirestoreHost(targetBackend: TargetBackend): string {
110110
}
111111
}
112112

113+
export function getEmulatorPort(): number {
114+
return parseInt(process.env.FIRESTORE_EMULATOR_PORT || '8080', 10);
115+
}
116+
113117
function getSslEnabled(targetBackend: TargetBackend): boolean {
114118
return targetBackend !== TargetBackend.EMULATOR;
115119
}

0 commit comments

Comments
 (0)