Skip to content

Merge extras #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ function createRavenMiddleware(Raven, options = {}) {

Raven.setDataCallback((data, original) => {
const state = store.getState();
data.extra.lastAction = actionTransformer(lastAction);
data.extra.state = stateTransformer(state);
const reduxExtra = {
lastAction: actionTransformer(lastAction),
state: stateTransformer(state)
};
data.extra = Object.assign(reduxExtra, data.extra);
if (getUserContext) {
data.user = getUserContext(state);
}
Expand Down
36 changes: 36 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ describe("raven-for-redux", () => {
context.middleware = createRavenMiddleware(Raven);
context.store = createStore(reducer, applyMiddleware(context.middleware));
});
it("merges Redux info with existing 'extras'", () => {
Raven.captureException(new Error("Crash!"), {
extra: { anotherValue: 10 }
});
const { extra } = context.mockTransport.mock.calls[0][0].data;
expect(extra).toMatchObject({
state: { value: 0 },
lastAction: undefined,
anotherValue: 10
// session:duration will also be defined
});
});
it("if explicitly passed extras contain a `state` property, the explicit version wins", () => {
Raven.captureException(new Error("Crash!"), {
extra: { anotherValue: 10, state: "SOME OTHER STATE" }
});
const { extra } = context.mockTransport.mock.calls[0][0].data;
expect(extra).toMatchObject({
state: "SOME OTHER STATE",
lastAction: undefined,
anotherValue: 10
// session:duration will also be defined
});
});
it("if explicitly passed extras contain a `lastAction` property, the explicit version wins", () => {
Raven.captureException(new Error("Crash!"), {
extra: { anotherValue: 10, lastAction: "SOME OTHER LAST ACTION" }
});
const { extra } = context.mockTransport.mock.calls[0][0].data;
expect(extra).toMatchObject({
state: { value: 0 },
lastAction: "SOME OTHER LAST ACTION",
anotherValue: 10
// session:duration will also be defined
});
});
it("includes the initial state when crashing/messaging before any action has been dispatched", () => {
Raven.captureMessage("report!");

Expand Down