@@ -2564,26 +2564,6 @@ describe('Raven (public API)', function() {
25642564 } ) ;
25652565 } ) ;
25662566
2567- describe ( '._captureUrlChange' , function ( ) {
2568- it ( 'should create a new breadcrumb from its "from" and "to" arguments' , function ( ) {
2569- Raven . _breadcrumbs = [ ] ;
2570- Raven . _captureUrlChange ( '/foo' , '/bar' ) ;
2571- assert . deepEqual ( Raven . _breadcrumbs , [
2572- { category : 'navigation' , timestamp : 0.1 , data : { from : '/foo' , to : '/bar' } }
2573- ] ) ;
2574- } ) ;
2575-
2576- it ( 'should strip protocol/host if passed URLs share the same origin as location.href' , function ( ) {
2577- Raven . _location = { href : 'http://example.com/foo' } ;
2578- Raven . _breadcrumbs = [ ] ;
2579-
2580- Raven . _captureUrlChange ( 'http://example.com/foo' , 'http://example.com/bar' ) ;
2581- assert . deepEqual ( Raven . _breadcrumbs , [
2582- { category : 'navigation' , timestamp : 0.1 , data : { from : '/foo' , to : '/bar' } }
2583- ] ) ;
2584- } ) ;
2585- } ) ;
2586-
25872567 describe ( '.Raven.isSetup' , function ( ) {
25882568 it ( 'should work as advertised' , function ( ) {
25892569 var isSetup = this . sinon . stub ( Raven , 'isSetup' ) ;
@@ -2675,6 +2655,143 @@ describe('Raven (public API)', function() {
26752655 } ) ;
26762656} ) ;
26772657
2658+ describe ( 'Raven (private methods)' , function ( ) {
2659+ beforeEach ( function ( ) {
2660+ this . clock = sinon . useFakeTimers ( ) ;
2661+ this . clock . tick ( 0 ) ; // Raven initialized at time "0"
2662+ Raven = new _Raven ( ) ;
2663+ } ) ;
2664+
2665+ afterEach ( function ( ) {
2666+ this . clock . restore ( ) ;
2667+ } ) ;
2668+
2669+ describe ( '._captureUrlChange' , function ( ) {
2670+ it ( 'should create a new breadcrumb from its "from" and "to" arguments' , function ( ) {
2671+ this . clock . tick ( 100 ) ;
2672+ Raven . _breadcrumbs = [ ] ;
2673+ Raven . _captureUrlChange ( '/foo' , '/bar' ) ;
2674+ assert . deepEqual ( Raven . _breadcrumbs , [
2675+ { category : 'navigation' , timestamp : 0.1 , data : { from : '/foo' , to : '/bar' } }
2676+ ] ) ;
2677+ } ) ;
2678+
2679+ it ( 'should strip protocol/host if passed URLs share the same origin as location.href' , function ( ) {
2680+ this . clock . tick ( 100 ) ;
2681+ Raven . _location = { href : 'http://example.com/foo' } ;
2682+ Raven . _breadcrumbs = [ ] ;
2683+
2684+ Raven . _captureUrlChange ( 'http://example.com/foo' , 'http://example.com/bar' ) ;
2685+ assert . deepEqual ( Raven . _breadcrumbs , [
2686+ { category : 'navigation' , timestamp : 0.1 , data : { from : '/foo' , to : '/bar' } }
2687+ ] ) ;
2688+ } ) ;
2689+ } ) ;
2690+
2691+ describe ( '._isRepeatData' , function ( ) {
2692+ describe ( 'from captureMessage' , function ( ) {
2693+ beforeEach ( function ( ) {
2694+ Raven . _lastData = {
2695+ message : 'the thing broke'
2696+ }
2697+ } ) ;
2698+
2699+ it ( 'should return true for duplicate captureMessage payloads' , function ( ) {
2700+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2701+ assert . isTrue ( Raven . _isRepeatData ( data ) ) ;
2702+ } ) ;
2703+
2704+ it ( 'should return true for duplicate captureMessage payloads w/ synthetic traces' , function ( ) {
2705+ Raven . _lastData . stacktrace = {
2706+ frames : [ {
2707+ lineno : 100 ,
2708+ colno : 1337 ,
2709+ 'function' : 'lol' ,
2710+ filename : 'https://example.com/js/foo.js'
2711+ } ]
2712+ } ;
2713+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2714+ assert . isTrue ( Raven . _isRepeatData ( data ) ) ;
2715+ } ) ;
2716+
2717+ it ( 'should return false for different messages' , function ( ) {
2718+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2719+ data . message = 'the other thing broke' ;
2720+
2721+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2722+ } ) ;
2723+
2724+ it ( 'should return false for different captureMessage payloads w/ synthetic traces' , function ( ) {
2725+ Raven . _lastData . stacktrace = {
2726+ frames : [ {
2727+ lineno : 100 ,
2728+ colno : 1337 ,
2729+ 'function' : 'lol' ,
2730+ filename : 'https://example.com/js/foo.js'
2731+ } , {
2732+ lineno : 200 ,
2733+ colno : 1338 ,
2734+ 'function' : 'woo' ,
2735+ filename : 'https://example.com/js/bar.js'
2736+ } ]
2737+ } ;
2738+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2739+ data . stacktrace . frames [ 0 ] . lineno = 101 ;
2740+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2741+
2742+ data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2743+ data . stacktrace . frames . shift ( ) ; // different frame count
2744+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2745+
2746+ data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2747+ data . stacktrace = undefined ; // no stacktrace, same msg
2748+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2749+ } ) ;
2750+ } ) ;
2751+
2752+ describe ( 'from captureException/onerror' , function ( ) {
2753+ beforeEach ( function ( ) {
2754+ Raven . _lastData = {
2755+ culprit : 'https://example.com/js/foo.js' ,
2756+ exception : {
2757+ type : 'TypeError' ,
2758+ value : 'foo is not defined' ,
2759+ values : [ {
2760+ stacktrace : {
2761+ frames : [ {
2762+ lineno : 100 ,
2763+ colno : 1337 ,
2764+ 'function' : 'lol' ,
2765+ filename : 'https://example.com/js/foo.js'
2766+ } ]
2767+ }
2768+ } ]
2769+ }
2770+ }
2771+ } ) ;
2772+
2773+ it ( 'should return true for duplicate exceptions' , function ( ) {
2774+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2775+ assert . isTrue ( Raven . _isRepeatData ( data ) ) ;
2776+ } ) ;
2777+
2778+ it ( 'should return false for different exceptions' , function ( ) {
2779+ var data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2780+ data . culprit = 'https://example.com/js/bar.js' ;
2781+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2782+
2783+ data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2784+ data . exception . values [ 0 ] . stacktrace . frames [ 0 ] . lineno = 101 ;
2785+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2786+
2787+ data = JSON . parse ( JSON . stringify ( Raven . _lastData ) ) ; // copy
2788+ data . exception . values [ 0 ] . stacktrace . frames = [ ] ;
2789+ assert . isFalse ( Raven . _isRepeatData ( data ) ) ;
2790+ } ) ;
2791+ } ) ;
2792+ } ) ;
2793+ } ) ;
2794+
26782795// intentionally separate install/uninstall from other test methods, because
26792796// the built-in wrapping doesn't play nice w/ Sinon's useFakeTimers() [won't
26802797// restore setTimeout, setInterval, etc]
0 commit comments