Skip to content
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

fix(plugin-navigation-breadcrumbs): Don't call startSession() if autoCaptureSessions=false #514

Merged
merged 1 commit into from
Apr 3, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const wrapHistoryFn = (client, target, fn, win) => {
client.leaveBreadcrumb(`History ${fn}`, stateChangeToMetaData(win, state, title, url), 'navigation')
// if throttle plugin is in use, refresh the event sent count
if (typeof client.refresh === 'function') client.refresh()
// if the client is operating in session-mode, a new route should trigger a new session
if (client.session) client.startSession()
// if the client is operating in auto session-mode, a new route should trigger a new session
if (client.config.autoCaptureSessions) client.startSession()
// Internet Explorer will convert `undefined` to a string when passed, causing an unintended redirect
// to '/undefined'. therefore we only pass the url if it's not undefined.
orig.apply(target, [ state, title ].concat(url !== undefined ? url : []))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ describe('plugin: navigation breadcrumbs', () => {
expect(c.breadcrumbs.length).toBe(0)
})

it('should start a new session if autoCaptureSessions=true', (done) => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa' })
c.configure()
c.sessionDelegate({
startSession: client => {
done()
}
})
const { winHandlers, docHandlers, window } = getMockWindow()
c.use(plugin, window)
winHandlers['load'].forEach((h) => h.call(window))
docHandlers['DOMContentLoaded'].forEach((h) => h.call(window.document))
window.history.replaceState({}, 'bar', 'network-breadcrumb-test.html')
})

it('should not a new session if autoCaptureSessions=false', (done) => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa', autoCaptureSessions: false })
c.configure()
c.sessionDelegate({
startSession: client => {
expect('shouldn’t get here').toBe(false)
done()
}
})
const { winHandlers, docHandlers, window } = getMockWindow()
c.use(plugin, window)
winHandlers['load'].forEach((h) => h.call(window))
docHandlers['DOMContentLoaded'].forEach((h) => h.call(window.document))
window.history.replaceState({}, 'bar', 'network-breadcrumb-test.html')
setTimeout(() => done(), 1)
})

it('should be enabled when autoBreadcrumbs=false and navigationBreadcrumbsEnabled=true', () => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa', autoBreadcrumbs: false, navigationBreadcrumbsEnabled: true })
Expand Down