Skip to content

Commit 5907ce6

Browse files
committed
fix: Capture only failed console.assert calls
1 parent baf12ae commit 5907ce6

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ export class Breadcrumbs implements Integration {
9898
if (args[0] === false) {
9999
breadcrumbData.message = `Assertion failed: ${safeJoin(args.slice(1), ' ') || 'console.assert'}`;
100100
breadcrumbData.data.extra.arguments = normalize(args.slice(1), 3);
101+
Breadcrumbs.addBreadcrumb(breadcrumbData, {
102+
input: args,
103+
level,
104+
});
101105
}
106+
} else {
107+
Breadcrumbs.addBreadcrumb(breadcrumbData, {
108+
input: args,
109+
level,
110+
});
102111
}
103112

104-
Breadcrumbs.addBreadcrumb(breadcrumbData, {
105-
input: args,
106-
level,
107-
});
108-
109113
// this fails for some browsers. :(
110114
if (originalConsoleLevel) {
111115
Function.prototype.apply.call(originalConsoleLevel, global.console, args);

packages/browser/test/integration/subjects/console-logs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
console.log("One");
22
console.warn("Two", { a: 1 });
33
console.error("Error 2", { b: { c: [] } });
4+
5+
// Passed assertions _should not_ be captured
6+
console.assert(1 + 1 === 2, "math works");
7+
// Failed assertions _should_ be captured
8+
console.assert(1 + 1 === 3, "math broke");
9+
410
function a() {
511
throw new Error("Error thrown 3");
612
}

packages/browser/test/integration/suites/breadcrumbs.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ describe("breadcrumbs", function() {
712712
}
713713
);
714714

715-
it("should add breadcrumbs on thrown errors", function() {
715+
it("should capture console breadcrumbs", function() {
716716
return runInSandbox(sandbox, { manual: true }, function() {
717717
window.allowConsoleBreadcrumbs = true;
718718
var logs = document.createElement("script");
@@ -726,8 +726,15 @@ describe("breadcrumbs", function() {
726726
// The async loader doesn't capture breadcrumbs, but we should receive the event without them
727727
assert.lengthOf(summary.events, 1);
728728
} else {
729-
assert.ok(summary.breadcrumbs);
730-
assert.lengthOf(summary.breadcrumbs, 3);
729+
if ("assert" in console) {
730+
assert.lengthOf(summary.breadcrumbs, 4);
731+
assert.deepEqual(summary.breadcrumbs[3].data.extra.arguments, [
732+
"math broke",
733+
]);
734+
} else {
735+
assert.lengthOf(summary.breadcrumbs, 3);
736+
}
737+
731738
assert.deepEqual(summary.breadcrumbs[0].data.extra.arguments, ["One"]);
732739
assert.deepEqual(summary.breadcrumbs[1].data.extra.arguments, [
733740
"Two",

0 commit comments

Comments
 (0)