From e8030709b9e698182bd53cb60b8e648f48091aba Mon Sep 17 00:00:00 2001 From: Christian Schlensker Date: Fri, 9 Sep 2016 11:56:55 -0700 Subject: [PATCH] Create "Bugsnag loaded" breadcrumb (#179) --- src/bugsnag.js | 5 +++++ test/test.bugsnag.js | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/bugsnag.js b/src/bugsnag.js index 01beb7a039..6770e0ade7 100644 --- a/src/bugsnag.js +++ b/src/bugsnag.js @@ -1109,6 +1109,11 @@ trackConsoleLog(); trackNavigation(); + // Leave the initial breadcrumb + if (getSetting("autoBreadcrumbs", true)) { + self.leaveBreadcrumb({ type: "navigation", name: "Bugsnag Loaded" }); + } + window.Bugsnag = self; // If people are using a javascript loader, we should integrate with it. // We don't want to defer instrumenting their code with callbacks however, diff --git a/test/test.bugsnag.js b/test/test.bugsnag.js index de4c1eaf9f..7d6c7eea8f 100644 --- a/test/test.bugsnag.js +++ b/test/test.bugsnag.js @@ -436,7 +436,7 @@ describe("Bugsnag", function () { } }; - var actual = requestData().params.breadcrumbs[0]; + var actual = requestData().params.breadcrumbs[1]; assert(actual, "no breadcrumbs present"); assert.equal(actual.type, expected.type); @@ -455,7 +455,7 @@ describe("Bugsnag", function () { } }; - var actual = requestData().params.breadcrumbs[0]; + var actual = requestData().params.breadcrumbs[1]; assert.equal(actual.name, expected.name); assert.deepEqual(actual.metaData, expected.metaData); @@ -475,7 +475,7 @@ describe("Bugsnag", function () { Bugsnag.leaveBreadcrumb(expected); Bugsnag.notify("Something"); - var actual = requestData().params.breadcrumbs[0]; + var actual = requestData().params.breadcrumbs[1]; assert.deepEqual(actual, expected); }); @@ -493,14 +493,14 @@ describe("Bugsnag", function () { Bugsnag.notify("Something"); // Replacing an invalid breadcrumb also triggers a console log breadcrumb - var logCrumb = requestData().params.breadcrumbs[0]; + var logCrumb = requestData().params.breadcrumbs[1]; assert.equal(logCrumb.type, "log"); assert.equal( logCrumb.metaData.message, "[Bugsnag] Converted invalid breadcrumb type 'fanciful' to 'manual'" ); - var actualCrumb = requestData().params.breadcrumbs[1]; + var actualCrumb = requestData().params.breadcrumbs[2]; assert.equal(actualCrumb.type, "manual"); }); @@ -512,7 +512,7 @@ describe("Bugsnag", function () { Bugsnag.leaveBreadcrumb(longValue); Bugsnag.notify("Something"); - var crumb = requestData().params.breadcrumbs[0]; + var crumb = requestData().params.breadcrumbs[1]; assert.equal(crumb.metaData.message.length, 140); }); @@ -550,7 +550,7 @@ describe("Bugsnag", function () { } }; - var actual = requestData().params.breadcrumbs[0]; + var actual = requestData().params.breadcrumbs[1]; assert(actual, "no breadcrumbs present"); assert.equal(actual.type, expected.type); @@ -562,7 +562,7 @@ describe("Bugsnag", function () { container.className = "blue steel"; clickOn(container); Bugsnag.notify("Something"); - var selector = requestData().params.breadcrumbs[0].metaData.targetSelector; + var selector = requestData().params.breadcrumbs[1].metaData.targetSelector; assert.equal(selector, "DIV#container.blue.steel"); }); @@ -570,14 +570,14 @@ describe("Bugsnag", function () { container.textContent = "\n Hello \n\n"; clickOn(container); Bugsnag.notify("Something"); - assert.equal(requestData().params.breadcrumbs[0].metaData.targetText, "Hello"); + assert.equal(requestData().params.breadcrumbs[1].metaData.targetText, "Hello"); }); it("handles invalid id attributes", function() { container.id = "12345"; clickOn(container); Bugsnag.notify("Something"); - var selector = requestData().params.breadcrumbs[0].metaData.targetSelector; + var selector = requestData().params.breadcrumbs[1].metaData.targetSelector; assert.equal(selector, "DIV#12345"); }); });