Convert ParallelReportDispatcher to an ES6 class

ParallelReportDispatcher itself doesn't gain anything from this, but
it'll allow monkey patching prevention to be implemented and tested
more uniformly.
This commit is contained in:
Steve Gravrock
2026-02-16 11:14:13 -08:00
parent 8bb325628f
commit 281c0d1ee8
2 changed files with 86 additions and 88 deletions

View File

@@ -7966,42 +7966,43 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* Jasmine specs run in. Doing so will break Jasmine's error handling.
* @param onError {function} Function called when an unhandled exception, unhandled promise rejection, or explicit reporter failure occurs
*/
function ParallelReportDispatcher(onError, deps = {}) {
const ReportDispatcher = deps.ReportDispatcher || private$.ReportDispatcher;
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
const dispatcher = new ReportDispatcher(
private$.reporterEvents,
function(queueRunnerOptions) {
queueRunnerOptions = {
...queueRunnerOptions,
globalErrors,
timeout: { setTimeout, clearTimeout },
fail: function(error) {
// A callback-style async reporter called either done.fail()
// or done(anError).
if (!error) {
error = new Error('A reporter called done.fail()');
class ParallelReportDispatcher {
constructor(onError, deps = {}) {
const ReportDispatcher =
deps.ReportDispatcher || private$.ReportDispatcher;
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
const dispatcher = new ReportDispatcher(
private$.reporterEvents,
function(queueRunnerOptions) {
queueRunnerOptions = {
...queueRunnerOptions,
globalErrors,
timeout: { setTimeout, clearTimeout },
fail: function(error) {
// A callback-style async reporter called either done.fail()
// or done(anError).
if (!error) {
error = new Error('A reporter called done.fail()');
}
onError(error);
},
onException: function(error) {
// A reporter method threw an exception or returned a rejected
// promise, or there was an unhandled exception or unhandled promise
// rejection while an asynchronous reporter method was running.
onError(error);
}
};
new QueueRunner(queueRunnerOptions).execute();
},
function(error) {
// A reporter called done() more than once.
onError(error);
}
);
onError(error);
},
onException: function(error) {
// A reporter method threw an exception or returned a rejected
// promise, or there was an unhandled exception or unhandled promise
// rejection while an asynchronous reporter method was running.
onError(error);
}
};
new QueueRunner(queueRunnerOptions).execute();
},
function(error) {
// A reporter called done() more than once.
onError(error);
}
);
const self = {
/**
* Adds a reporter to the list of reporters that events will be dispatched to.
* @function
@@ -8009,13 +8010,13 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* @param {Reporter} reporterToAdd The reporter to be added.
* @see custom_reporter
*/
addReporter: dispatcher.addReporter.bind(dispatcher),
this.addReporter = dispatcher.addReporter.bind(dispatcher);
/**
* Clears all registered reporters.
* @function
* @name ParallelReportDispatcher#clearReporters
*/
clearReporters: dispatcher.clearReporters.bind(dispatcher),
this.clearReporters = dispatcher.clearReporters.bind(dispatcher);
/**
* Installs a global error handler. After this method is called, any
* unhandled exceptions or unhandled promise rejections will be passed to
@@ -8023,23 +8024,21 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* @function
* @name ParallelReportDispatcher#installGlobalErrors
*/
installGlobalErrors: globalErrors.install.bind(globalErrors),
this.installGlobalErrors = globalErrors.install.bind(globalErrors);
/**
* Uninstalls the global error handler.
* @function
* @name ParallelReportDispatcher#uninstallGlobalErrors
*/
uninstallGlobalErrors: function() {
this.uninstallGlobalErrors = function() {
// late-bind uninstall because it doesn't exist until install is called
globalErrors.uninstall(globalErrors);
};
for (const eventName of private$.reporterEvents) {
this[eventName] = dispatcher[eventName].bind(dispatcher);
}
};
for (const eventName of private$.reporterEvents) {
self[eventName] = dispatcher[eventName].bind(dispatcher);
}
return self;
}
return ParallelReportDispatcher;

View File

@@ -15,42 +15,43 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* Jasmine specs run in. Doing so will break Jasmine's error handling.
* @param onError {function} Function called when an unhandled exception, unhandled promise rejection, or explicit reporter failure occurs
*/
function ParallelReportDispatcher(onError, deps = {}) {
const ReportDispatcher = deps.ReportDispatcher || private$.ReportDispatcher;
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
const dispatcher = new ReportDispatcher(
private$.reporterEvents,
function(queueRunnerOptions) {
queueRunnerOptions = {
...queueRunnerOptions,
globalErrors,
timeout: { setTimeout, clearTimeout },
fail: function(error) {
// A callback-style async reporter called either done.fail()
// or done(anError).
if (!error) {
error = new Error('A reporter called done.fail()');
class ParallelReportDispatcher {
constructor(onError, deps = {}) {
const ReportDispatcher =
deps.ReportDispatcher || private$.ReportDispatcher;
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
const dispatcher = new ReportDispatcher(
private$.reporterEvents,
function(queueRunnerOptions) {
queueRunnerOptions = {
...queueRunnerOptions,
globalErrors,
timeout: { setTimeout, clearTimeout },
fail: function(error) {
// A callback-style async reporter called either done.fail()
// or done(anError).
if (!error) {
error = new Error('A reporter called done.fail()');
}
onError(error);
},
onException: function(error) {
// A reporter method threw an exception or returned a rejected
// promise, or there was an unhandled exception or unhandled promise
// rejection while an asynchronous reporter method was running.
onError(error);
}
};
new QueueRunner(queueRunnerOptions).execute();
},
function(error) {
// A reporter called done() more than once.
onError(error);
}
);
onError(error);
},
onException: function(error) {
// A reporter method threw an exception or returned a rejected
// promise, or there was an unhandled exception or unhandled promise
// rejection while an asynchronous reporter method was running.
onError(error);
}
};
new QueueRunner(queueRunnerOptions).execute();
},
function(error) {
// A reporter called done() more than once.
onError(error);
}
);
const self = {
/**
* Adds a reporter to the list of reporters that events will be dispatched to.
* @function
@@ -58,13 +59,13 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* @param {Reporter} reporterToAdd The reporter to be added.
* @see custom_reporter
*/
addReporter: dispatcher.addReporter.bind(dispatcher),
this.addReporter = dispatcher.addReporter.bind(dispatcher);
/**
* Clears all registered reporters.
* @function
* @name ParallelReportDispatcher#clearReporters
*/
clearReporters: dispatcher.clearReporters.bind(dispatcher),
this.clearReporters = dispatcher.clearReporters.bind(dispatcher);
/**
* Installs a global error handler. After this method is called, any
* unhandled exceptions or unhandled promise rejections will be passed to
@@ -72,23 +73,21 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
* @function
* @name ParallelReportDispatcher#installGlobalErrors
*/
installGlobalErrors: globalErrors.install.bind(globalErrors),
this.installGlobalErrors = globalErrors.install.bind(globalErrors);
/**
* Uninstalls the global error handler.
* @function
* @name ParallelReportDispatcher#uninstallGlobalErrors
*/
uninstallGlobalErrors: function() {
this.uninstallGlobalErrors = function() {
// late-bind uninstall because it doesn't exist until install is called
globalErrors.uninstall(globalErrors);
};
for (const eventName of private$.reporterEvents) {
this[eventName] = dispatcher[eventName].bind(dispatcher);
}
};
for (const eventName of private$.reporterEvents) {
self[eventName] = dispatcher[eventName].bind(dispatcher);
}
return self;
}
return ParallelReportDispatcher;