mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-03-02 02:10:49 +03:00
Include 3 extra frames when Error.captureStackTrace not supported
To get the necessary limit after excluding extensions frames
This commit is contained in:
parent
2960ac6eae
commit
292e5f64c4
packages/redux-devtools-instrument
|
@ -40,6 +40,7 @@ export const ActionCreators = {
|
||||||
|
|
||||||
let stack;
|
let stack;
|
||||||
if (trace) {
|
if (trace) {
|
||||||
|
let extraFrames = 0;
|
||||||
if (typeof trace === 'function') {
|
if (typeof trace === 'function') {
|
||||||
stack = trace(action);
|
stack = trace(action);
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,13 +52,15 @@ export const ActionCreators = {
|
||||||
Error.stackTraceLimit = traceLimit;
|
Error.stackTraceLimit = traceLimit;
|
||||||
}
|
}
|
||||||
Error.captureStackTrace(error, toExcludeFromTrace);
|
Error.captureStackTrace(error, toExcludeFromTrace);
|
||||||
|
} else {
|
||||||
|
extraFrames = 3;
|
||||||
}
|
}
|
||||||
stack = error.stack;
|
stack = error.stack;
|
||||||
if (prevStackTraceLimit) Error.stackTraceLimit = prevStackTraceLimit;
|
if (prevStackTraceLimit) Error.stackTraceLimit = prevStackTraceLimit;
|
||||||
if (typeof Error.stackTraceLimit !== 'number' || Error.stackTraceLimit > traceLimit) {
|
if (extraFrames || typeof Error.stackTraceLimit !== 'number' || Error.stackTraceLimit > traceLimit) {
|
||||||
const frames = stack.split('\n');
|
const frames = stack.split('\n');
|
||||||
if (frames.length > traceLimit) {
|
if (frames.length > traceLimit) {
|
||||||
stack = frames.slice(0, traceLimit + (frames[0] === 'Error' ? 1 : 0)).join('\n');
|
stack = frames.slice(0, traceLimit + extraFrames + (frames[0] === 'Error' ? 1 : 0)).join('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -805,6 +805,24 @@ describe('instrument', () => {
|
||||||
fn4();
|
fn4();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include 3 extra frames when Error.captureStackTrace not suported', () => {
|
||||||
|
const captureStackTrace = Error.captureStackTrace;
|
||||||
|
Error.captureStackTrace = undefined;
|
||||||
|
monitoredStore = createStore(counter, instrument(undefined, { trace: true, traceLimit: 5 }));
|
||||||
|
monitoredLiftedStore = monitoredStore.liftedStore;
|
||||||
|
monitoredStore.dispatch({ type: 'INCREMENT' });
|
||||||
|
Error.captureStackTrace = captureStackTrace;
|
||||||
|
|
||||||
|
exportedState = monitoredLiftedStore.getState();
|
||||||
|
expect(exportedState.actionsById[0].stack).toBe(undefined);
|
||||||
|
expect(exportedState.actionsById[1].stack).toBeA('string');
|
||||||
|
expect(exportedState.actionsById[1].stack).toMatch(/^Error/);
|
||||||
|
expect(exportedState.actionsById[1].stack).toContain('instrument.js');
|
||||||
|
expect(exportedState.actionsById[1].stack).toContain('instrument.spec.js');
|
||||||
|
expect(exportedState.actionsById[1].stack).toContain('/mocha/');
|
||||||
|
expect(exportedState.actionsById[1].stack.split('\n').length).toBe(5 + 3 + 1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should get stack trace from a function', () => {
|
it('should get stack trace from a function', () => {
|
||||||
const traceFn = () => new Error().stack;
|
const traceFn = () => new Error().stack;
|
||||||
monitoredStore = createStore(counter, instrument(undefined, { trace: traceFn }));
|
monitoredStore = createStore(counter, instrument(undefined, { trace: traceFn }));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user