Skip to content

Commit 2b8b730

Browse files
authored
Merge extras (#59)
1 parent 27506d5 commit 2b8b730

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ function createRavenMiddleware(Raven, options = {}) {
1717

1818
Raven.setDataCallback((data, original) => {
1919
const state = store.getState();
20-
data.extra.lastAction = actionTransformer(lastAction);
21-
data.extra.state = stateTransformer(state);
20+
const reduxExtra = {
21+
lastAction: actionTransformer(lastAction),
22+
state: stateTransformer(state)
23+
};
24+
data.extra = Object.assign(reduxExtra, data.extra);
2225
if (getUserContext) {
2326
data.user = getUserContext(state);
2427
}

index.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ describe("raven-for-redux", () => {
4141
context.middleware = createRavenMiddleware(Raven);
4242
context.store = createStore(reducer, applyMiddleware(context.middleware));
4343
});
44+
it("merges Redux info with existing 'extras'", () => {
45+
Raven.captureException(new Error("Crash!"), {
46+
extra: { anotherValue: 10 }
47+
});
48+
const { extra } = context.mockTransport.mock.calls[0][0].data;
49+
expect(extra).toMatchObject({
50+
state: { value: 0 },
51+
lastAction: undefined,
52+
anotherValue: 10
53+
// session:duration will also be defined
54+
});
55+
});
56+
it("if explicitly passed extras contain a `state` property, the explicit version wins", () => {
57+
Raven.captureException(new Error("Crash!"), {
58+
extra: { anotherValue: 10, state: "SOME OTHER STATE" }
59+
});
60+
const { extra } = context.mockTransport.mock.calls[0][0].data;
61+
expect(extra).toMatchObject({
62+
state: "SOME OTHER STATE",
63+
lastAction: undefined,
64+
anotherValue: 10
65+
// session:duration will also be defined
66+
});
67+
});
68+
it("if explicitly passed extras contain a `lastAction` property, the explicit version wins", () => {
69+
Raven.captureException(new Error("Crash!"), {
70+
extra: { anotherValue: 10, lastAction: "SOME OTHER LAST ACTION" }
71+
});
72+
const { extra } = context.mockTransport.mock.calls[0][0].data;
73+
expect(extra).toMatchObject({
74+
state: { value: 0 },
75+
lastAction: "SOME OTHER LAST ACTION",
76+
anotherValue: 10
77+
// session:duration will also be defined
78+
});
79+
});
4480
it("includes the initial state when crashing/messaging before any action has been dispatched", () => {
4581
Raven.captureMessage("report!");
4682

0 commit comments

Comments
 (0)