mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 15:02:25 +00:00

Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
38 lines
736 B
JavaScript
38 lines
736 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
|
|
var expected = 'Post Body For Test';
|
|
|
|
var server = http.Server(function(req, res) {
|
|
var result = '';
|
|
|
|
req.setEncoding('utf8');
|
|
req.on('data', function(chunk) {
|
|
result += chunk;
|
|
});
|
|
|
|
req.on('end', function() {
|
|
assert.strictEqual(expected, result);
|
|
server.close();
|
|
res.writeHead(200);
|
|
res.end('hello world\n');
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(0, function() {
|
|
http.request({
|
|
port: this.address().port,
|
|
path: '/',
|
|
method: 'POST'
|
|
}, function(res) {
|
|
console.log(res.statusCode);
|
|
res.resume();
|
|
}).on('error', function(e) {
|
|
console.log(e.message);
|
|
process.exit(1);
|
|
}).end(expected);
|
|
});
|