From dbf19a57345a451802aab9248235ba1b4100a4f5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Jul 2014 13:04:30 +0800 Subject: [PATCH] Add spec for #511. --- spec/fixtures/module/create_socket.js | 4 ++++ spec/node-spec.coffee | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/module/create_socket.js diff --git a/spec/fixtures/module/create_socket.js b/spec/fixtures/module/create_socket.js new file mode 100644 index 000000000..2a8b475c5 --- /dev/null +++ b/spec/fixtures/module/create_socket.js @@ -0,0 +1,4 @@ +var net = require('net'); +var server = net.createServer(function() {}); +server.listen(process.argv[2]); +process.exit(0); diff --git a/spec/node-spec.coffee b/spec/node-spec.coffee index 7eb84593f..a2cc8abe3 100644 --- a/spec/node-spec.coffee +++ b/spec/node-spec.coffee @@ -2,11 +2,12 @@ assert = require 'assert' child_process = require 'child_process' fs = require 'fs' path = require 'path' +os = require 'os' describe 'node feature', -> - describe 'child_process', -> - fixtures = path.join __dirname, 'fixtures' + fixtures = path.join __dirname, 'fixtures' + describe 'child_process', -> describe 'child_process.fork', -> it 'works in current process', (done) -> child = child_process.fork path.join(fixtures, 'module', 'ping.js') @@ -73,3 +74,18 @@ describe 'node feature', -> setImmediate -> setImmediate -> setImmediate done + + describe 'net.connect', -> + it 'emit error when connect to a socket path without listeners', (done) -> + socketPath = + if process.platform is 'win32' + '\\\\.\\pipe\\atom-shell-test-sock' + else + path.join os.tmpdir(), 'atom-shell-test.sock' + script = path.join(fixtures, 'module', 'create_socket.js') + child = child_process.fork script, [socketPath] + child.on 'exit', -> + client = require('net').connect socketPath + client.on 'error', (error) -> + assert.equal error.code, 'ECONNREFUSED' + done()