Add spec for Task.once()

This commit is contained in:
Corey Johnson & Kevin Sawicki 2013-06-14 16:09:38 -07:00 committed by probablycorey
parent 2a7d35cc39
commit 8c4bddac9f
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module.exports = ->
console.log "The pid is #{process.pid}"
'hello'

View File

@ -20,3 +20,23 @@ describe "Task", ->
expect(console.log).not.toHaveBeenCalled()
expect(console.error).not.toHaveBeenCalled()
expect(console.warn).not.toHaveBeenCalled()
describe "@once(taskPath, args..., callback)", ->
it "terminates the process after it completes", ->
handlerResult = null
task = Task.once 'fixtures/task-spec-handler', (result) ->
handlerResult = result
processClosed = false
processErrored = false
childProcess = task.childProcess
spyOn(childProcess, 'kill').andCallThrough()
task.childProcess.on 'error', -> processErrored = true
waitsFor ->
handlerResult?
runs ->
expect(handlerResult).toBe 'hello'
expect(childProcess.kill).toHaveBeenCalled()
expect(processErrored).toBe false