File tree 1 file changed +18
-0
lines changed
packages/mongodb-memory-server-core/src/util/getport/__tests__
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -58,5 +58,23 @@ describe('getport', () => {
58
58
const testPort = 23000 ;
59
59
await expect ( getPort . getFreePort ( testPort ) ) . resolves . toStrictEqual ( testPort ) ;
60
60
} ) ;
61
+
62
+ it ( 'port should be predictable' , async ( ) => {
63
+ const testPort = 23232 ;
64
+ await expect ( getPort . getFreePort ( testPort ) ) . resolves . toStrictEqual ( testPort ) ;
65
+
66
+ const server = await new Promise <
67
+ http . Server < typeof http . IncomingMessage , typeof http . ServerResponse >
68
+ > ( ( res ) => {
69
+ const server = http . createServer ( ) ;
70
+ server . unref ( ) ;
71
+ server . listen ( testPort , ( ) => res ( server ) ) ;
72
+ } ) ;
73
+
74
+ const foundPort = await getPort . getFreePort ( testPort ) ;
75
+ expect ( foundPort ) . toStrictEqual ( testPort + 2 ) ; // predictable result
76
+
77
+ server . close ( ) ;
78
+ } ) ;
61
79
} ) ;
62
80
} ) ;
You can’t perform that action at this time.
0 commit comments