node/test/parallel/test-net-server-listen-path.js
Joyee Cheung 474e9d64b5 test: add more test cases of server.listen option
* Test listening with different handle and fd
* Test listening without callback

PR-URL: https://github.com/nodejs/node/pull/11778/
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-03-16 13:17:32 +08:00

50 lines
907 B
JavaScript

'use strict';
const common = require('../common');
const net = require('net');
common.refreshTmpDir();
function closeServer() {
return common.mustCall(function() {
this.close();
});
}
let counter = 0;
// Avoid conflict with listen-handle
function randomPipePath() {
return common.PIPE + '-listen-path-' + (counter++);
}
// Test listen(path)
{
const handlePath = randomPipePath();
net.createServer()
.listen(handlePath)
.on('listening', closeServer());
}
// Test listen({path})
{
const handlePath = randomPipePath();
net.createServer()
.listen({path: handlePath})
.on('listening', closeServer());
}
// Test listen(path, cb)
{
const handlePath = randomPipePath();
net.createServer()
.listen(handlePath, closeServer());
}
// Test listen(path, cb)
{
const handlePath = randomPipePath();
net.createServer()
.listen({path: handlePath}, closeServer());
}