dwf: refactoring how reporters work to add callbacks at all levels, separating how/when DOM writing works;
This commit is contained in:
@@ -18,11 +18,14 @@ if (typeof Function.method !== 'function') {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Jasmine internal classes & objects
|
||||
*/
|
||||
|
||||
/*
|
||||
* object for holding results; allows for the results array to hold another nestedResults()
|
||||
*
|
||||
*/
|
||||
|
||||
var nestedResults = function() {
|
||||
var that = {
|
||||
totalCount: 0,
|
||||
@@ -121,6 +124,30 @@ var actionCollection = function () {
|
||||
return that;
|
||||
}
|
||||
|
||||
/*
|
||||
* queuedFunction is how actionCollection's actions are implemented
|
||||
*/
|
||||
var queuedFunction = function(func, timeout, spec) {
|
||||
var that = {
|
||||
func: func,
|
||||
next: function () {
|
||||
spec.finish(); // default value is to be done after one function
|
||||
},
|
||||
execute: function () {
|
||||
if (timeout > 0) {
|
||||
setTimeout(function () {
|
||||
that.func.apply(spec);
|
||||
that.next();
|
||||
}, timeout);
|
||||
} else {
|
||||
that.func.apply(spec);
|
||||
that.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
return that;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Jasmine
|
||||
******************************************************************************/
|
||||
@@ -159,27 +186,6 @@ Matchers.method('should_not_equal', function (expected) {
|
||||
* Jasmine spec constructor
|
||||
*/
|
||||
|
||||
var queuedFunction = function(func, timeout, spec) {
|
||||
var that = {
|
||||
func: func,
|
||||
next: function () {
|
||||
spec.finish(); // default value is to be done after one function
|
||||
},
|
||||
execute: function () {
|
||||
if (timeout > 0) {
|
||||
setTimeout(function () {
|
||||
that.func.apply(spec);
|
||||
that.next();
|
||||
}, timeout);
|
||||
} else {
|
||||
that.func.apply(spec);
|
||||
that.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
return that;
|
||||
}
|
||||
|
||||
var it = function (description, func) {
|
||||
var that = {
|
||||
description: description,
|
||||
@@ -302,39 +308,28 @@ var Runner = function () {
|
||||
return that;
|
||||
}
|
||||
|
||||
var JasmineReporters = {};
|
||||
|
||||
var Jasmine = Runner();
|
||||
var currentSuite;
|
||||
var currentSpec;
|
||||
|
||||
JasmineReporters.reporter = function (elementId) {
|
||||
/* JasmineReporters.reporter
|
||||
* Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to
|
||||
* descendants of this object to do something with the results (see json_reporter.js)
|
||||
*/
|
||||
var JasmineReporters = {};
|
||||
|
||||
JasmineReporters.reporter = function (callbacks) {
|
||||
var that = {
|
||||
element: document.getElementById(elementId),
|
||||
output: '',
|
||||
callbacks: callbacks || {},
|
||||
|
||||
reportRunnerResults: function (results) { that.output += ''; },
|
||||
doCallback: function (callback, results) {
|
||||
if (callback) { callback(results); }
|
||||
},
|
||||
|
||||
reportSuiteResults: function (results) { that.output += ''; },
|
||||
|
||||
reportSpecResults: function (results) { that.output += ''; },
|
||||
|
||||
}
|
||||
|
||||
// TODO: throw if no element?
|
||||
if (that.element) {
|
||||
that.element.innerHTML = '';
|
||||
reportRunnerResults: function (results) { that.doCallback(that.callbacks.runnerCallback, results); },
|
||||
reportSuiteResults: function (results) { that.doCallback(that.callbacks.suiteCallback, results); },
|
||||
reportSpecResults: function (results) { that.doCallback(that.callbacks.specCallback, results);}
|
||||
}
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - HTML reporter
|
||||
* - Shows pass/fail progress (just like bootstrap reporter)
|
||||
* - Lists a Summary: total # specs, # of passed, # of failed
|
||||
* - Failed reports lists all specs that failed and what the failure was
|
||||
* - Failed output is styled with red
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -1,27 +1,73 @@
|
||||
JasmineReporters.JSON = function (elementId) {
|
||||
var that = JasmineReporters.reporter(elementId);
|
||||
/*
|
||||
* JasmineReporters.JSON --
|
||||
* Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner
|
||||
* result. Calling application can then do whatever it wants/needs with the string;
|
||||
*/
|
||||
JasmineReporters.JSON = function () {
|
||||
var that = JasmineReporters.reporter();
|
||||
that.specJSON = '';
|
||||
that.suiteJSON = '';
|
||||
that.runnerJSON = '';
|
||||
|
||||
that.reportRunnerResults = function (results) {
|
||||
that.output = Object.toJSON(results);
|
||||
var saveSpecResults = function (results) {
|
||||
that.specJSON = Object.toJSON(results);
|
||||
}
|
||||
that.reportSpecResults = saveSpecResults;
|
||||
|
||||
if (that.element) {
|
||||
that.element.innerHTML += that.output;
|
||||
}
|
||||
}
|
||||
var saveSuiteResults = function (results) {
|
||||
that.suiteJSON = Object.toJSON(results);
|
||||
}
|
||||
that.reportSuiteResults = saveSuiteResults;
|
||||
|
||||
var saveRunnerResults = function (results) {
|
||||
that.runnerJSON = Object.toJSON(results);
|
||||
}
|
||||
that.reportRunnerResults = saveRunnerResults;
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
JasmineReporters.IncrementalJSON = function (elementId) {
|
||||
var that = JasmineReporters.reporter(elementId);
|
||||
var domWriter = function (elementId) {
|
||||
var that = {
|
||||
element: document.getElementById(elementId),
|
||||
|
||||
that.reportSpecResults = function (results) {
|
||||
that.output = Object.toJSON(results);
|
||||
if (that.element) {
|
||||
that.element.innerHTML += that.output;
|
||||
write: function (text) {
|
||||
if (that.element) {
|
||||
that.element.innerHTML += text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
that.element.innerHTML = '';
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
JasmineReporters.JSONtoDOM = function (elementId) {
|
||||
var that = JasmineReporters.JSON();
|
||||
|
||||
that.domWriter = domWriter(elementId);
|
||||
|
||||
var writeRunnerResults = function (results) {
|
||||
that.domWriter.write(Object.toJSON(results));
|
||||
};
|
||||
|
||||
that.reportRunnerResults = writeRunnerResults;
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
|
||||
//JasmineReporters.IncrementalJSON = function (elementId) {
|
||||
// var that = JasmineReporters.reporter(elementId);
|
||||
//
|
||||
// that.reportSpecResults = function (results) {
|
||||
// that.output = Object.toJSON(results);
|
||||
// if (that.element) {
|
||||
// that.element.innerHTML += that.output;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return that;
|
||||
//}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user