Closes #311. Show more informative error when beautifier not found
This commit is contained in:
parent
66867a78b2
commit
c9159f2a92
|
@ -1,29 +1,67 @@
|
||||||
Beautify = require '../src/beautify'
|
Beautifiers = require "../src/beautifiers"
|
||||||
|
beautifiers = new Beautifiers()
|
||||||
|
Beautifier = require "../src/beautifiers/beautifier"
|
||||||
|
|
||||||
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
||||||
#
|
#
|
||||||
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
|
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
|
||||||
# or `fdescribe`). Remove the `f` to unfocus the block.
|
# or `fdescribe`). Remove the `f` to unfocus the block.
|
||||||
|
|
||||||
describe "AtomBeautify", ->
|
describe "Atom-Beautify", ->
|
||||||
activationPromise = null
|
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
atom.workspaceView = new WorkspaceView
|
|
||||||
activationPromise = atom.packages.activatePackage('atomBeautify')
|
|
||||||
|
|
||||||
# describe "when the beautify event is triggered", ->
|
# Activate package
|
||||||
# it "attaches and then detaches the view", ->
|
waitsForPromise ->
|
||||||
# expect(atom.workspaceView.find('.atom-beautify')).not.toExist()
|
activationPromise = atom.packages.activatePackage('atom-beautify')
|
||||||
#
|
# Force activate package
|
||||||
# # This is an activation event, triggering it will cause the package to be
|
pack = atom.packages.getLoadedPackage("atom-beautify")
|
||||||
# # activated.
|
pack.activateNow()
|
||||||
# atom.workspaceView.trigger 'beautify'
|
# Change logger level
|
||||||
#
|
# atom.config.set('atom-beautify._loggerLevel', 'verbose')
|
||||||
# waitsForPromise ->
|
# Return promise
|
||||||
# activationPromise
|
return activationPromise
|
||||||
#
|
|
||||||
# runs ->
|
describe "Beautifiers", ->
|
||||||
# expect(atom.workspaceView.find('.atom-beautify')).toExist()
|
|
||||||
# atom.workspaceView.trigger 'beautify'
|
describe "Beautifier::run", ->
|
||||||
# expect(atom.workspaceView.find('.atom-beautify')).not.toExist()
|
|
||||||
|
beautifier = null
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
beautifier = new Beautifier()
|
||||||
|
|
||||||
|
it "should error when beautifier's program not found", ->
|
||||||
|
expect(beautifier).not.toBe(null)
|
||||||
|
expect(beautifier instanceof Beautifier).toBe(true)
|
||||||
|
|
||||||
|
# waitsForRuns = (fn, message, timeout) ->
|
||||||
|
# isCompleted = false
|
||||||
|
# completed = ->
|
||||||
|
# console.log('completed')
|
||||||
|
# isCompleted = true
|
||||||
|
# runs ->
|
||||||
|
# console.log('runs')
|
||||||
|
# fn(completed)
|
||||||
|
# waitsFor(->
|
||||||
|
# console.log('waitsFor', isCompleted)
|
||||||
|
# isCompleted
|
||||||
|
# , message, timeout)
|
||||||
|
#
|
||||||
|
# waitsForRuns((cb) ->
|
||||||
|
# console.log('waitsForRuns', cb)
|
||||||
|
# setTimeout(cb, 2000)
|
||||||
|
# , "Waiting for beautification to complete", 5000)
|
||||||
|
|
||||||
|
waitsForPromise shouldReject: true, ->
|
||||||
|
p = beautifier.run("program", [])
|
||||||
|
expect(p).not.toBe(null)
|
||||||
|
expect(p instanceof beautifier.Promise).toBe(true)
|
||||||
|
cb = (v) ->
|
||||||
|
# console.log(v)
|
||||||
|
expect(v).not.toBe(null)
|
||||||
|
expect(v instanceof Error).toBe(true)
|
||||||
|
expect(v.code).toBe("CommandNotFound")
|
||||||
|
return v
|
||||||
|
p.then(cb, cb)
|
||||||
|
return p
|
|
@ -135,7 +135,7 @@ module.exports = class Beautifier
|
||||||
###
|
###
|
||||||
Run command-line interface command
|
Run command-line interface command
|
||||||
###
|
###
|
||||||
run: (executable, args, {ignoreReturnCode} = {}) ->
|
run: (executable, args, {ignoreReturnCode, help} = {}) ->
|
||||||
# Resolve executable
|
# Resolve executable
|
||||||
Promise.resolve(executable)
|
Promise.resolve(executable)
|
||||||
.then((exe) =>
|
.then((exe) =>
|
||||||
|
@ -173,7 +173,30 @@ module.exports = class Beautifier
|
||||||
)
|
)
|
||||||
cmd.on('error', (err) =>
|
cmd.on('error', (err) =>
|
||||||
@debug('error', err)
|
@debug('error', err)
|
||||||
reject(err)
|
# Check if error is ENOENT (command could not be found)
|
||||||
|
if err.code is 'ENOENT' or err.errno is 'ENOENT'
|
||||||
|
# Create new improved error
|
||||||
|
# notify user that it may not be installed or in path
|
||||||
|
message = "Could not find '#{exe}'. The program may not be installed."
|
||||||
|
er = new Error(message) # +(if help then "\n\n#{help}" else "")
|
||||||
|
if help?
|
||||||
|
if typeof help is "object"
|
||||||
|
helpStr = "See #{help.link} for program installation instructions.\n"
|
||||||
|
helpStr += "You can configure Atom Beautify with the absolute path \
|
||||||
|
to '#{help.program or exe}' by setting '#{help.pathOption}' in \
|
||||||
|
the Atom Beautify package settings.\n" if help.pathOption
|
||||||
|
helpStr += help.additional if help.additional
|
||||||
|
er.description = helpStr
|
||||||
|
else #if typeof help is "string"
|
||||||
|
er.description = help
|
||||||
|
er.code = 'CommandNotFound'
|
||||||
|
er.errno = er.code
|
||||||
|
er.syscall = 'beautifier::run'
|
||||||
|
er.file = exe
|
||||||
|
reject(er)
|
||||||
|
else
|
||||||
|
# continue as normal error
|
||||||
|
reject(err)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -76,7 +76,7 @@ beautify = ({onSave}) ->
|
||||||
|
|
||||||
# console.log(e)
|
# console.log(e)
|
||||||
stack = error.stack
|
stack = error.stack
|
||||||
detail = error.message
|
detail = error.description or error.message
|
||||||
atom.notifications?.addError(error.message, {
|
atom.notifications?.addError(error.message, {
|
||||||
stack, detail, dismissable : true})
|
stack, detail, dismissable : true})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue