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:
@@ -7966,42 +7966,43 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* Jasmine specs run in. Doing so will break Jasmine's error handling.
|
* 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
|
* @param onError {function} Function called when an unhandled exception, unhandled promise rejection, or explicit reporter failure occurs
|
||||||
*/
|
*/
|
||||||
function ParallelReportDispatcher(onError, deps = {}) {
|
class ParallelReportDispatcher {
|
||||||
const ReportDispatcher = deps.ReportDispatcher || private$.ReportDispatcher;
|
constructor(onError, deps = {}) {
|
||||||
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
|
const ReportDispatcher =
|
||||||
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
|
deps.ReportDispatcher || private$.ReportDispatcher;
|
||||||
const dispatcher = new ReportDispatcher(
|
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
|
||||||
private$.reporterEvents,
|
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
|
||||||
function(queueRunnerOptions) {
|
const dispatcher = new ReportDispatcher(
|
||||||
queueRunnerOptions = {
|
private$.reporterEvents,
|
||||||
...queueRunnerOptions,
|
function(queueRunnerOptions) {
|
||||||
globalErrors,
|
queueRunnerOptions = {
|
||||||
timeout: { setTimeout, clearTimeout },
|
...queueRunnerOptions,
|
||||||
fail: function(error) {
|
globalErrors,
|
||||||
// A callback-style async reporter called either done.fail()
|
timeout: { setTimeout, clearTimeout },
|
||||||
// or done(anError).
|
fail: function(error) {
|
||||||
if (!error) {
|
// A callback-style async reporter called either done.fail()
|
||||||
error = new Error('A reporter called 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.
|
* Adds a reporter to the list of reporters that events will be dispatched to.
|
||||||
* @function
|
* @function
|
||||||
@@ -8009,13 +8010,13 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* @param {Reporter} reporterToAdd The reporter to be added.
|
* @param {Reporter} reporterToAdd The reporter to be added.
|
||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
addReporter: dispatcher.addReporter.bind(dispatcher),
|
this.addReporter = dispatcher.addReporter.bind(dispatcher);
|
||||||
/**
|
/**
|
||||||
* Clears all registered reporters.
|
* Clears all registered reporters.
|
||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#clearReporters
|
* @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
|
* Installs a global error handler. After this method is called, any
|
||||||
* unhandled exceptions or unhandled promise rejections will be passed to
|
* unhandled exceptions or unhandled promise rejections will be passed to
|
||||||
@@ -8023,23 +8024,21 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#installGlobalErrors
|
* @name ParallelReportDispatcher#installGlobalErrors
|
||||||
*/
|
*/
|
||||||
installGlobalErrors: globalErrors.install.bind(globalErrors),
|
this.installGlobalErrors = globalErrors.install.bind(globalErrors);
|
||||||
/**
|
/**
|
||||||
* Uninstalls the global error handler.
|
* Uninstalls the global error handler.
|
||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#uninstallGlobalErrors
|
* @name ParallelReportDispatcher#uninstallGlobalErrors
|
||||||
*/
|
*/
|
||||||
uninstallGlobalErrors: function() {
|
this.uninstallGlobalErrors = function() {
|
||||||
// late-bind uninstall because it doesn't exist until install is called
|
// late-bind uninstall because it doesn't exist until install is called
|
||||||
globalErrors.uninstall(globalErrors);
|
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;
|
return ParallelReportDispatcher;
|
||||||
|
|||||||
@@ -15,42 +15,43 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* Jasmine specs run in. Doing so will break Jasmine's error handling.
|
* 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
|
* @param onError {function} Function called when an unhandled exception, unhandled promise rejection, or explicit reporter failure occurs
|
||||||
*/
|
*/
|
||||||
function ParallelReportDispatcher(onError, deps = {}) {
|
class ParallelReportDispatcher {
|
||||||
const ReportDispatcher = deps.ReportDispatcher || private$.ReportDispatcher;
|
constructor(onError, deps = {}) {
|
||||||
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
|
const ReportDispatcher =
|
||||||
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
|
deps.ReportDispatcher || private$.ReportDispatcher;
|
||||||
const dispatcher = new ReportDispatcher(
|
const QueueRunner = deps.QueueRunner || private$.QueueRunner;
|
||||||
private$.reporterEvents,
|
const globalErrors = deps.globalErrors || new private$.GlobalErrors();
|
||||||
function(queueRunnerOptions) {
|
const dispatcher = new ReportDispatcher(
|
||||||
queueRunnerOptions = {
|
private$.reporterEvents,
|
||||||
...queueRunnerOptions,
|
function(queueRunnerOptions) {
|
||||||
globalErrors,
|
queueRunnerOptions = {
|
||||||
timeout: { setTimeout, clearTimeout },
|
...queueRunnerOptions,
|
||||||
fail: function(error) {
|
globalErrors,
|
||||||
// A callback-style async reporter called either done.fail()
|
timeout: { setTimeout, clearTimeout },
|
||||||
// or done(anError).
|
fail: function(error) {
|
||||||
if (!error) {
|
// A callback-style async reporter called either done.fail()
|
||||||
error = new Error('A reporter called 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.
|
* Adds a reporter to the list of reporters that events will be dispatched to.
|
||||||
* @function
|
* @function
|
||||||
@@ -58,13 +59,13 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* @param {Reporter} reporterToAdd The reporter to be added.
|
* @param {Reporter} reporterToAdd The reporter to be added.
|
||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
addReporter: dispatcher.addReporter.bind(dispatcher),
|
this.addReporter = dispatcher.addReporter.bind(dispatcher);
|
||||||
/**
|
/**
|
||||||
* Clears all registered reporters.
|
* Clears all registered reporters.
|
||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#clearReporters
|
* @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
|
* Installs a global error handler. After this method is called, any
|
||||||
* unhandled exceptions or unhandled promise rejections will be passed to
|
* unhandled exceptions or unhandled promise rejections will be passed to
|
||||||
@@ -72,23 +73,21 @@ getJasmineRequireObj().ParallelReportDispatcher = function(j$, private$) {
|
|||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#installGlobalErrors
|
* @name ParallelReportDispatcher#installGlobalErrors
|
||||||
*/
|
*/
|
||||||
installGlobalErrors: globalErrors.install.bind(globalErrors),
|
this.installGlobalErrors = globalErrors.install.bind(globalErrors);
|
||||||
/**
|
/**
|
||||||
* Uninstalls the global error handler.
|
* Uninstalls the global error handler.
|
||||||
* @function
|
* @function
|
||||||
* @name ParallelReportDispatcher#uninstallGlobalErrors
|
* @name ParallelReportDispatcher#uninstallGlobalErrors
|
||||||
*/
|
*/
|
||||||
uninstallGlobalErrors: function() {
|
this.uninstallGlobalErrors = function() {
|
||||||
// late-bind uninstall because it doesn't exist until install is called
|
// late-bind uninstall because it doesn't exist until install is called
|
||||||
globalErrors.uninstall(globalErrors);
|
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;
|
return ParallelReportDispatcher;
|
||||||
|
|||||||
Reference in New Issue
Block a user