mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
51602f69a5
Converted all references of global atom to NylasEnv Temporary rename atom.io find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.io/temporaryAtomIoReplacement/g' atom.config to NylasEnv.config find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.config/NylasEnv.config/g' atom.packages -> NylasEnv.packages atom.commands -> NylasEnv.commands atom.getLoadSettings find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.commands/NylasEnv.commands/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getLoadSettings/NylasEnv.getLoadSettings/g' More common atom methods find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.styles/NylasEnv.styles/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.emitError/NylasEnv.emitError/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inSpecMode/NylasEnv.inSpecMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inDevMode/NylasEnv.inDevMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getWindowType/NylasEnv.getWindowType/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.displayWindow/NylasEnv.displayWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.quit/NylasEnv.quit/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.close/NylasEnv.close/g' More atom method changes find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.keymaps/NylasEnv.keymaps/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.hide/NylasEnv.hide/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getCurrentWindow/NylasEnv.getCurrentWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.menu/NylasEnv.menu/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getConfigDirPath/NylasEnv.getConfigDirPath/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isMainWindow/NylasEnv.isMainWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.finishUnload/NylasEnv.finishUnload/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isWorkWindow/NylasEnv.isWorkWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.showSaveDialog/NylasEnv.showSaveDialog/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.append/NylasEnv.append/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.confirm/NylasEnv.confirm/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.clipboard/NylasEnv.clipboard/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getVersion/NylasEnv.getVersion/g' More atom renaming Rename atom methods More atom methods Fix grunt config variable Change atom.cmd to N1.cmd Rename atom.coffee and atom.js to nylas-env.coffee nylas-env.js Fix atom global reference in specs manually Fix atom requires Change engine from atom to nylas got rid of global/nylas-env rename to nylas-win-bootup Fix onWindowPropsChanged to onWindowPropsReceived fix nylas-workspace atom-text-editor to nylas-theme-wrap atom-text-editor -> nylas-theme-wrap Replacing atom keyword AtomWindow -> NylasWindow Replace Atom -> N1 Rename atom items nylas.asar -> atom.asar Remove more atom references Remove 6to5 references Remove license exception for atom
220 lines
8.6 KiB
CoffeeScript
220 lines
8.6 KiB
CoffeeScript
Actions = require '../../src/flux/actions'
|
|
TaskQueue = require '../../src/flux/stores/task-queue'
|
|
Task = require '../../src/flux/tasks/task'
|
|
|
|
{APIError,
|
|
OfflineError,
|
|
TimeoutError} = require '../../src/flux/errors'
|
|
|
|
noop = ->
|
|
|
|
describe "Task", ->
|
|
describe "initial state", ->
|
|
it "should set up queue state with additional information about local/remote", ->
|
|
task = new Task()
|
|
expect(task.queueState).toEqual({ isProcessing : false, localError : null, localComplete : false, remoteError : null, remoteAttempts : 0, remoteComplete : false, status: null, debugStatus: Task.DebugStatus.JustConstructed})
|
|
|
|
describe "runLocal", ->
|
|
beforeEach ->
|
|
class APITestTask extends Task
|
|
performLocal: -> Promise.resolve()
|
|
performRemote: -> Promise.resolve(Task.Status.Success)
|
|
@task = new APITestTask()
|
|
|
|
describe "when performLocal is not complete", ->
|
|
it "should run performLocal", ->
|
|
spyOn(@task, 'performLocal').andCallThrough()
|
|
@task.runLocal()
|
|
expect(@task.performLocal).toHaveBeenCalled()
|
|
|
|
describe "when performLocal rejects", ->
|
|
beforeEach ->
|
|
spyOn(@task, 'performLocal').andCallFake =>
|
|
Promise.reject(new Error("Oh no!"))
|
|
|
|
it "should save the error to the queueState", ->
|
|
@task.runLocal().catch(noop)
|
|
advanceClock()
|
|
expect(@task.performLocal).toHaveBeenCalled()
|
|
expect(@task.queueState.localComplete).toBe(false)
|
|
expect(@task.queueState.localError.message).toBe("Oh no!")
|
|
|
|
it "should reject with the error", ->
|
|
rejection = null
|
|
runs ->
|
|
@task.runLocal().catch (err) ->
|
|
rejection = err
|
|
waitsFor ->
|
|
rejection
|
|
runs ->
|
|
expect(rejection.message).toBe("Oh no!")
|
|
|
|
describe "when performLocal resolves", ->
|
|
beforeEach ->
|
|
spyOn(@task, 'performLocal').andCallFake -> Promise.resolve('Hooray')
|
|
|
|
it "should save that performLocal is complete", ->
|
|
@task.runLocal()
|
|
advanceClock()
|
|
expect(@task.queueState.localComplete).toBe(true)
|
|
|
|
it "should save that there was no performLocal error", ->
|
|
@task.runLocal()
|
|
advanceClock()
|
|
expect(@task.queueState.localError).toBe(null)
|
|
|
|
describe "runRemote", ->
|
|
beforeEach ->
|
|
@task.queueState.localComplete = true
|
|
|
|
it "should run performRemote", ->
|
|
spyOn(@task, 'performRemote').andCallThrough()
|
|
@task.runRemote()
|
|
advanceClock()
|
|
expect(@task.performRemote).toHaveBeenCalled()
|
|
|
|
it "it should resolve Continue if it already ran", ->
|
|
@task.queueState.remoteComplete = true
|
|
waitsForPromise =>
|
|
@task.runRemote().then (status) =>
|
|
expect(@task.queueState.status).toBe Task.Status.Continue
|
|
expect(status).toBe Task.Status.Continue
|
|
|
|
it "marks as complete if the task 'continue's", ->
|
|
spyOn(@task, 'performRemote').andCallFake ->
|
|
Promise.resolve(Task.Status.Continue)
|
|
@task.runRemote()
|
|
advanceClock()
|
|
expect(@task.performRemote).toHaveBeenCalled()
|
|
expect(@task.queueState.remoteError).toBe(null)
|
|
expect(@task.queueState.remoteComplete).toBe(true)
|
|
expect(@task.queueState.status).toBe(Task.Status.Continue)
|
|
|
|
it "marks as failed if the task reverts", ->
|
|
spyOn(@task, 'performRemote').andCallFake ->
|
|
Promise.resolve(Task.Status.Failed)
|
|
@task.runRemote()
|
|
advanceClock()
|
|
expect(@task.performRemote).toHaveBeenCalled()
|
|
expect(@task.queueState.remoteError).toBe(null)
|
|
expect(@task.queueState.remoteComplete).toBe(true)
|
|
expect(@task.queueState.status).toBe(Task.Status.Failed)
|
|
|
|
describe "when performRemote resolves", ->
|
|
beforeEach ->
|
|
spyOn(@task, 'performRemote').andCallFake ->
|
|
Promise.resolve(Task.Status.Success)
|
|
|
|
it "should save that performRemote is complete with no errors", ->
|
|
@task.runRemote()
|
|
advanceClock()
|
|
expect(@task.performRemote).toHaveBeenCalled()
|
|
expect(@task.queueState.remoteError).toBe(null)
|
|
expect(@task.queueState.remoteComplete).toBe(true)
|
|
expect(@task.queueState.status).toBe(Task.Status.Success)
|
|
|
|
it "should only allow the performRemote method to return a Task.Status", ->
|
|
result = null
|
|
err = null
|
|
|
|
class OKTask extends Task
|
|
performRemote: -> Promise.resolve(Task.Status.Retry)
|
|
|
|
@ok = new OKTask()
|
|
@ok.queueState.localComplete = true
|
|
@ok.runRemote().then (r) -> result = r
|
|
advanceClock()
|
|
expect(@ok.queueState.status).toBe(Task.Status.Retry)
|
|
expect(result).toBe(Task.Status.Retry)
|
|
|
|
class BadTask extends Task
|
|
performRemote: -> Promise.resolve('lalal')
|
|
@bad = new BadTask()
|
|
@bad.queueState.localComplete = true
|
|
@bad.runRemote().catch (e) -> err = e
|
|
advanceClock()
|
|
expect(err.message).toBe('performRemote returned lalal, which is not a Task.Status')
|
|
|
|
describe "when performRemote rejects multiple times", ->
|
|
beforeEach ->
|
|
spyOn(@task, 'performRemote').andCallFake =>
|
|
Promise.resolve(Task.Status.Failed)
|
|
|
|
it "should increment the number of attempts", ->
|
|
runs ->
|
|
@task.runRemote().catch(noop)
|
|
waitsFor ->
|
|
@task.queueState.remoteAttempts == 1
|
|
runs ->
|
|
@task.runRemote().catch(noop)
|
|
waitsFor ->
|
|
@task.queueState.remoteAttempts == 2
|
|
|
|
describe "when performRemote resolves with Task.Status.Failed", ->
|
|
beforeEach ->
|
|
spyOn(NylasEnv, "emitError")
|
|
@error = new APIError("Oh no!")
|
|
spyOn(@task, 'performRemote').andCallFake =>
|
|
Promise.resolve(Task.Status.Failed)
|
|
|
|
it "Should handle the error as a caught Failure", ->
|
|
waitsForPromise =>
|
|
@task.runRemote().then ->
|
|
throw new Error("Should not resolve")
|
|
.catch (err) =>
|
|
expect(@task.queueState.remoteError instanceof Error).toBe true
|
|
expect(@task.queueState.remoteAttempts).toBe(1)
|
|
expect(@task.queueState.status).toBe(Task.Status.Failed)
|
|
expect(NylasEnv.emitError).not.toHaveBeenCalled()
|
|
|
|
describe "when performRemote resolves with Task.Status.Failed and an error", ->
|
|
beforeEach ->
|
|
spyOn(NylasEnv, "emitError")
|
|
@error = new APIError("Oh no!")
|
|
spyOn(@task, 'performRemote').andCallFake =>
|
|
Promise.resolve([Task.Status.Failed, @error])
|
|
|
|
it "Should handle the error as a caught Failure", ->
|
|
waitsForPromise =>
|
|
@task.runRemote().then ->
|
|
throw new Error("Should not resolve")
|
|
.catch (err) =>
|
|
expect(@task.queueState.remoteError).toBe(@error)
|
|
expect(@task.queueState.remoteAttempts).toBe(1)
|
|
expect(@task.queueState.status).toBe(Task.Status.Failed)
|
|
expect(NylasEnv.emitError).not.toHaveBeenCalled()
|
|
|
|
describe "when performRemote rejects with Task.Status.Failed", ->
|
|
beforeEach ->
|
|
spyOn(NylasEnv, "emitError")
|
|
@error = new APIError("Oh no!")
|
|
spyOn(@task, 'performRemote').andCallFake =>
|
|
Promise.reject([Task.Status.Failed, @error])
|
|
|
|
it "Should handle the rejection as normal", ->
|
|
waitsForPromise =>
|
|
@task.runRemote().then ->
|
|
throw new Error("Should not resolve")
|
|
.catch (err) =>
|
|
expect(@task.queueState.remoteError).toBe(@error)
|
|
expect(@task.queueState.remoteAttempts).toBe(1)
|
|
expect(@task.queueState.status).toBe(Task.Status.Failed)
|
|
expect(NylasEnv.emitError).not.toHaveBeenCalled()
|
|
|
|
describe "when performRemote throws an unknown error", ->
|
|
beforeEach ->
|
|
spyOn(NylasEnv, "emitError")
|
|
@error = new Error("Oh no!")
|
|
spyOn(@task, 'performRemote').andCallFake =>
|
|
throw @error
|
|
|
|
it "Should handle the error as an uncaught error", ->
|
|
waitsForPromise =>
|
|
@task.runRemote().then ->
|
|
throw new Error("Should not resolve")
|
|
.catch (err) =>
|
|
expect(@task.queueState.remoteError).toBe(@error)
|
|
expect(@task.queueState.remoteAttempts).toBe(1)
|
|
expect(@task.queueState.status).toBe(Task.Status.Failed)
|
|
expect(@task.queueState.debugStatus).toBe(Task.DebugStatus.UncaughtError)
|
|
expect(NylasEnv.emitError).toHaveBeenCalledWith(@error)
|