Skip to content

Tag Support #69

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
Apr 4, 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
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function createRavenMiddleware(Raven, options = {}) {
stateTransformer = identity,
breadcrumbCategory = "redux-action",
filterBreadcrumbActions = filter,
getUserContext
getUserContext,
getTags
} = options;

return store => {
Expand All @@ -25,6 +26,9 @@ function createRavenMiddleware(Raven, options = {}) {
if (getUserContext) {
data.user = getUserContext(state);
}
if (getTags) {
data.tags = getTags(state);
}
return original ? original(data) : data;
});

Expand Down
14 changes: 13 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe("raven-for-redux", () => {
action => `transformed action ${action.type}`
);
context.getUserContext = jest.fn(state => `user context ${state.value}`);
context.getTags = jest.fn(state => `tags ${state.value}`);
context.breadcrumbDataFromAction = jest.fn(action => ({
extra: action.extra
}));
Expand All @@ -211,7 +212,8 @@ describe("raven-for-redux", () => {
actionTransformer: context.actionTransformer,
breadcrumbDataFromAction: context.breadcrumbDataFromAction,
filterBreadcrumbActions: context.filterBreadcrumbActions,
getUserContext: context.getUserContext
getUserContext: context.getUserContext,
getTags: context.getTags
})
)
);
Expand Down Expand Up @@ -265,6 +267,16 @@ describe("raven-for-redux", () => {
"user context 1"
);
});
it("transforms the tags on data callback", () => {
context.store.dispatch({ type: "INCREMENT", extra: "FOO" });
expect(() => {
context.store.dispatch({ type: "THROW", extra: "BAR" });
}).toThrow();
expect(context.mockTransport).toHaveBeenCalledTimes(1);
expect(context.mockTransport.mock.calls[0][0].data.tags).toEqual(
"tags 1"
);
});
});
describe("with multiple data callbaks", () => {
beforeEach(() => {
Expand Down