22/* global Promise */
33'use strict' ;
44
5+ var versionRegexp = / ^ v ( \d + ) \. ( \d + ) \. ( \d + ) $ / i;
6+ var majorVersion = parseInt ( versionRegexp . exec ( process . version ) [ 1 ] , 10 ) ;
7+
58var raven = require ( '../' ) ,
69 nock = require ( 'nock' ) ,
710 url = require ( 'url' ) ,
@@ -246,6 +249,62 @@ describe('raven.Client', function() {
246249 client . captureException ( 'wtf?' ) ;
247250 } ) ;
248251
252+ it ( 'should serialize non-error exceptions' , function ( done ) {
253+ var old = client . send ;
254+ client . send = function mockSend ( kwargs ) {
255+ client . send = old ;
256+
257+ kwargs . message . should . equal (
258+ 'Non-Error exception captured with keys: aKeyOne, bKeyTwo, cKeyThree, dKeyFour\u2026'
259+ ) ;
260+
261+ // Remove superfluous node version data to simplify the test itself
262+ delete kwargs . extra . node ;
263+ kwargs . extra . should . have . property ( '__serialized__' , {
264+ aKeyOne : 'a' ,
265+ bKeyTwo : 42 ,
266+ cKeyThree : { } ,
267+ dKeyFour : [ 'd' ] ,
268+ eKeyFive : '[Function: foo]' ,
269+ fKeySix : {
270+ levelTwo : {
271+ levelThreeObject : '[Object]' ,
272+ levelThreeArray : '[Array]' ,
273+ // Node < 6 is not capable of pulling function name from unnamed object methods
274+ levelThreeAnonymousFunction :
275+ majorVersion < 6
276+ ? '[Function]'
277+ : '[Function: levelThreeAnonymousFunction]' ,
278+ levelThreeNamedFunction : '[Function: bar]' ,
279+ levelThreeString : 'foo' ,
280+ levelThreeNumber : 42
281+ }
282+ }
283+ } ) ;
284+
285+ done ( ) ;
286+ } ;
287+ client . captureException ( {
288+ aKeyOne : 'a' ,
289+ bKeyTwo : 42 ,
290+ cKeyThree : { } ,
291+ dKeyFour : [ 'd' ] ,
292+ eKeyFive : function foo ( ) { } ,
293+ fKeySix : {
294+ levelTwo : {
295+ levelThreeObject : {
296+ enough : 42
297+ } ,
298+ levelThreeArray : [ 42 ] ,
299+ levelThreeAnonymousFunction : function ( ) { } ,
300+ levelThreeNamedFunction : function bar ( ) { } ,
301+ levelThreeString : 'foo' ,
302+ levelThreeNumber : 42
303+ }
304+ }
305+ } ) ;
306+ } ) ;
307+
249308 it ( 'should send an Error to Sentry server on another port' , function ( done ) {
250309 var scope = nock ( 'https://app.getsentry.com:8443' )
251310 . filteringRequestBody ( / .* / , '*' )
@@ -380,19 +439,15 @@ describe('raven.Client', function() {
380439
381440 describe ( 'exit conditions' , function ( ) {
382441 var exitStr = 'exit test assertions complete\n' ;
383- it ( 'should catch an uncaughtException and capture it before exiting' , function (
384- done
385- ) {
442+ it ( 'should catch an uncaughtException and capture it before exiting' , function ( done ) {
386443 child_process . exec ( 'node test/exit/capture.js' , function ( err , stdout , stderr ) {
387444 stdout . should . equal ( exitStr ) ;
388445 stderr . should . startWith ( 'Error: derp' ) ;
389446 done ( ) ;
390447 } ) ;
391448 } ) ;
392449
393- it ( 'should catch an uncaughtException and capture it before calling a provided callback' , function (
394- done
395- ) {
450+ it ( 'should catch an uncaughtException and capture it before calling a provided callback' , function ( done ) {
396451 child_process . exec ( 'node test/exit/capture_callback.js' , function (
397452 err ,
398453 stdout ,
@@ -405,9 +460,7 @@ describe('raven.Client', function() {
405460 } ) ;
406461 } ) ;
407462
408- it ( 'should catch an uncaughtException and capture it without a second followup exception causing premature shutdown' , function (
409- done
410- ) {
463+ it ( 'should catch an uncaughtException and capture it without a second followup exception causing premature shutdown' , function ( done ) {
411464 child_process . exec ( 'node test/exit/capture_with_second_error.js' , function (
412465 err ,
413466 stdout ,
@@ -419,9 +472,7 @@ describe('raven.Client', function() {
419472 } ) ;
420473 } ) ;
421474
422- it ( 'should treat an error thrown by captureException from uncaughtException handler as a sending error passed to onFatalError' , function (
423- done
424- ) {
475+ it ( 'should treat an error thrown by captureException from uncaughtException handler as a sending error passed to onFatalError' , function ( done ) {
425476 this . timeout ( 4000 ) ;
426477 child_process . exec ( 'node test/exit/throw_on_send.js' , function (
427478 err ,
@@ -447,9 +498,7 @@ describe('raven.Client', function() {
447498 } ) ;
448499 } ) ;
449500
450- it ( 'should catch a domain exception and capture it before calling a provided callback' , function (
451- done
452- ) {
501+ it ( 'should catch a domain exception and capture it before calling a provided callback' , function ( done ) {
453502 child_process . exec ( 'node test/exit/domain_capture_callback.js' , function (
454503 err ,
455504 stdout ,
@@ -462,9 +511,7 @@ describe('raven.Client', function() {
462511 } ) ;
463512 } ) ;
464513
465- it ( 'should catch a domain exception and capture it without a second followup exception causing premature shutdown' , function (
466- done
467- ) {
514+ it ( 'should catch a domain exception and capture it without a second followup exception causing premature shutdown' , function ( done ) {
468515 child_process . exec ( 'node test/exit/domain_capture_with_second_error.js' , function (
469516 err ,
470517 stdout ,
@@ -476,9 +523,7 @@ describe('raven.Client', function() {
476523 } ) ;
477524 } ) ;
478525
479- it ( 'should treat an error thrown by captureException from domain exception handler as a sending error passed to onFatalError' , function (
480- done
481- ) {
526+ it ( 'should treat an error thrown by captureException from domain exception handler as a sending error passed to onFatalError' , function ( done ) {
482527 this . timeout ( 4000 ) ;
483528 child_process . exec ( 'node test/exit/domain_throw_on_send.js' , function (
484529 err ,
@@ -492,9 +537,7 @@ describe('raven.Client', function() {
492537 } ) ;
493538 } ) ;
494539
495- it ( 'should catch an uncaughtException and capture it without a second followup domain exception causing premature shutdown' , function (
496- done
497- ) {
540+ it ( 'should catch an uncaughtException and capture it without a second followup domain exception causing premature shutdown' , function ( done ) {
498541 child_process . exec ( 'node test/exit/capture_with_second_domain_error.js' , function (
499542 err ,
500543 stdout ,
@@ -506,9 +549,7 @@ describe('raven.Client', function() {
506549 } ) ;
507550 } ) ;
508551
509- it ( 'should catch an uncaughtException and capture it and failsafe shutdown if onFatalError throws' , function (
510- done
511- ) {
552+ it ( 'should catch an uncaughtException and capture it and failsafe shutdown if onFatalError throws' , function ( done ) {
512553 child_process . exec ( 'node test/exit/throw_on_fatal.js' , function (
513554 err ,
514555 stdout ,
@@ -579,9 +620,7 @@ describe('raven.Client', function() {
579620 ) ;
580621 } ) ;
581622
582- it ( 'should pass original shouldSendCallback to newer shouldSendCallback' , function (
583- done
584- ) {
623+ it ( 'should pass original shouldSendCallback to newer shouldSendCallback' , function ( done ) {
585624 var cb1 = function ( data ) {
586625 return false ;
587626 } ;
0 commit comments