From 2a83f5cc303eb4bc0afa90cdbc4a16a7c296798e Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sun, 5 Oct 2025 05:57:56 -0700 Subject: [PATCH] Don't mutate suite's failedExpectations from env --- lib/jasmine-core/jasmine.js | 9 ++++++++- spec/core/integration/GlobalErrorHandlingSpec.js | 10 +++++----- src/core/Env.js | 2 +- src/core/buildExpectationResult.js | 7 +++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 76d40626..4d88e1d7 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1252,7 +1252,7 @@ getJasmineRequireObj().Env = function(j$) { if (!envOptions.suppressLoadErrors) { installGlobalErrors(); globalErrors.pushListener(function loadtimeErrorHandler(error) { - topSuite.result.failedExpectations.push({ + topSuite.addExpectationResult(false, { passed: false, globalErrorType: 'load', message: error.message, @@ -2597,6 +2597,13 @@ getJasmineRequireObj().buildExpectationResult = function(j$) { globalErrorType: options.globalErrorType }; + if (options.filename !== undefined) { + result.filename = options.filename; + } + if (options.lineno !== undefined) { + result.lineno = options.lineno; + } + if (!result.passed) { if (options.error && !j$.private.isString(options.error)) { if ('code' in options.error) { diff --git a/spec/core/integration/GlobalErrorHandlingSpec.js b/spec/core/integration/GlobalErrorHandlingSpec.js index caf59b38..95d206eb 100644 --- a/spec/core/integration/GlobalErrorHandlingSpec.js +++ b/spec/core/integration/GlobalErrorHandlingSpec.js @@ -53,17 +53,17 @@ describe('Global error handling (integration)', function() { passed: false, globalErrorType: 'load', message: 'Uncaught SyntaxError: Unexpected end of input', - stack: '@borkenSpec.js:42', filename: 'borkenSpec.js', - lineno: 42 + lineno: 42, + matcherName: undefined, + stack: jasmine.any(String) }, { passed: false, globalErrorType: 'load', message: 'ENOCHEESE', - stack: error.stack, - filename: undefined, - lineno: undefined + matcherName: undefined, + stack: jasmine.any(String) } ]); }); diff --git a/src/core/Env.js b/src/core/Env.js index c542b2df..ba69fc66 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -68,7 +68,7 @@ getJasmineRequireObj().Env = function(j$) { if (!envOptions.suppressLoadErrors) { installGlobalErrors(); globalErrors.pushListener(function loadtimeErrorHandler(error) { - topSuite.result.failedExpectations.push({ + topSuite.addExpectationResult(false, { passed: false, globalErrorType: 'load', message: error.message, diff --git a/src/core/buildExpectationResult.js b/src/core/buildExpectationResult.js index 78a102da..442a5b25 100644 --- a/src/core/buildExpectationResult.js +++ b/src/core/buildExpectationResult.js @@ -23,6 +23,13 @@ getJasmineRequireObj().buildExpectationResult = function(j$) { globalErrorType: options.globalErrorType }; + if (options.filename !== undefined) { + result.filename = options.filename; + } + if (options.lineno !== undefined) { + result.lineno = options.lineno; + } + if (!result.passed) { if (options.error && !j$.private.isString(options.error)) { if ('code' in options.error) {