Skip to content

Commit

Permalink
tests: add bombardier e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosSacASac committed Nov 30, 2022
1 parent d6f7b77 commit 7d183d2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions benchmark/e2e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node ./benchmark/server.js
bombardier --body-file="./README.md" --method=POST --duration=10s --connections=100 http://localhost:3000/api/upload




40 changes: 40 additions & 0 deletions benchmark/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// inital copy of with-http.js
// made a copy so that examples can be changed without impacting tests
import http from 'node:http';
import slugify from '@sindresorhus/slugify';
import formidable, {errors as formidableErrors} from '../src/index.js';

const server = http.createServer((req, res) => {
// handle common internet errors
// to avoid server crash
req.on('error', console.error);
res.on('error', console.error);


if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') {
const form = formidable({
uploadDir: `benchmark/testuploads`,
keepExtensions: true,
});

form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
res.end(String(err));
return;
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ fields, files }, null, 2));
});

return;
}

// else not used in tests

});

server.listen(3000, () => {
console.log('Server listening on http://localhost:3000 ...');
});
1 change: 1 addition & 0 deletions benchmark/testuploads/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File to force directory existence in git

0 comments on commit 7d183d2

Please sign in to comment.