@@ -8,10 +8,10 @@ import formidable from '../../src/index.js';
8
8
let ok = 0 ;
9
9
let errors = 0 ;
10
10
11
- const PORT = 0 ;
11
+ const PORT = 89 ;
12
12
13
13
test ( 'keep alive error' , ( done ) => {
14
- const server = createServer ( ( req , res ) => {
14
+ const server = createServer ( async ( req , res ) => {
15
15
const form = formidable ( ) ;
16
16
form . on ( 'error' , ( ) => {
17
17
errors += 1 ;
@@ -23,13 +23,35 @@ test('keep alive error', (done) => {
23
23
res . writeHead ( 200 ) ;
24
24
res . end ( ) ;
25
25
} ) ;
26
- form . parse ( req ) ;
26
+ try {
27
+ await form . parse ( req ) ;
28
+ // for client two
29
+ strictEqual ( ok , 1 , `should "ok" count === 1, has: ${ ok } ` ) ;
30
+
31
+ server . close ( ) ;
32
+ done ( ) ;
33
+ } catch ( formidableError ) {
34
+ strictEqual ( errors , 1 , `should "errors" === 1, has: ${ errors } ` ) ;
35
+
36
+ const clientTwo = createConnection ( PORT ) ;
37
+
38
+ // correct post upload (with hyphens)
39
+ clientTwo . write (
40
+ 'POST /upload-test HTTP/1.1\r\n' +
41
+ 'Host: localhost\r\n' +
42
+ 'Connection: keep-alive\r\n' +
43
+ 'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
44
+ 'Content-Length: 13\r\n\r\n' +
45
+ '------aaa--\r\n' ,
46
+ ) ;
47
+ clientTwo . end ( ) ;
48
+
49
+ }
27
50
} ) ;
28
51
29
52
server . listen ( PORT , ( ) => {
30
- const chosenPort = server . address ( ) . port ;
31
53
32
- const client = createConnection ( chosenPort ) ;
54
+ const client = createConnection ( PORT ) ;
33
55
34
56
// first send malformed (boundary / hyphens) post upload
35
57
client . write (
@@ -47,29 +69,6 @@ test('keep alive error', (done) => {
47
69
client . write ( buf ) ;
48
70
client . end ( ) ;
49
71
50
- setTimeout ( ( ) => {
51
- strictEqual ( errors , 1 , `should "errors" === 1, has: ${ errors } ` ) ;
52
-
53
- const clientTwo = createConnection ( chosenPort ) ;
54
-
55
- // correct post upload (with hyphens)
56
- clientTwo . write (
57
- 'POST /upload-test HTTP/1.1\r\n' +
58
- 'Host: localhost\r\n' +
59
- 'Connection: keep-alive\r\n' +
60
- 'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
61
- 'Content-Length: 13\r\n\r\n' +
62
- '------aaa--\r\n' ,
63
- ) ;
64
- clientTwo . end ( ) ;
65
-
66
- setTimeout ( ( ) => {
67
- strictEqual ( ok , 1 , `should "ok" count === 1, has: ${ ok } ` ) ;
68
-
69
- server . close ( ) ;
70
- done ( ) ;
71
- } , 300 ) ;
72
- } , 200 ) ;
73
72
} , 150 ) ;
74
73
} ) ;
75
74
} ) ;
0 commit comments