Skip to content

Commit

Permalink
tests: make some tests cleaner, use promise
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosSacASac committed Jun 28, 2023
1 parent f6c9392 commit f3851e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 3 additions & 2 deletions test/standalone/connection-aborted.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ test('connection aborted', (done) => {
'from .parse() callback: Error event should follow aborted',
);

server.close();
done();
server.close(() => {
done();
});
});
});

Expand Down
12 changes: 8 additions & 4 deletions test/standalone/content-transfer-encoding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ const UPLOAD_DIR = join(process.cwd(), 'test', 'tmp');
// OS choosing port
const PORT = 13530;
test('content transfer encoding', (done) => {
const server = createServer((req, res) => {
const form = formidable();
form.uploadDir = UPLOAD_DIR;
const server = createServer(async (req, res) => {
const form = formidable({
uploadDir: UPLOAD_DIR
});
form.on('end', () => {
throw new Error('Unexpected "end" event');
});
form.on('error', (e) => {
res.writeHead(500);
res.end(e.message);
});
form.parse(req);
try {
await form.parse(req);
} catch (formidableError) {
}
});

server.listen(PORT, () => {
Expand Down
11 changes: 6 additions & 5 deletions test/standalone/issue-46.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const body = "LS1hN2E2NWI5OS04YTYxLTRlMmMtYjE0OS1mNzNhM2IzNWY5MjMNCmNvbnRlbnQtZG
const buffer = Buffer.from(body, 'base64url');

test("issue 46", (done) => {
const server = createServer((req, res) => {
const server = createServer(async (req, res) => {
// Parse form and write results to response.
const form = formidable();
form.parse(req, (err, fields, files) => {
ok(fields.foo, 'should have fields.foo === barry');
strictEqual(fields.foo[0], 'barry');
server.close();
const [fields] = await form.parse(req);
ok(fields.foo, 'should have fields.foo === barry');
strictEqual(fields.foo[0], 'barry');
server.close(() => {
done();
});
});
Expand All @@ -35,5 +35,6 @@ test("issue 46", (done) => {

req.write(buffer);
req.end();

});
});
5 changes: 3 additions & 2 deletions test/standalone/keep-alive-error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ test('keep alive error', (done) => {
// for client two
strictEqual(ok, 1, `should "ok" count === 1, has: ${ok}`);

server.close();
done();
server.close(() => {
done();
});
} catch (formidableError) {
strictEqual(errors, 1, `should "errors" === 1, has: ${errors}`);

Expand Down

0 comments on commit f3851e1

Please sign in to comment.