computmaxer / karma-jspm

Other
74 stars 50 forks source link

CP-1392 Redirected errors during System().import to karma().error. #130

Closed FrederikNJS closed 8 years ago

FrederikNJS commented 8 years ago

Fixes #128

The issue in #128 was that if the System.import() function failed, then all the browsers would disconnect with a "Potentially unhandled rejection". This is mostly annoying for SyntaxErrors.

By catching the errors from System.import, and redirecting the message to karma.error(), karma-jspm is improved in the following ways:

Before a syntax error would result in the following output:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR: 'Potentially unhandled rejection [3] eval@[native code]
__exec@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:1395:16
execute@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3521:20
linkDynamicModule@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3126:36
link@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:2969:28
execute@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3301:17
doDynamicExecute@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:703:32
link@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:905:36
doLink@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:557:11
updateLinkSetOnLoad@http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:605:24
http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:417:30
tryCatchReject@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:1252:34
runContinuation1@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:1211:18
when@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:999:20
run@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:890:17
_drain@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:166:22
drain@http://localhost:9877/base/jspm_packages/system-polyfills.src.js?3aa57969dce4ecea4c51aab540f372d15cc886b6:131:15'

Chrome 48.0.2564 (Linux 0.0.0) ERROR: 'Potentially unhandled rejection [3] SyntaxError: missing ) after argument list
    Evaluating http://localhost:9877/base/test/brokentest.js
    Error loading http://localhost:9877/base/test/brokentest.js
    at eval (native)
    at SystemJSLoader.__exec (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:1395:16)
    at entry.execute (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3521:16)
    at linkDynamicModule (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3126:32)
    at link (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:2969:11)
    at Object.execute (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:3301:13)
    at doDynamicExecute (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:703:25)
    at link (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:905:20)
    at doLink (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:557:7)
    at updateLinkSetOnLoad (http://localhost:9877/base/jspm_packages/system.src.js?38538ebca96bc7b222f7e7ba15943f173a485f6e:605:18)'

19 02 2016 13:17:04.301:WARN [PhantomJS 2.1.1 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.

19 02 2016 13:17:04.344:WARN [Chrome 48.0.2564 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.

With this pull request, the output is instead:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  SyntaxError: Expected token ')'
    Evaluating /home/frederiknjs/Code/personal/karma/test/brokentest.js
    Error loading /home/frederiknjs/Code/personal/karma/test/brokentest.js

Chrome 48.0.2564 (Linux 0.0.0) ERROR
  SyntaxError: missing ) after argument list
    Evaluating /home/frederiknjs/Code/personal/karma/test/brokentest.js
    Error loading /home/frederiknjs/Code/personal/karma/test/brokentest.js

Hope you like it :-)

maxwellpeterson-wf commented 8 years ago

+1 very nice! @trentgrover-wf @evanweible-wf @jayudey-wf

evanweible-wf commented 8 years ago

Awesome! +1

FrederikNJS commented 8 years ago

Interestingly, the output is even better in another of my projects. I'm not sure why, but it might just be because there is more code. Here's an example:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  SyntaxError: /home/frederiknjs/Code/personal/gw2map/javascript/model/region.js: Unexpected token (11:2)
     9 |     this._zones = regionDef.get('maps').valueSeq().map(mapDef=>new Zone(mapDef, iconUrls))
    10 |     this.name = regionDef.get('name').
  > 11 |   }
       |   ^
    12 | 
    13 |   get zones() {
    14 |     return this._zones.filter(zone => !this._Zone.falseZones.has(zone.id))
    Error loading /home/frederiknjs/Code/personal/gw2map/javascript/model/region.js as "javascript/model/region" from /home/frederiknjs/Code/personal/gw2map/test/model/floor-spec.js
jayudey-wf commented 8 years ago

QA Resource Approval: +10

Merging into master.