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(
8787 conf ?: EmulatorConfig ,
8888 discovered ?: DiscoveredEmulators
8989) {
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+ }
9198 if ( discovered && ! discovered [ emulator ] ) {
9299 console . warn (
93100 `Warning: config for the ${ emulator } emulator is specified, but the Emulator hub ` +
94101 'reports it as not running. This may lead to errors such as connection refused.'
95102 ) ;
96103 }
97104 return {
98- host : fixHostname ( conf . host , discovered ?. hub ?. host ) ,
99- port : conf . port
105+ host : fixHostname ( host , discovered ?. hub ?. host ) ,
106+ port : port
100107 } ;
101108 }
102109 const envVar = EMULATOR_HOST_ENV_VARS [ emulator ] ;
Original file line number Diff line number Diff line change @@ -140,6 +140,22 @@ describe('getEmulatorHostAndPort()', () => {
140140 expect ( result ?. host ) . to . equal ( '::1' ) ;
141141 } ) ;
142142
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+
143159 it ( 'uses discovered host/port if both config and env var are unset' , async ( ) => {
144160 const result = getEmulatorHostAndPort ( 'hub' , undefined , {
145161 hub : { host : '::1' , port : 3333 }
You can’t perform that action at this time.
0 commit comments