Removed ReportDispatcher support for multiple args and non-object args

All reporter calls take a single argument of object type, and always have.
This commit is contained in:
Steve Gravrock
2025-09-20 15:52:42 -07:00
parent ee696cbbf6
commit 7aaa16f576
3 changed files with 31 additions and 31 deletions

View File

@@ -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);
}
});
}

View File

@@ -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' });
});
});

View File

@@ -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);
}
});
}