diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 14f07851..95b3d2d7 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -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; diff --git a/src/core/ParallelReportDispatcher.js b/src/core/ParallelReportDispatcher.js index e47f3e2d..360478d6 100644 --- a/src/core/ParallelReportDispatcher.js +++ b/src/core/ParallelReportDispatcher.js @@ -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;