From cc69edf92c2d88abb8795dcdb011dfbd3b75a6a3 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 22 Jun 2024 11:49:49 -0700 Subject: [PATCH] Fixed stack trace filtering in FF when the developer tools are open --- lib/jasmine-core/jasmine.js | 11 ++++++++++- spec/core/ExceptionFormatterSpec.js | 19 +++++++++++++++++++ src/core/StackTrace.js | 11 ++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 6298b922..0d5bf2c8 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -9774,7 +9774,7 @@ getJasmineRequireObj().StackTrace = function(j$) { // e.g. " at /some/path:4320:20 { re: /\s*at (.+)$/, fileLineColIx: 1, style: 'v8' }, - // PhantomJS on OS X, Safari, Firefox + // Safari, most Firefox stack frames // e.g. "run@http://localhost:8888/__jasmine__/jasmine.js:4320:27" // or "http://localhost:8888/__jasmine__/jasmine.js:4320:27" { @@ -9782,6 +9782,15 @@ getJasmineRequireObj().StackTrace = function(j$) { fnIx: 2, fileLineColIx: 3, style: 'webkit' + }, + + // Some Firefox stack frames when the developer tools are open + // e.g. "promise callback*specStarted@http://localhost:8888/__jasmine__/jasmine.js:1880:41" + { + re: /^^(?:((?:promise callback|[^\s]+ handler)\*([^@\s]+)@)|@)?([^\s]+)$/, + fnIx: 2, + fileLineColIx: 3, + style: 'webkit' } ]; diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 51a4c61b..c720da1d 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -153,6 +153,25 @@ describe('ExceptionFormatter', function() { ); }); + it('filters Jasmine stack frames with Firefox async annotations', function() { + const error = { + stack: + 'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' + + 'promise callback*fn1@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' + + 'setTimeout handler*fn2@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' + + 'http://localhost:8888/__spec__/core/UtilSpec.js:115:28' + }; + const subject = new jasmineUnderTest.ExceptionFormatter({ + jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js' + }); + const result = subject.stack(error); + expect(result).toEqual( + 'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' + + '\n' + + 'http://localhost:8888/__spec__/core/UtilSpec.js:115:28' + ); + }); + it('filters Jasmine stack frames in this environment', function() { const error = new Error('an error'); const subject = new jasmineUnderTest.ExceptionFormatter({ diff --git a/src/core/StackTrace.js b/src/core/StackTrace.js index 2f930beb..9038e470 100644 --- a/src/core/StackTrace.js +++ b/src/core/StackTrace.js @@ -32,7 +32,7 @@ getJasmineRequireObj().StackTrace = function(j$) { // e.g. " at /some/path:4320:20 { re: /\s*at (.+)$/, fileLineColIx: 1, style: 'v8' }, - // PhantomJS on OS X, Safari, Firefox + // Safari, most Firefox stack frames // e.g. "run@http://localhost:8888/__jasmine__/jasmine.js:4320:27" // or "http://localhost:8888/__jasmine__/jasmine.js:4320:27" { @@ -40,6 +40,15 @@ getJasmineRequireObj().StackTrace = function(j$) { fnIx: 2, fileLineColIx: 3, style: 'webkit' + }, + + // Some Firefox stack frames when the developer tools are open + // e.g. "promise callback*specStarted@http://localhost:8888/__jasmine__/jasmine.js:1880:41" + { + re: /^^(?:((?:promise callback|[^\s]+ handler)\*([^@\s]+)@)|@)?([^\s]+)$/, + fnIx: 2, + fileLineColIx: 3, + style: 'webkit' } ];