@@ -2,6 +2,12 @@ const Raven = require("raven-js");
22const createRavenMiddleware = require ( "./index" ) ;
33const { createStore, applyMiddleware } = require ( "redux" ) ;
44
5+ const stringify = require . requireActual (
6+ "./vendor/json-stringify-safe/stringify"
7+ ) ;
8+ const stringifyMocked = require ( "./vendor/json-stringify-safe/stringify" ) ;
9+ jest . mock ( "./vendor/json-stringify-safe/stringify" ) ;
10+
511Raven . config (
612 "https://5d5bf17b1bed4afc9103b5a09634775e@sentry.io/146969"
713) . install ( ) ;
@@ -27,6 +33,7 @@ const context = {};
2733
2834describe ( "raven-for-redux" , ( ) => {
2935 beforeEach ( ( ) => {
36+ stringifyMocked . mockImplementation ( obj => stringify ( obj ) ) ;
3037 context . mockTransport = jest . fn ( ) ;
3138 Raven . setTransport ( context . mockTransport ) ;
3239 Raven . setDataCallback ( undefined ) ;
@@ -188,13 +195,48 @@ describe("raven-for-redux", () => {
188195 } ) ;
189196
190197 [ "captureException" , "captureMessage" ] . forEach ( fnName => {
198+ it ( `skips state for ${ fnName } if state is larger than 200000B` , ( ) => {
199+ expect ( Raven . _globalOptions . transport ) . toEqual ( context . mockTransport ) ;
200+ stringifyMocked
201+ . mockClear ( )
202+ . mockImplementationOnce ( ( ) => ( { length : 200001 } ) )
203+ . mockImplementationOnce ( ( ) => ( { length : 500 } ) ) ;
204+ // Test that allowDuplicates is set to true inside our handler and reset afterwards
205+ // (Error message needs to be unique for each test, because we set allowDuplicates to null)
206+ Raven . _globalOptions . allowDuplicates = null ;
207+ Raven [ fnName ] . call (
208+ Raven ,
209+ fnName === "captureException"
210+ ? new Error ( "Test skip state" )
211+ : "Test skip state"
212+ ) ;
213+
214+ // Ensure transport and allowDuplicates have been reset
215+ expect ( Raven . _globalOptions . transport ) . toEqual ( context . mockTransport ) ;
216+ expect ( Raven . _globalOptions . allowDuplicates ) . toEqual ( null ) ;
217+ expect ( context . mockTransport ) . toHaveBeenCalledTimes ( 1 ) ;
218+ const { extra } = context . mockTransport . mock . calls [ 0 ] [ 0 ] . data ;
219+ expect ( extra ) . toMatchObject ( {
220+ state :
221+ "Could not send state because request would be larger than 200KB. (Was: 200001B)" ,
222+ lastAction : undefined
223+ } ) ;
224+ } ) ;
225+
191226 it ( `retries ${ fnName } without any state if Sentry returns 413 request too large` , ( ) => {
227+ expect ( Raven . _globalOptions . transport ) . toEqual ( context . mockTransport ) ;
192228 context . mockTransport . mockImplementationOnce ( options => {
193229 options . onError ( { request : { status : 413 } } ) ;
194230 } ) ;
195- // allowDuplicates is set to true inside our handler and reset afterwards
231+ // Test that allowDuplicates is set to true inside our handler and reset afterwards
232+ // (Error message needs to be unique for each test, because we set allowDuplicates to null)
196233 Raven . _globalOptions . allowDuplicates = null ;
197- Raven [ fnName ] . call ( Raven , new Error ( "Crash!" ) ) ;
234+ Raven [ fnName ] . call (
235+ Raven ,
236+ fnName === "captureException"
237+ ? new Error ( "Test retry on 413 error" )
238+ : "Test retry on 413 error"
239+ ) ;
198240
199241 // Ensure transport and allowDuplicates have been reset
200242 expect ( Raven . _globalOptions . transport ) . toEqual ( context . mockTransport ) ;
0 commit comments