File tree 2 files changed +6
-8
lines changed
packages/mongodb-memory-server-core/src/util/getport
2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change 1
1
import * as getPort from '../index' ;
2
- import * as http from 'node:http ' ;
2
+ import * as net from 'node:net ' ;
3
3
4
4
// the following tests may fail on systems with actual ports being used in those ranges (20000 to 40000)
5
5
@@ -31,7 +31,7 @@ describe('getport', () => {
31
31
32
32
it ( 'should return "false" on used port' , async ( ) => {
33
33
const testPort = 30000 ;
34
- const blockingServer = http . createServer ( ) ;
34
+ const blockingServer = net . createServer ( ) ;
35
35
blockingServer . unref ( ) ;
36
36
blockingServer . listen ( testPort ) ;
37
37
await expect ( getPort . tryPort ( testPort ) ) . resolves . toStrictEqual ( false ) ;
@@ -63,10 +63,8 @@ describe('getport', () => {
63
63
const testPort = 23232 ;
64
64
await expect ( getPort . getFreePort ( testPort ) ) . resolves . toStrictEqual ( testPort ) ;
65
65
66
- const server = await new Promise <
67
- http . Server < typeof http . IncomingMessage , typeof http . ServerResponse >
68
- > ( ( res ) => {
69
- const server = http . createServer ( ) ;
66
+ const server = await new Promise < net . Server > ( ( res ) => {
67
+ const server = net . createServer ( ) ;
70
68
server . unref ( ) ;
71
69
server . listen ( testPort , ( ) => res ( server ) ) ;
72
70
} ) ;
Original file line number Diff line number Diff line change 1
- import * as http from 'node:http ' ;
1
+ import * as net from 'node:net ' ;
2
2
3
3
/** Linux min port that does not require root permissions */
4
4
export const MIN_PORT = 1024 ;
@@ -101,7 +101,7 @@ export function validPort(port: number): number {
101
101
*/
102
102
export function tryPort ( port : number ) : Promise < boolean > {
103
103
return new Promise ( ( res , rej ) => {
104
- const server = http . createServer ( ) ;
104
+ const server = net . createServer ( ) ;
105
105
106
106
// some engines dont support ".unref"(net / tcp.unref), like "deno" in the past and now "bun"
107
107
if ( typeof server . unref === 'function' ) {
You can’t perform that action at this time.
0 commit comments