1
1
'use strict'
2
2
3
- const { test } = require ( 'tap' )
3
+ const { tspl } = require ( '@matteo.collina/tspl' )
4
+ const { test, after } = require ( 'node:test' )
5
+ const { once } = require ( 'node:events' )
4
6
const { Client, errors } = require ( '..' )
5
7
const net = require ( 'node:net' )
6
8
7
- test ( 'https://github.com/mcollina/undici/issues/810' , ( t ) => {
8
- t . plan ( 3 )
9
+ test ( 'https://github.com/mcollina/undici/issues/810' , async ( t ) => {
10
+ t = tspl ( t , { plan : 3 } )
9
11
10
12
let x = 0
11
13
const server = net . createServer ( socket => {
@@ -19,117 +21,127 @@ test('https://github.com/mcollina/undici/issues/810', (t) => {
19
21
socket . write ( '\r\n' )
20
22
}
21
23
} )
22
- t . teardown ( server . close . bind ( server ) )
23
-
24
- server . listen ( 0 , ( ) => {
25
- const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : 2 } )
26
- t . teardown ( client . destroy . bind ( client ) )
27
-
28
- client . request ( {
29
- path : '/' ,
30
- method : 'GET'
31
- } , ( err , data ) => {
32
- t . error ( err )
33
- data . body . resume ( ) . on ( 'end' , ( ) => {
34
- // t.fail() FIX: Should fail.
35
- t . ok ( true , 'pass' )
36
- } ) . on ( 'error' , err => (
37
- t . ok ( err instanceof errors . HTTPParserError )
38
- ) )
39
- } )
40
- client . request ( {
41
- path : '/' ,
42
- method : 'GET'
43
- } , ( err , data ) => {
24
+ after ( ( ) => server . close ( ) )
25
+
26
+ server . listen ( 0 )
27
+
28
+ await once ( server , 'listening' )
29
+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : 2 } )
30
+ after ( ( ) => client . close ( ) )
31
+
32
+ client . request ( {
33
+ path : '/' ,
34
+ method : 'GET'
35
+ } , ( err , data ) => {
36
+ t . ifError ( err )
37
+ data . body . resume ( ) . on ( 'end' , ( ) => {
38
+ // t.fail() FIX: Should fail.
39
+ t . ok ( true , 'pass' )
40
+ } ) . on ( 'error' , err => (
44
41
t . ok ( err instanceof errors . HTTPParserError )
45
- } )
42
+ ) )
43
+ } )
44
+ client . request ( {
45
+ path : '/' ,
46
+ method : 'GET'
47
+ } , ( err , data ) => {
48
+ t . ok ( err instanceof errors . HTTPParserError )
46
49
} )
50
+ await t . completed
47
51
} )
48
52
49
- test ( 'https://github.com/mcollina/undici/issues/810 no pipelining' , ( t ) => {
50
- t . plan ( 2 )
53
+ test ( 'https://github.com/mcollina/undici/issues/810 no pipelining' , async ( t ) => {
54
+ t = tspl ( t , { plan : 2 } )
51
55
52
56
const server = net . createServer ( socket => {
53
57
socket . write ( 'HTTP/1.1 200 OK\r\n' )
54
58
socket . write ( 'Content-Length: 1\r\n\r\n' )
55
59
socket . write ( '11111\r\n' )
56
60
} )
57
- t . teardown ( server . close . bind ( server ) )
58
-
59
- server . listen ( 0 , ( ) => {
60
- const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
61
-
62
- client . request ( {
63
- path : '/' ,
64
- method : 'GET'
65
- } , ( err , data ) => {
66
- t . error ( err )
67
- data . body . resume ( ) . on ( 'end' , ( ) => {
68
- // t.fail() FIX: Should fail.
69
- t . ok ( true , 'pass' )
70
- } )
61
+ after ( ( ) => server . close ( ) )
62
+
63
+ server . listen ( 0 )
64
+
65
+ await once ( server , 'listening' )
66
+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
67
+
68
+ client . request ( {
69
+ path : '/' ,
70
+ method : 'GET'
71
+ } , ( err , data ) => {
72
+ t . ifError ( err )
73
+ data . body . resume ( ) . on ( 'end' , ( ) => {
74
+ // t.fail() FIX: Should fail.
75
+ t . ok ( true , 'pass' )
71
76
} )
72
77
} )
78
+ await t . completed
73
79
} )
74
80
75
- test ( 'https://github.com/mcollina/undici/issues/810 pipelining' , ( t ) => {
76
- t . plan ( 2 )
81
+ test ( 'https://github.com/mcollina/undici/issues/810 pipelining' , async ( t ) => {
82
+ t = tspl ( t , { plan : 2 } )
77
83
78
84
const server = net . createServer ( socket => {
79
85
socket . write ( 'HTTP/1.1 200 OK\r\n' )
80
86
socket . write ( 'Content-Length: 1\r\n\r\n' )
81
87
socket . write ( '11111\r\n' )
82
88
} )
83
- t . teardown ( server . close . bind ( server ) )
84
-
85
- server . listen ( 0 , ( ) => {
86
- const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : true } )
87
- t . teardown ( client . destroy . bind ( client ) )
88
-
89
- client . request ( {
90
- path : '/' ,
91
- method : 'GET'
92
- } , ( err , data ) => {
93
- t . error ( err )
94
- data . body . resume ( ) . on ( 'end' , ( ) => {
95
- // t.fail() FIX: Should fail.
96
- t . ok ( true , 'pass' )
97
- } )
89
+ after ( ( ) => server . close ( ) )
90
+
91
+ server . listen ( 0 )
92
+
93
+ await once ( server , 'listening' )
94
+
95
+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : true } )
96
+ after ( ( ) => client . close ( ) )
97
+
98
+ client . request ( {
99
+ path : '/' ,
100
+ method : 'GET'
101
+ } , ( err , data ) => {
102
+ t . ifError ( err )
103
+ data . body . resume ( ) . on ( 'end' , ( ) => {
104
+ // t.fail() FIX: Should fail.
105
+ t . ok ( true , 'pass' )
98
106
} )
99
107
} )
108
+ await t . completed
100
109
} )
101
110
102
- test ( 'https://github.com/mcollina/undici/issues/810 pipelining 2' , ( t ) => {
103
- t . plan ( 4 )
111
+ test ( 'https://github.com/mcollina/undici/issues/810 pipelining 2' , async ( t ) => {
112
+ t = tspl ( t , { plan : 4 } )
104
113
105
114
const server = net . createServer ( socket => {
106
115
socket . write ( 'HTTP/1.1 200 OK\r\n' )
107
116
socket . write ( 'Content-Length: 1\r\n\r\n' )
108
117
socket . write ( '11111\r\n' )
109
118
} )
110
- t . teardown ( server . close . bind ( server ) )
111
-
112
- server . listen ( 0 , ( ) => {
113
- const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : true } )
114
- t . teardown ( client . destroy . bind ( client ) )
115
-
116
- client . request ( {
117
- path : '/' ,
118
- method : 'GET'
119
- } , ( err , data ) => {
120
- t . error ( err )
121
- data . body . resume ( ) . on ( 'end' , ( ) => {
122
- // t.fail() FIX: Should fail.
123
- t . ok ( true , 'pass' )
124
- } )
125
- } )
119
+ after ( ( ) => server . close ( ) )
126
120
127
- client . request ( {
128
- path : '/' ,
129
- method : 'GET'
130
- } , ( err , data ) => {
131
- t . equal ( err . code , 'HPE_INVALID_CONSTANT' )
132
- t . ok ( err instanceof errors . HTTPParserError )
121
+ server . listen ( 0 )
122
+
123
+ await once ( server , 'listening' )
124
+
125
+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` , { pipelining : true } )
126
+ after ( ( ) => client . close ( ) )
127
+
128
+ client . request ( {
129
+ path : '/' ,
130
+ method : 'GET'
131
+ } , ( err , data ) => {
132
+ t . ifError ( err )
133
+ data . body . resume ( ) . on ( 'end' , ( ) => {
134
+ // t.fail() FIX: Should fail.
135
+ t . ok ( true , 'pass' )
133
136
} )
134
137
} )
138
+
139
+ client . request ( {
140
+ path : '/' ,
141
+ method : 'GET'
142
+ } , ( err , data ) => {
143
+ t . strictEqual ( err . code , 'HPE_INVALID_CONSTANT' )
144
+ t . ok ( err instanceof errors . HTTPParserError )
145
+ } )
146
+ await t . completed
135
147
} )
0 commit comments