Skip to content

Commit

Permalink
test: revise test-http-client-default-headers-exist
Browse files Browse the repository at this point in the history
* Remove assert.strictEqual where assert.ok suffices
* Replace countdown with Promise.all()

PR-URL: #32493
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Trott authored and targos committed Apr 22, 2020
1 parent 3ed9fcd commit 565f0f7
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions test/parallel/test-http-client-default-headers-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

const { once } = require('events');

const expectedHeaders = {
'DELETE': ['host', 'connection'],
Expand All @@ -37,10 +38,6 @@ const expectedHeaders = {

const expectedMethods = Object.keys(expectedHeaders);

const countdown =
new Countdown(expectedMethods.length,
common.mustCall(() => server.close()));

const server = http.createServer(common.mustCall((req, res) => {
res.end();

Expand All @@ -49,9 +46,8 @@ const server = http.createServer(common.mustCall((req, res) => {

const requestHeaders = Object.keys(req.headers);
requestHeaders.forEach((header) => {
assert.strictEqual(
assert.ok(
expectedHeaders[req.method].includes(header.toLowerCase()),
true,
`${header} should not exist for method ${req.method}`
);
});
Expand All @@ -61,15 +57,14 @@ const server = http.createServer(common.mustCall((req, res) => {
expectedHeaders[req.method].length,
`some headers were missing for method: ${req.method}`
);

countdown.dec();
}, expectedMethods.length));

server.listen(0, common.mustCall(() => {
expectedMethods.forEach((method) => {
http.request({
Promise.all(expectedMethods.map(async (method) => {
const request = http.request({
method: method,
port: server.address().port
}).end();
});
return once(request, 'response');
})).then(common.mustCall(() => { server.close(); }));
}));

0 comments on commit 565f0f7

Please sign in to comment.