mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
45 lines
1.4 KiB
CoffeeScript
45 lines
1.4 KiB
CoffeeScript
Task = require '../src/task'
|
|
|
|
describe "Task", ->
|
|
describe "@once(taskPath, args..., callback)", ->
|
|
it "terminates the process after it completes", ->
|
|
handlerResult = null
|
|
task = Task.once require.resolve('./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
|
|
|
|
it "calls listeners registered with ::on when events are emitted in the task", ->
|
|
task = new Task(require.resolve('./fixtures/task-spec-handler'))
|
|
|
|
eventSpy = jasmine.createSpy('eventSpy')
|
|
task.on("some-event", eventSpy)
|
|
|
|
waitsFor (done) -> task.start(done)
|
|
|
|
runs ->
|
|
expect(eventSpy).toHaveBeenCalledWith(1, 2, 3)
|
|
|
|
it "unregisters listeners when the Disposable returned by ::on is disposed", ->
|
|
task = new Task(require.resolve('./fixtures/task-spec-handler'))
|
|
|
|
eventSpy = jasmine.createSpy('eventSpy')
|
|
disposable = task.on("some-event", eventSpy)
|
|
disposable.dispose()
|
|
|
|
waitsFor (done) -> task.start(done)
|
|
|
|
runs ->
|
|
expect(eventSpy).not.toHaveBeenCalled()
|