@@ -5,15 +5,15 @@ import { blockPort } from "./utils";
5
5
6
6
const isWindows = process . platform === "win32" ;
7
7
8
- describe ( "getPort ()" , ( ) => {
9
- describe ( "checks ports on default host`" , ( ) => {
10
- let portBlocker : Server ;
8
+ describe ( "getPort" , ( ) => {
9
+ let portBlocker : Server ;
11
10
12
- afterEach ( ( ) => {
13
- portBlocker ?. close ( ) ;
14
- } ) ;
11
+ afterEach ( ( ) => {
12
+ portBlocker ?. close ( ) ;
13
+ } ) ;
15
14
16
- test ( "default port is NOT IN USE" , async ( ) => {
15
+ describe ( "default host`" , ( ) => {
16
+ test ( "default port is not in use" , async ( ) => {
17
17
const port = await getPort ( ) ;
18
18
expect ( port ) . toEqual ( 3000 ) ;
19
19
} ) ;
@@ -24,48 +24,26 @@ describe("getPort ()", () => {
24
24
expect ( port ) . toEqual ( 3001 ) ;
25
25
} ) ;
26
26
} ) ;
27
- } ) ;
28
27
29
- describe ( "getPort (host)" , ( ) => {
30
- describe ( "checks ports on `localhost`" , ( ) => {
31
- let portBlocker : Server ;
32
-
33
- afterEach ( ( ) => {
34
- portBlocker ?. close ( ) ;
35
- } ) ;
36
-
37
- test ( "default port is NOT IN USE" , async ( ) => {
28
+ describe ( "localhost" , ( ) => {
29
+ test ( "default port is not in use" , async ( ) => {
38
30
const port = await getPort ( { host : "localhost" } ) ;
39
31
expect ( port ) . toEqual ( 3000 ) ;
40
32
} ) ;
41
33
42
- test ( "default port is IN USE" , async ( ) => {
34
+ test ( "default port is in use" , async ( ) => {
35
+ process . env . HOST = "localhost" ;
43
36
portBlocker = await blockPort ( 3000 , "localhost" ) ;
44
- const port = await getPort ( { host : "localhost" } ) ;
45
- expect ( port ) . toEqual ( 3001 ) ;
37
+ const port1 = await getPort ( { port : 3000 , portRange : [ 3000 , 3100 ] } ) ;
38
+ expect ( port1 ) . toEqual ( 3001 ) ;
39
+ const port2 = await getPort ( ) ;
40
+ expect ( port2 ) . toEqual ( 3001 ) ;
41
+ const port3 = await getPort ( 3000 ) ;
42
+ expect ( port3 ) . not . toEqual ( 3001 ) ;
46
43
} ) ;
47
44
} ) ;
48
45
} ) ;
49
46
50
- describe ( "getPort (host)" , ( ) => {
51
- let portBlocker : Server ;
52
-
53
- afterEach ( ( ) => {
54
- portBlocker ?. close ( ) ;
55
- } ) ;
56
-
57
- test ( "default port is in use" , async ( ) => {
58
- process . env . HOST = "localhost" ;
59
- portBlocker = await blockPort ( 3000 , "localhost" ) ;
60
- const port1 = await getPort ( { port : 3000 , portRange : [ 3000 , 3100 ] } ) ;
61
- expect ( port1 ) . toEqual ( 3001 ) ;
62
- const port2 = await getPort ( ) ;
63
- expect ( port2 ) . toEqual ( 3001 ) ;
64
- const port3 = await getPort ( 3000 ) ;
65
- expect ( port3 ) . not . toEqual ( 3001 ) ;
66
- } ) ;
67
- } ) ;
68
-
69
47
describe ( "random port" , ( ) => {
70
48
test ( "{ random: true }" , async ( ) => {
71
49
const port = await getPort ( { random : true } ) ;
0 commit comments