* Top level private APIs (e.g. jasmine.private.whatever) are no longer exposed * jasmineRequire is no longer exposed * core is self-booting * Globals are automatically created in browsers. (They can subsequently be removed by user code if desired.) * Globals are *not* automatically created in Node. An installGlobals function is exported instead. The jasmine package calls installGlobals unless configured not to do so. * In Node, the same instance is returned each time jasmine-core is imported. A reset function is exported. It effectively resets all state by discarding the env and creating a new one. This allows mulitple sequential runs within the same process to be independent of each other, but does not allow multiple concurrent runs. (That probably never worked anyway.) Fixes #2094
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
getJasmineRequireObj().ReportDispatcher = function(j$, private$) {
|
|
'use strict';
|
|
|
|
function ReportDispatcher(methods, runQueue, onLateError) {
|
|
const dispatchedMethods = methods || [];
|
|
|
|
for (const method of dispatchedMethods) {
|
|
this[method] = (function(m) {
|
|
return function(event) {
|
|
return dispatch(m, event);
|
|
};
|
|
})(method);
|
|
}
|
|
|
|
let reporters = [];
|
|
let fallbackReporter = null;
|
|
|
|
this.addReporter = function(reporter) {
|
|
reporters.push(reporter);
|
|
};
|
|
|
|
this.provideFallbackReporter = function(reporter) {
|
|
fallbackReporter = reporter;
|
|
};
|
|
|
|
this.clearReporters = function() {
|
|
reporters = [];
|
|
};
|
|
|
|
return this;
|
|
|
|
function dispatch(method, event) {
|
|
if (reporters.length === 0 && fallbackReporter !== null) {
|
|
reporters.push(fallbackReporter);
|
|
}
|
|
const fns = [];
|
|
for (const reporter of reporters) {
|
|
addFn(fns, reporter, method, event);
|
|
}
|
|
|
|
return new Promise(function(resolve) {
|
|
runQueue({
|
|
queueableFns: fns,
|
|
onComplete: resolve,
|
|
isReporter: true,
|
|
onMultipleDone: function() {
|
|
onLateError(
|
|
new Error(
|
|
"An asynchronous reporter callback called its 'done' callback " +
|
|
'more than once.'
|
|
)
|
|
);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function addFn(fns, reporter, method, event) {
|
|
const fn = reporter[method];
|
|
if (!fn) {
|
|
return;
|
|
}
|
|
|
|
const thisEvent = structuredClone(event);
|
|
if (fn.length <= 1) {
|
|
fns.push({
|
|
fn: function() {
|
|
return fn.call(reporter, thisEvent);
|
|
}
|
|
});
|
|
} else {
|
|
fns.push({
|
|
fn: function(done) {
|
|
return fn.call(reporter, thisEvent, done);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return ReportDispatcher;
|
|
};
|