Skip to content

Commit 36de953

Browse files
committed
Improve typing for EmulatorConfig.
1 parent ddcfbc4 commit 36de953

File tree

1 file changed

+17
-11
lines changed
  • packages/rules-unit-testing/src/public_types

1 file changed

+17
-11
lines changed

packages/rules-unit-testing/src/public_types/index.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface TestEnvironmentConfig {
9999
* If specified either way, other running emulators can be automatically discovered, and thus do
100100
* not to be explicity specified.
101101
*/
102-
hub?: Pick<EmulatorConfig, 'host' | 'port'>;
102+
hub?: HostAndPort;
103103

104104
/**
105105
* The Database emulator. Its host and port can also be discovered automatically through the hub
@@ -121,26 +121,32 @@ export interface TestEnvironmentConfig {
121121
}
122122

123123
/**
124-
* Configuration for a given emulator.
124+
* An object containing the hostname and port number of an emulator.
125125
* @public
126126
*/
127-
export interface EmulatorConfig {
128-
/** The security rules source code under test for this emulator. Strongly recommended. */
129-
rules?: string;
130-
127+
export interface HostAndPort {
131128
/**
132129
* The host of the emulator. Can be omitted if discovered automatically through the hub or
133130
* specified via environment variables. See {@code TestEnvironmentConfig} for details.
134131
*/
135-
host?: string;
132+
host: string;
136133

137134
/**
138135
* The port of the emulator. Can be omitted if discovered automatically through the hub or
139136
* specified via environment variables. See {@code TestEnvironmentConfig} for details.
140137
*/
141-
port?: number;
138+
port: number;
142139
}
143140

141+
/**
142+
* Configuration for a given emulator.
143+
* @public
144+
*/
145+
export type EmulatorConfig = {
146+
/** The security rules source code under test for this emulator. Strongly recommended. */
147+
rules?: string;
148+
} & (HostAndPort | {}); // Both or none of host and port should be specified.
149+
144150
/**
145151
* An object used to control the rules unit test environment. Can be used to create RulesTestContext
146152
* for different authentication situations.
@@ -154,9 +160,9 @@ export interface RulesTestEnvironment {
154160
* A readonly copy of the emulator config specified or discovered at test environment creation.
155161
*/
156162
readonly emulators: {
157-
database?: { host: string; port: number };
158-
firestore?: { host: string; port: number };
159-
storage?: { host: string; port: number };
163+
database?: HostAndPort;
164+
firestore?: HostAndPort;
165+
storage?: HostAndPort;
160166
};
161167

162168
/**

0 commit comments

Comments
 (0)