Skip to content

Commit 7d183d2

Browse files
committed
tests: add bombardier e2e tests
1 parent d6f7b77 commit 7d183d2

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

benchmark/e2e.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node ./benchmark/server.js
2+
bombardier --body-file="./README.md" --method=POST --duration=10s --connections=100 http://localhost:3000/api/upload
3+
4+
5+
6+

benchmark/server.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// inital copy of with-http.js
2+
// made a copy so that examples can be changed without impacting tests
3+
import http from 'node:http';
4+
import slugify from '@sindresorhus/slugify';
5+
import formidable, {errors as formidableErrors} from '../src/index.js';
6+
7+
const server = http.createServer((req, res) => {
8+
// handle common internet errors
9+
// to avoid server crash
10+
req.on('error', console.error);
11+
res.on('error', console.error);
12+
13+
14+
if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') {
15+
const form = formidable({
16+
uploadDir: `benchmark/testuploads`,
17+
keepExtensions: true,
18+
});
19+
20+
form.parse(req, (err, fields, files) => {
21+
if (err) {
22+
console.error(err);
23+
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
24+
res.end(String(err));
25+
return;
26+
}
27+
res.writeHead(200, { 'Content-Type': 'application/json' });
28+
res.end(JSON.stringify({ fields, files }, null, 2));
29+
});
30+
31+
return;
32+
}
33+
34+
// else not used in tests
35+
36+
});
37+
38+
server.listen(3000, () => {
39+
console.log('Server listening on http://localhost:3000 ...');
40+
});

benchmark/testuploads/note.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File to force directory existence in git

0 commit comments

Comments
 (0)