File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { tcpAddress } from './Transports'
2+
3+ describe ( 'tcpAddress' , ( ) => {
4+
5+ const defaults = {
6+ host : '127.0.0.1' ,
7+ port : 4321
8+ }
9+
10+ test ( 'parses a string with host and port' , ( ) => {
11+ expect ( tcpAddress ( 'example.com:2010' , defaults ) ) . toEqual ( {
12+ host : 'example.com' ,
13+ port : 2010
14+ } )
15+ } )
16+
17+ test ( 'parses a number as the port' , ( ) => {
18+ expect ( tcpAddress ( 2020 , defaults ) ) . toEqual ( {
19+ host : '127.0.0.1' ,
20+ port : 2020
21+ } )
22+ } )
23+
24+ test ( 'parses a string with just port' , ( ) => {
25+ expect ( tcpAddress ( '2030' , defaults ) ) . toEqual ( {
26+ host : '127.0.0.1' ,
27+ port : 2030
28+ } )
29+ } )
30+
31+ } )
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ export interface TcpAddress {
3232}
3333
3434export function tcpAddress (
35- address : undefined | string | Omit < TcpAddress , 'type' > ,
35+ address : undefined | string | number | Omit < TcpAddress , 'type' > ,
3636 defaults : {
3737 host : string
3838 port : number
@@ -55,6 +55,8 @@ export function tcpAddress(
5555 } else {
5656 return defaults
5757 }
58+ } else if ( typeof address === 'number' ) {
59+ return { host : defaults . host , port : address }
5860 } else {
5961 const { host = defaults . host , port = defaults . port } = address
6062 return { host, port }
You can’t perform that action at this time.
0 commit comments