mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02: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:
parent
59741a9bee
commit
04b4d15b39
213 changed files with 1101 additions and 2882 deletions
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
require('../common');
|
||||
var assert = require('assert');
|
||||
const common = require('../common');
|
||||
var http = require('http');
|
||||
|
||||
var body = 'hello world\n';
|
||||
|
@ -13,27 +12,20 @@ function test(headers) {
|
|||
server.close();
|
||||
});
|
||||
|
||||
var gotEnd = false;
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
var request = http.request({
|
||||
port: this.address().port,
|
||||
method: 'HEAD',
|
||||
path: '/'
|
||||
}, function(response) {
|
||||
}, common.mustCall(function(response) {
|
||||
console.error('response start');
|
||||
response.on('end', function() {
|
||||
response.on('end', common.mustCall(function() {
|
||||
console.error('response end');
|
||||
gotEnd = true;
|
||||
});
|
||||
}));
|
||||
response.resume();
|
||||
});
|
||||
}));
|
||||
request.end();
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.ok(gotEnd);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
test({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue