Skip to content

Commit

Permalink
test: refactor, add assertion to http-request-end
Browse files Browse the repository at this point in the history
PR-URL: #53411
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
jakecastelli authored and aduh95 committed Jul 16, 2024
1 parent de99d69 commit 6aa4f0f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions test/parallel/test-http-request-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const http = require('http');

const expected = 'Post Body For Test';
const expectedStatusCode = 200;

const server = http.Server(function(req, res) {
let result = '';
Expand All @@ -34,12 +35,12 @@ const server = http.Server(function(req, res) {
result += chunk;
});

req.on('end', function() {
req.on('end', common.mustCall(() => {
assert.strictEqual(result, expected);
res.writeHead(200);
res.writeHead(expectedStatusCode);
res.end('hello world\n');
server.close();
});
}));

});

Expand All @@ -49,12 +50,9 @@ server.listen(0, function() {
path: '/',
method: 'POST'
}, function(res) {
console.log(res.statusCode);
assert.strictEqual(res.statusCode, expectedStatusCode);
res.resume();
}).on('error', function(e) {
console.log(e.message);
process.exit(1);
});
}).on('error', common.mustNotCall());

const result = req.end(expected);

Expand Down

0 comments on commit 6aa4f0f

Please sign in to comment.