-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactoring test with common.mustCall #12702
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,16 +36,6 @@ const options = { | |
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') | ||
}; | ||
|
||
const tests = 2; | ||
let successful = 0; | ||
|
||
const testSucceeded = function() { | ||
successful = successful + 1; | ||
if (successful === tests) { | ||
server.close(); | ||
} | ||
}; | ||
|
||
const body = 'hello world\n'; | ||
|
||
const serverCallback = common.mustCall(function(req, res) { | ||
|
@@ -55,7 +45,7 @@ const serverCallback = common.mustCall(function(req, res) { | |
|
||
const server = https.createServer(options, serverCallback); | ||
|
||
server.listen(0, function() { | ||
server.listen(0, function(){ | ||
// Do a request ignoring the unauthorized server certs | ||
const noCertCheckOptions = { | ||
hostname: '127.0.0.1', | ||
|
@@ -66,16 +56,15 @@ server.listen(0, function() { | |
}; | ||
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions); | ||
|
||
const req = https.request(noCertCheckOptions, function(res) { | ||
const req = https.request(noCertCheckOptions, function(res){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. |
||
let responseBody = ''; | ||
res.on('data', function(d) { | ||
responseBody = responseBody + d; | ||
}); | ||
|
||
res.on('end', function() { | ||
res.on('end', common.mustCall(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enclosing |
||
assert.strictEqual(responseBody, body); | ||
testSucceeded(); | ||
}); | ||
})); | ||
}); | ||
req.end(); | ||
|
||
|
@@ -108,6 +97,6 @@ server.listen(0, function() { | |
}); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.strictEqual(successful, tests); | ||
}); | ||
function testSucceeded (){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
server.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is only called from one place, you can just inline the |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the space back. Does this pass
make jslint
?