mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: use mustCall() for simple flow tracking
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>
This commit is contained in:
@@ -16,14 +16,11 @@ var options = {
|
||||
cert: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-cert.pem'))
|
||||
};
|
||||
|
||||
var reqCount = 0;
|
||||
|
||||
var server = https.createServer(options, function(req, res) {
|
||||
++reqCount;
|
||||
var server = https.createServer(options, common.mustCall(function(req, res) {
|
||||
res.writeHead(200);
|
||||
res.end();
|
||||
req.resume();
|
||||
}).listen(0, function() {
|
||||
})).listen(0, function() {
|
||||
authorized();
|
||||
});
|
||||
|
||||
@@ -32,9 +29,7 @@ function authorized() {
|
||||
port: server.address().port,
|
||||
rejectUnauthorized: true,
|
||||
ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))]
|
||||
}, function(res) {
|
||||
assert(false);
|
||||
});
|
||||
}, common.fail);
|
||||
req.on('error', function(err) {
|
||||
override();
|
||||
});
|
||||
@@ -60,7 +55,3 @@ function override() {
|
||||
});
|
||||
req.end();
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.equal(reqCount, 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user