2013-12-06 14:23:02 +00:00
|
|
|
assert = require 'assert'
|
|
|
|
child_process = require 'child_process'
|
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
2014-07-25 05:04:30 +00:00
|
|
|
os = require 'os'
|
2014-08-07 02:29:26 +00:00
|
|
|
remote = require 'remote'
|
2013-12-06 14:23:02 +00:00
|
|
|
|
2013-12-15 16:31:40 +00:00
|
|
|
describe 'node feature', ->
|
2014-07-25 05:04:30 +00:00
|
|
|
fixtures = path.join __dirname, 'fixtures'
|
2013-12-06 14:23:02 +00:00
|
|
|
|
2014-07-25 05:04:30 +00:00
|
|
|
describe 'child_process', ->
|
2013-12-06 14:23:02 +00:00
|
|
|
describe 'child_process.fork', ->
|
|
|
|
it 'works in current process', (done) ->
|
|
|
|
child = child_process.fork path.join(fixtures, 'module', 'ping.js')
|
|
|
|
child.on 'message', (msg) ->
|
|
|
|
assert.equal msg, 'message'
|
|
|
|
done()
|
|
|
|
child.send 'message'
|
|
|
|
|
|
|
|
it 'works in forked process', (done) ->
|
|
|
|
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js')
|
|
|
|
child.on 'message', (msg) ->
|
|
|
|
assert.equal msg, 'message'
|
|
|
|
done()
|
|
|
|
child.send 'message'
|
|
|
|
|
|
|
|
it 'works in forked process when options.env is specifed', (done) ->
|
|
|
|
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js'),
|
|
|
|
[],
|
|
|
|
path: process.env['PATH']
|
|
|
|
child.on 'message', (msg) ->
|
|
|
|
assert.equal msg, 'message'
|
|
|
|
done()
|
|
|
|
child.send 'message'
|
|
|
|
|
2014-07-31 08:47:11 +00:00
|
|
|
it 'works in browser process', (done) ->
|
2014-08-07 02:29:26 +00:00
|
|
|
fork = remote.require('child_process').fork
|
2014-07-31 08:47:11 +00:00
|
|
|
child = fork path.join(fixtures, 'module', 'ping.js')
|
|
|
|
child.on 'message', (msg) ->
|
|
|
|
assert.equal msg, 'message'
|
|
|
|
done()
|
|
|
|
child.send 'message'
|
|
|
|
|
2013-12-06 14:23:02 +00:00
|
|
|
describe 'contexts', ->
|
|
|
|
describe 'setTimeout in fs callback', ->
|
|
|
|
it 'does not crash', (done) ->
|
|
|
|
fs.readFile __filename, ->
|
|
|
|
setTimeout done, 0
|
|
|
|
|
2014-01-09 12:34:17 +00:00
|
|
|
describe 'setTimeout in pure uv callback', ->
|
|
|
|
it 'does not crash', (done) ->
|
|
|
|
process.scheduleCallback ->
|
|
|
|
setTimeout done, 0
|
|
|
|
|
2013-12-06 14:23:02 +00:00
|
|
|
describe 'throw error in node context', ->
|
|
|
|
it 'gets caught', (done) ->
|
|
|
|
error = new Error('boo!')
|
|
|
|
lsts = process.listeners 'uncaughtException'
|
|
|
|
process.removeAllListeners 'uncaughtException'
|
|
|
|
process.on 'uncaughtException', (err) ->
|
|
|
|
process.removeAllListeners 'uncaughtException'
|
|
|
|
for lst in lsts
|
|
|
|
process.on 'uncaughtException', lst
|
|
|
|
done()
|
|
|
|
fs.readFile __filename, ->
|
|
|
|
throw error
|
|
|
|
|
2014-08-07 02:29:26 +00:00
|
|
|
describe 'setTimeout called under Chromium event loop in browser process', ->
|
|
|
|
it 'can be scheduled in time', (done) ->
|
|
|
|
remote.getGlobal('setTimeout')(done, 0)
|
|
|
|
|
2014-08-07 06:23:28 +00:00
|
|
|
describe 'setInterval called under Chromium event loop in browser process', ->
|
|
|
|
it 'can be scheduled in time', (done) ->
|
|
|
|
clear = ->
|
|
|
|
remote.getGlobal('clearInterval')(interval)
|
|
|
|
done()
|
|
|
|
interval = remote.getGlobal('setInterval')(clear, 0)
|
|
|
|
|
2013-12-06 14:23:02 +00:00
|
|
|
describe 'message loop', ->
|
|
|
|
describe 'process.nextTick', ->
|
|
|
|
it 'emits the callback', (done) ->
|
|
|
|
process.nextTick done
|
|
|
|
|
|
|
|
it 'works in nested calls', (done) ->
|
|
|
|
process.nextTick ->
|
|
|
|
process.nextTick ->
|
|
|
|
process.nextTick done
|
|
|
|
|
|
|
|
describe 'setImmediate', ->
|
|
|
|
it 'emits the callback', (done) ->
|
|
|
|
setImmediate done
|
|
|
|
|
|
|
|
it 'works in nested calls', (done) ->
|
|
|
|
setImmediate ->
|
|
|
|
setImmediate ->
|
|
|
|
setImmediate done
|
2014-07-25 05:04:30 +00:00
|
|
|
|
|
|
|
describe 'net.connect', ->
|
|
|
|
it 'emit error when connect to a socket path without listeners', (done) ->
|
2014-07-25 07:02:17 +00:00
|
|
|
return done() if process.platform is 'win32'
|
|
|
|
|
|
|
|
socketPath = path.join os.tmpdir(), 'atom-shell-test.sock'
|
2014-07-25 05:04:30 +00:00
|
|
|
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()
|