Re-throw package activation exceptions in test mode

This commit is contained in:
Max Brunsfeld 2017-01-12 20:06:10 -08:00 committed by Nathan Sobo
parent e4a218ff45
commit a57b627a58
2 changed files with 10 additions and 1 deletions

View File

@ -546,8 +546,9 @@ describe "PackageManager", ->
waitsFor -> activatedPackage?
runs -> expect(activatedPackage.name).toBe 'package-with-main'
describe "when the package throws an error while loading", ->
describe "when the package's main module throws an error on load", ->
it "adds a notification instead of throwing an exception", ->
spyOn(atom, 'inSpecMode').andReturn(false)
atom.config.set("core.disabledPackages", [])
addErrorHandler = jasmine.createSpy()
atom.notifications.onDidAddNotification(addErrorHandler)
@ -556,6 +557,11 @@ describe "PackageManager", ->
expect(addErrorHandler.argsForCall[0][0].message).toContain("Failed to load the package-that-throws-an-exception package")
expect(addErrorHandler.argsForCall[0][0].options.packageName).toEqual "package-that-throws-an-exception"
it "re-throws the exception in test mode", ->
atom.config.set("core.disabledPackages", [])
addErrorHandler = jasmine.createSpy()
expect(-> atom.packages.activatePackage("package-that-throws-an-exception")).toThrow("This package throws an exception")
describe "when the package is not found", ->
it "rejects the promise", ->
atom.config.set("core.disabledPackages", [])

View File

@ -711,6 +711,9 @@ class Package
incompatibleNativeModules
handleError: (message, error) ->
if atom.inSpecMode()
throw error
if error.filename and error.location and (error instanceof SyntaxError)
location = "#{error.filename}:#{error.location.first_line + 1}:#{error.location.first_column + 1}"
detail = "#{error.message} in #{location}"