Generate compiled jasmine.js for async reporters work

This commit is contained in:
Gregg Van Hove
2018-01-29 14:02:02 -08:00
parent 50cd6fdd68
commit 262a2fe674
+168 -121
View File
@@ -528,7 +528,19 @@ getJasmineRequireObj().Spec = function(j$) {
Spec.prototype.execute = function(onComplete, excluded) { Spec.prototype.execute = function(onComplete, excluded) {
var self = this; var self = this;
this.onStart(this); var onStart = {
fn: function(done) {
self.onStart(self, done);
}
};
var complete = {
fn: function(done) {
self.queueableFn.fn = null;
self.result.status = self.status(excluded);
self.resultCallback(self.result, done);
}
};
var fns = this.beforeAndAfterFns(); var fns = this.beforeAndAfterFns();
var regularFns = fns.befores.concat(this.queueableFn); var regularFns = fns.befores.concat(this.queueableFn);
@@ -537,8 +549,10 @@ getJasmineRequireObj().Spec = function(j$) {
isLeaf: true, isLeaf: true,
queueableFns: regularFns, queueableFns: regularFns,
cleanupFns: fns.afters, cleanupFns: fns.afters,
onException: function() { self.onException.apply(self, arguments); }, onException: function () {
onComplete: complete, self.onException.apply(self, arguments);
},
onComplete: onComplete,
userContext: this.userContext() userContext: this.userContext()
}; };
@@ -547,17 +561,10 @@ getJasmineRequireObj().Spec = function(j$) {
runnerConfig.cleanupFns = []; runnerConfig.cleanupFns = [];
} }
runnerConfig.queueableFns.unshift(onStart);
runnerConfig.cleanupFns.push(complete);
this.queueRunnerFactory(runnerConfig); this.queueRunnerFactory(runnerConfig);
function complete() {
self.queueableFn.fn = null;
self.result.status = self.status(excluded);
self.resultCallback(self.result);
if (onComplete) {
onComplete();
}
}
}; };
Spec.prototype.onException = function onException(e) { Spec.prototype.onException = function onException(e) {
@@ -720,59 +727,6 @@ getJasmineRequireObj().Env = function(j$) {
return currentSpec || currentSuite(); return currentSpec || currentSuite();
}; };
/**
* This represents the available reporter callback for an object passed to {@link Env#addReporter}.
* @interface Reporter
*/
var reporter = new j$.ReportDispatcher([
/**
* `jasmineStarted` is called after all of the specs have been loaded, but just before execution starts.
* @function
* @name Reporter#jasmineStarted
* @param {JasmineStartedInfo} suiteInfo Information about the full Jasmine suite that is being run
*/
'jasmineStarted',
/**
* When the entire suite has finished execution `jasmineDone` is called
* @function
* @name Reporter#jasmineDone
* @param {JasmineDoneInfo} suiteInfo Information about the full Jasmine suite that just finished running.
*/
'jasmineDone',
/**
* `suiteStarted` is invoked when a `describe` starts to run
* @function
* @name Reporter#suiteStarted
* @param {SuiteResult} result Information about the individual {@link describe} being run
*/
'suiteStarted',
/**
* `suiteDone` is invoked when all of the child specs and suites for a given suite have been run
*
* While jasmine doesn't require any specific functions, not defining a `suiteDone` will make it impossible for a reporter to know when a suite has failures in an `afterAll`.
* @function
* @name Reporter#suiteDone
* @param {SuiteResult} result
*/
'suiteDone',
/**
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
* @function
* @name Reporter#specStarted
* @param {SpecResult} result Information about the individual {@link it} being run
*/
'specStarted',
/**
* `specDone` is invoked when an `it` and its associated `beforeEach` and `afterEach` functions have been run.
*
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
* @function
* @name Reporter#specDone
* @param {SpecResult} result
*/
'specDone'
]);
var globalErrors = new j$.GlobalErrors(); var globalErrors = new j$.GlobalErrors();
globalErrors.install(); globalErrors.install();
globalErrors.pushListener(function(message, filename, lineno) { globalErrors.pushListener(function(message, filename, lineno) {
@@ -941,15 +895,18 @@ getJasmineRequireObj().Env = function(j$) {
handlingLoadErrors = false; handlingLoadErrors = false;
}; };
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options, args) {
options.catchException = catchException; options.catchException = catchException;
options.clearStack = options.clearStack || clearStack; options.clearStack = options.clearStack || clearStack;
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
options.fail = self.fail; options.fail = self.fail;
options.globalErrors = globalErrors; options.globalErrors = globalErrors;
options.completeOnFirstError = throwOnExpectationFailure && options.isLeaf; options.completeOnFirstError = throwOnExpectationFailure && options.isLeaf;
options.onException = options.onException || function(e) {
(currentRunnable() || topSuite).onException(e);
};
new j$.QueueRunner(options).execute(); new j$.QueueRunner(options).execute(args);
}; };
var topSuite = new j$.Suite({ var topSuite = new j$.Suite({
@@ -966,6 +923,59 @@ getJasmineRequireObj().Env = function(j$) {
return topSuite; return topSuite;
}; };
/**
* This represents the available reporter callback for an object passed to {@link Env#addReporter}.
* @interface Reporter
*/
var reporter = new j$.ReportDispatcher([
/**
* `jasmineStarted` is called after all of the specs have been loaded, but just before execution starts.
* @function
* @name Reporter#jasmineStarted
* @param {JasmineStartedInfo} suiteInfo Information about the full Jasmine suite that is being run
*/
'jasmineStarted',
/**
* When the entire suite has finished execution `jasmineDone` is called
* @function
* @name Reporter#jasmineDone
* @param {JasmineDoneInfo} suiteInfo Information about the full Jasmine suite that just finished running.
*/
'jasmineDone',
/**
* `suiteStarted` is invoked when a `describe` starts to run
* @function
* @name Reporter#suiteStarted
* @param {SuiteResult} result Information about the individual {@link describe} being run
*/
'suiteStarted',
/**
* `suiteDone` is invoked when all of the child specs and suites for a given suite have been run
*
* While jasmine doesn't require any specific functions, not defining a `suiteDone` will make it impossible for a reporter to know when a suite has failures in an `afterAll`.
* @function
* @name Reporter#suiteDone
* @param {SuiteResult} result
*/
'suiteDone',
/**
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
* @function
* @name Reporter#specStarted
* @param {SpecResult} result Information about the individual {@link it} being run
*/
'specStarted',
/**
* `specDone` is invoked when an `it` and its associated `beforeEach` and `afterEach` functions have been run.
*
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
* @function
* @name Reporter#specDone
* @param {SpecResult} result
*/
'specDone'
], queueRunnerFactory);
this.execute = function(runnablesToRun) { this.execute = function(runnablesToRun) {
var self = this; var self = this;
this.suppressLoadErrors(); this.suppressLoadErrors();
@@ -987,23 +997,24 @@ getJasmineRequireObj().Env = function(j$) {
tree: topSuite, tree: topSuite,
runnableIds: runnablesToRun, runnableIds: runnablesToRun,
queueRunnerFactory: queueRunnerFactory, queueRunnerFactory: queueRunnerFactory,
nodeStart: function(suite) { nodeStart: function(suite, next) {
currentlyExecutingSuites.push(suite); currentlyExecutingSuites.push(suite);
defaultResourcesForRunnable(suite.id, suite.parentSuite.id); defaultResourcesForRunnable(suite.id, suite.parentSuite.id);
reporter.suiteStarted(suite.result); reporter.suiteStarted(suite.result, next);
}, },
nodeComplete: function(suite, result) { nodeComplete: function(suite, result, next) {
if (suite !== currentSuite()) { if (suite !== currentSuite()) {
throw new Error('Tried to complete the wrong suite'); throw new Error('Tried to complete the wrong suite');
} }
clearResourcesForRunnable(suite.id); clearResourcesForRunnable(suite.id);
currentlyExecutingSuites.pop(); currentlyExecutingSuites.pop();
reporter.suiteDone(result);
if (result.status === 'failed') { if (result.status === 'failed') {
hasFailures = true; hasFailures = true;
} }
reporter.suiteDone(result, next);
}, },
orderChildren: function(node) { orderChildren: function(node) {
return order.sort(node.children); return order.sort(node.children);
@@ -1026,40 +1037,40 @@ getJasmineRequireObj().Env = function(j$) {
reporter.jasmineStarted({ reporter.jasmineStarted({
totalSpecsDefined: totalSpecsDefined, totalSpecsDefined: totalSpecsDefined,
order: order order: order
}); }, function() {
currentlyExecutingSuites.push(topSuite);
currentlyExecutingSuites.push(topSuite); processor.execute(function () {
clearResourcesForRunnable(topSuite.id);
currentlyExecutingSuites.pop();
var overallStatus, incompleteReason;
processor.execute(function() { if (hasFailures || topSuite.result.failedExpectations.length > 0) {
clearResourcesForRunnable(topSuite.id); overallStatus = 'failed';
currentlyExecutingSuites.pop(); } else if (focusedRunnables.length > 0) {
var overallStatus, incompleteReason; overallStatus = 'incomplete';
incompleteReason = 'fit() or fdescribe() was found';
} else if (totalSpecsDefined === 0) {
overallStatus = 'incomplete';
incompleteReason = 'No specs found';
} else {
overallStatus = 'passed';
}
if (hasFailures || topSuite.result.failedExpectations.length > 0) { /**
overallStatus = 'failed'; * Information passed to the {@link Reporter#jasmineDone} event.
} else if (focusedRunnables.length > 0) { * @typedef JasmineDoneInfo
overallStatus = 'incomplete'; * @property {OverallStatus} - The overall result of the sute: 'passed', 'failed', or 'incomplete'.
incompleteReason = 'fit() or fdescribe() was found'; * @property {IncompleteReason} - Explanation of why the suite was incimplete.
} else if (totalSpecsDefined === 0) { * @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
overallStatus = 'incomplete'; * @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
incompleteReason = 'No specs found'; */
} else { reporter.jasmineDone({
overallStatus = 'passed'; overallStatus: overallStatus,
} incompleteReason: incompleteReason,
order: order,
/** failedExpectations: topSuite.result.failedExpectations
* Information passed to the {@link Reporter#jasmineDone} event. }, function() {});
* @typedef JasmineDoneInfo
* @property {OverallStatus} - The overall result of the sute: 'passed', 'failed', or 'incomplete'.
* @property {IncompleteReason} - Explanation of why the suite was incimplete.
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
*/
reporter.jasmineDone({
overallStatus: overallStatus,
incompleteReason: incompleteReason,
order: order,
failedExpectations: topSuite.result.failedExpectations
}); });
}); });
}; };
@@ -1262,20 +1273,21 @@ getJasmineRequireObj().Env = function(j$) {
return spec; return spec;
function specResultCallback(result) { function specResultCallback(result, next) {
clearResourcesForRunnable(spec.id); clearResourcesForRunnable(spec.id);
currentSpec = null; currentSpec = null;
reporter.specDone(result);
if (result.status === 'failed') { if (result.status === 'failed') {
hasFailures = true; hasFailures = true;
} }
reporter.specDone(result, next);
} }
function specStarted(spec) { function specStarted(spec, next) {
currentSpec = spec; currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id); defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result); reporter.specStarted(spec.result, next);
} }
}; };
@@ -4460,6 +4472,10 @@ getJasmineRequireObj().QueueRunner = function(j$) {
this.fail = attrs.fail || function() {}; this.fail = attrs.fail || function() {};
this.globalErrors = attrs.globalErrors || { pushListener: function() {}, popListener: function() {} }; this.globalErrors = attrs.globalErrors || { pushListener: function() {}, popListener: function() {} };
this.completeOnFirstError = !!attrs.completeOnFirstError; this.completeOnFirstError = !!attrs.completeOnFirstError;
if (typeof(this.onComplete) !== 'function') {
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
}
} }
QueueRunner.prototype.execute = function() { QueueRunner.prototype.execute = function() {
@@ -4489,15 +4505,15 @@ getJasmineRequireObj().QueueRunner = function(j$) {
QueueRunner.prototype.attempt = function attempt(iterativeIndex) { QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
var self = this, completedSynchronously = true, var self = this, completedSynchronously = true,
handleError = function(error) { handleError = function handleError(error) {
onException(error); onException(error);
next(); next();
}, },
cleanup = once(function() { cleanup = once(function cleanup() {
self.clearTimeout(timeoutId); self.clearTimeout(timeoutId);
self.globalErrors.popListener(handleError); self.globalErrors.popListener(handleError);
}), }),
next = once(function () { next = once(function next() {
cleanup(); cleanup();
function runNext() { function runNext() {
@@ -4518,7 +4534,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
queueableFn = self.queueableFns[iterativeIndex], queueableFn = self.queueableFns[iterativeIndex],
timeoutId; timeoutId;
next.fail = function() { next.fail = function nextFail() {
self.fail.apply(null, arguments); self.fail.apply(null, arguments);
errored = true; errored = true;
next(); next();
@@ -4606,7 +4622,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}; };
getJasmineRequireObj().ReportDispatcher = function(j$) { getJasmineRequireObj().ReportDispatcher = function(j$) {
function ReportDispatcher(methods) { function ReportDispatcher(methods, queueRunnerFactory) {
var dispatchedMethods = methods || []; var dispatchedMethods = methods || [];
@@ -4640,11 +4656,39 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
if (reporters.length === 0 && fallbackReporter !== null) { if (reporters.length === 0 && fallbackReporter !== null) {
reporters.push(fallbackReporter); reporters.push(fallbackReporter);
} }
var onComplete = args[args.length - 1];
args = j$.util.argsToArray(args).splice(0, args.length - 1);
var fns = [];
for (var i = 0; i < reporters.length; i++) { for (var i = 0; i < reporters.length; i++) {
var reporter = reporters[i]; var reporter = reporters[i];
if (reporter[method]) { addFn(fns, reporter, method, args);
reporter[method].apply(reporter, j$.util.cloneArgs(args)); }
}
queueRunnerFactory({
queueableFns: fns,
onComplete: onComplete
});
}
function addFn(fns, reporter, method, args) {
var fn = reporter[method];
if (!fn) {
return;
}
var thisArgs = j$.util.cloneArgs(args);
if (fn.length <= 1) {
fns.push({
fn: function () {
return fn.apply(reporter, thisArgs);
}
});
} else {
fns.push({
fn: function (done) {
return fn.apply(reporter, thisArgs.concat([done]));
}
});
} }
} }
} }
@@ -5857,17 +5901,20 @@ getJasmineRequireObj().TreeProcessor = function() {
if (node.children) { if (node.children) {
return { return {
fn: function(done) { fn: function(done) {
nodeStart(node); var onStart = {
fn: function(next) {
nodeStart(node, next);
}
};
queueRunnerFactory({ queueRunnerFactory({
onComplete: function() { onComplete: function () {
node.cleanupBeforeAfter(); node.cleanupBeforeAfter();
nodeComplete(node, node.getResult()); nodeComplete(node, node.getResult(), done);
done();
}, },
queueableFns: wrapChildren(node, segmentNumber), queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
userContext: node.sharedUserContext(), userContext: node.sharedUserContext(),
onException: function() { onException: function () {
node.onException.apply(node, arguments); node.onException.apply(node, arguments);
} }
}); });