File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
packages/rules-unit-testing Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -87,16 +87,23 @@ export function getEmulatorHostAndPort(
87
87
conf ?: EmulatorConfig ,
88
88
discovered ?: DiscoveredEmulators
89
89
) {
90
- if ( conf && 'host' in conf && 'port' in conf ) {
90
+ if ( conf && ( 'host' in conf || 'port' in conf ) ) {
91
+ const { host, port } = conf as any ;
92
+ if ( ! host || ! port ) {
93
+ throw new Error (
94
+ `Invalid configuration ${ emulator } .host=${ host } and ${ emulator } .port=${ port } . ` +
95
+ 'If either parameter is supplied, both must be defined.'
96
+ ) ;
97
+ }
91
98
if ( discovered && ! discovered [ emulator ] ) {
92
99
console . warn (
93
100
`Warning: config for the ${ emulator } emulator is specified, but the Emulator hub ` +
94
101
'reports it as not running. This may lead to errors such as connection refused.'
95
102
) ;
96
103
}
97
104
return {
98
- host : fixHostname ( conf . host , discovered ?. hub ?. host ) ,
99
- port : conf . port
105
+ host : fixHostname ( host , discovered ?. hub ?. host ) ,
106
+ port : port
100
107
} ;
101
108
}
102
109
const envVar = EMULATOR_HOST_ENV_VARS [ emulator ] ;
Original file line number Diff line number Diff line change @@ -140,6 +140,22 @@ describe('getEmulatorHostAndPort()', () => {
140
140
expect ( result ?. host ) . to . equal ( '::1' ) ;
141
141
} ) ;
142
142
143
+ it ( 'throws if only host is present' , async ( ) => {
144
+ expect ( ( ) =>
145
+ getEmulatorHostAndPort ( 'hub' , {
146
+ host : '[::1]'
147
+ } as HostAndPort )
148
+ ) . to . throw ( / h u b .p o r t = u n d e f i n e d / ) ;
149
+ } ) ;
150
+
151
+ it ( 'throws if only port is present' , async ( ) => {
152
+ expect ( ( ) =>
153
+ getEmulatorHostAndPort ( 'database' , {
154
+ port : 1234
155
+ } as HostAndPort )
156
+ ) . to . throw ( / I n v a l i d c o n f i g u r a t i o n d a t a b a s e .h o s t = u n d e f i n e d / ) ;
157
+ } ) ;
158
+
143
159
it ( 'uses discovered host/port if both config and env var are unset' , async ( ) => {
144
160
const result = getEmulatorHostAndPort ( 'hub' , undefined , {
145
161
hub : { host : '::1' , port : 3333 }
You can’t perform that action at this time.
0 commit comments