Skip to content

Commit d90b69d

Browse files
committed
tests: rewrite test for Promise
1 parent 0179abf commit d90b69d

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

test/standalone/keep-alive-error.test.js

+27-28
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import formidable from '../../src/index.js';
88
let ok = 0;
99
let errors = 0;
1010

11-
const PORT = 0;
11+
const PORT = 89;
1212

1313
test('keep alive error', (done) => {
14-
const server = createServer((req, res) => {
14+
const server = createServer(async (req, res) => {
1515
const form = formidable();
1616
form.on('error', () => {
1717
errors += 1;
@@ -23,13 +23,35 @@ test('keep alive error', (done) => {
2323
res.writeHead(200);
2424
res.end();
2525
});
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+
}
2750
});
2851

2952
server.listen(PORT, () => {
30-
const chosenPort = server.address().port;
3153

32-
const client = createConnection(chosenPort);
54+
const client = createConnection(PORT);
3355

3456
// first send malformed (boundary / hyphens) post upload
3557
client.write(
@@ -47,29 +69,6 @@ test('keep alive error', (done) => {
4769
client.write(buf);
4870
client.end();
4971

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);
7372
}, 150);
7473
});
7574
});

0 commit comments

Comments
 (0)