mirror of
https://github.com/HackPlan/atom-shell.git
synced 2026-04-29 12:15:38 +08:00
Flatten spec files, make them seem cleaner.
This commit is contained in:
70
spec/node-spec.coffee
Normal file
70
spec/node-spec.coffee
Normal file
@@ -0,0 +1,70 @@
|
||||
assert = require 'assert'
|
||||
child_process = require 'child_process'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
||||
describe 'node features', ->
|
||||
describe 'child_process', ->
|
||||
fixtures = path.join __dirname, 'fixtures'
|
||||
|
||||
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'
|
||||
|
||||
describe 'contexts', ->
|
||||
describe 'setTimeout in fs callback', ->
|
||||
it 'does not crash', (done) ->
|
||||
fs.readFile __filename, ->
|
||||
setTimeout done, 0
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user