diff --git a/test/common/index.js b/test/common/index.js index e77e7b95059947..9f770005db7a53 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -223,6 +223,15 @@ function createZeroFilledFile(filename) { fs.closeSync(fd); } +function receive(req, cb) { + let buf = ''; + req.on('data', (data) => { + buf += data; + }); + req.on('end', () => { + cb(buf); + }); +} const pwdCommand = isWindows ? ['cmd.exe', ['/d', '/c', 'cd']] : @@ -688,6 +697,7 @@ const common = { platformTimeout, printSkipMessage, pwdCommand, + receive, rootDir, runWithInvalidFD, skip, diff --git a/test/parallel/test-http-response-no-headers.js b/test/parallel/test-http-response-no-headers.js index 22705936e08254..f69b2f63e5de81 100644 --- a/test/parallel/test-http-response-no-headers.js +++ b/test/parallel/test-http-response-no-headers.js @@ -45,18 +45,13 @@ function test(httpVersion, callback) { }; const req = http.get(options, common.mustCall(function(res) { - let body = ''; - - res.on('data', function(data) { - body += data; - }); - res.on('aborted', common.mustNotCall()); - res.on('end', common.mustCall(function() { - assert.strictEqual(body, expected[httpVersion]); + + common.receive(res, function(data) { + assert.strictEqual(data, expected[httpVersion]); server.close(); if (callback) process.nextTick(callback); - })); + }); })); req.on('error', function(err) {