From 7aaa16f576e2ea0b146a141a266fd571a07983e6 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 20 Sep 2025 15:52:42 -0700 Subject: [PATCH] Removed ReportDispatcher support for multiple args and non-object args All reporter calls take a single argument of object type, and always have. --- lib/jasmine-core/jasmine.js | 16 ++++++++-------- spec/core/ReportDispatcherSpec.js | 30 +++++++++++++++--------------- src/core/ReportDispatcher.js | 16 ++++++++-------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 37135702..f074d174 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -8581,8 +8581,8 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { for (const method of dispatchedMethods) { this[method] = (function(m) { - return function() { - return dispatch(m, arguments); + return function(event) { + return dispatch(m, event); }; })(method); } @@ -8604,13 +8604,13 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { return this; - function dispatch(method, args) { + function dispatch(method, event) { if (reporters.length === 0 && fallbackReporter !== null) { reporters.push(fallbackReporter); } const fns = []; for (const reporter of reporters) { - addFn(fns, reporter, method, args); + addFn(fns, reporter, method, event); } return new Promise(function(resolve) { @@ -8630,23 +8630,23 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { }); } - function addFn(fns, reporter, method, args) { + function addFn(fns, reporter, method, event) { const fn = reporter[method]; if (!fn) { return; } - const thisArgs = j$.util.cloneArgs(args); + const thisEvent = j$.util.clone(event); if (fn.length <= 1) { fns.push({ fn: function() { - return fn.apply(reporter, thisArgs); + return fn.call(reporter, thisEvent); } }); } else { fns.push({ fn: function(done) { - return fn.apply(reporter, thisArgs.concat([done])); + return fn.call(reporter, thisEvent, done); } }); } diff --git a/spec/core/ReportDispatcherSpec.js b/spec/core/ReportDispatcherSpec.js index 83649a9c..5c9fe06c 100644 --- a/spec/core/ReportDispatcherSpec.js +++ b/spec/core/ReportDispatcherSpec.js @@ -23,7 +23,7 @@ describe('ReportDispatcher', function() { dispatcher.addReporter(reporter); dispatcher.addReporter(anotherReporter); - dispatcher.foo(123, 456); + dispatcher.foo({ an: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ @@ -37,16 +37,16 @@ describe('ReportDispatcher', function() { let fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); - expect(reporter.foo).toHaveBeenCalledWith(123, 456); + expect(reporter.foo).toHaveBeenCalledWith({ an: 'event' }); expect(reporter.foo.calls.mostRecent().object).toBe(reporter); fns[1].fn(); - expect(anotherReporter.foo).toHaveBeenCalledWith(123, 456); + expect(anotherReporter.foo).toHaveBeenCalledWith({ an: 'event' }); expect(anotherReporter.foo.calls.mostRecent().object).toBe(anotherReporter); runQueue.calls.reset(); - dispatcher.bar('a', 'b'); + dispatcher.bar({ another: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ @@ -60,10 +60,10 @@ describe('ReportDispatcher', function() { fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); - expect(reporter.bar).toHaveBeenCalledWith('a', 'b'); + expect(reporter.bar).toHaveBeenCalledWith({ another: 'event' }); fns[1].fn(); - expect(anotherReporter.bar).toHaveBeenCalledWith('a', 'b'); + expect(anotherReporter.bar).toHaveBeenCalledWith({ another: 'event' }); }); it("does not dispatch to a reporter if the reporter doesn't accept the method", function() { @@ -90,7 +90,7 @@ describe('ReportDispatcher', function() { reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']); dispatcher.provideFallbackReporter(reporter); - dispatcher.foo(123, 456); + dispatcher.foo({ an: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ @@ -101,7 +101,7 @@ describe('ReportDispatcher', function() { const fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); - expect(reporter.foo).toHaveBeenCalledWith(123, 456); + expect(reporter.foo).toHaveBeenCalledWith({ an: 'event' }); }); it('does not call fallback reporting methods when another reporter is provided', function() { @@ -115,7 +115,7 @@ describe('ReportDispatcher', function() { dispatcher.provideFallbackReporter(fallbackReporter); dispatcher.addReporter(reporter); - dispatcher.foo(123, 456); + dispatcher.foo({ an: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ @@ -126,8 +126,8 @@ describe('ReportDispatcher', function() { const fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); - expect(reporter.foo).toHaveBeenCalledWith(123, 456); - expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456); + expect(reporter.foo).toHaveBeenCalledWith({ an: 'event' }); + expect(fallbackReporter.foo).not.toHaveBeenCalled(); }); it('allows registered reporters to be cleared', function() { @@ -140,7 +140,7 @@ describe('ReportDispatcher', function() { reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']); dispatcher.addReporter(reporter1); - dispatcher.foo(123); + dispatcher.foo({ an: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ queueableFns: [{ fn: jasmine.any(Function) }], @@ -150,11 +150,11 @@ describe('ReportDispatcher', function() { let fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); - expect(reporter1.foo).toHaveBeenCalledWith(123); + expect(reporter1.foo).toHaveBeenCalledWith({ an: 'event' }); dispatcher.clearReporters(); dispatcher.addReporter(reporter2); - dispatcher.bar(456); + dispatcher.bar({ another: 'event' }); expect(runQueue).toHaveBeenCalledWith( jasmine.objectContaining({ @@ -166,6 +166,6 @@ describe('ReportDispatcher', function() { fns = runQueue.calls.mostRecent().args[0].queueableFns; fns[0].fn(); expect(reporter1.bar).not.toHaveBeenCalled(); - expect(reporter2.bar).toHaveBeenCalledWith(456); + expect(reporter2.bar).toHaveBeenCalledWith({ another: 'event' }); }); }); diff --git a/src/core/ReportDispatcher.js b/src/core/ReportDispatcher.js index a20c62ed..266ed899 100644 --- a/src/core/ReportDispatcher.js +++ b/src/core/ReportDispatcher.js @@ -6,8 +6,8 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { for (const method of dispatchedMethods) { this[method] = (function(m) { - return function() { - return dispatch(m, arguments); + return function(event) { + return dispatch(m, event); }; })(method); } @@ -29,13 +29,13 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { return this; - function dispatch(method, args) { + function dispatch(method, event) { if (reporters.length === 0 && fallbackReporter !== null) { reporters.push(fallbackReporter); } const fns = []; for (const reporter of reporters) { - addFn(fns, reporter, method, args); + addFn(fns, reporter, method, event); } return new Promise(function(resolve) { @@ -55,23 +55,23 @@ getJasmineRequireObj().ReportDispatcher = function(j$) { }); } - function addFn(fns, reporter, method, args) { + function addFn(fns, reporter, method, event) { const fn = reporter[method]; if (!fn) { return; } - const thisArgs = j$.util.cloneArgs(args); + const thisEvent = j$.util.clone(event); if (fn.length <= 1) { fns.push({ fn: function() { - return fn.apply(reporter, thisArgs); + return fn.call(reporter, thisEvent); } }); } else { fns.push({ fn: function(done) { - return fn.apply(reporter, thisArgs.concat([done])); + return fn.call(reporter, thisEvent, done); } }); }