dwf: refactoring how reporters work to add callbacks at all levels, separating how/when DOM writing works;

This commit is contained in:
pivotal 2008-12-08 11:35:10 -08:00
parent 1450eb5b65
commit b8a8dc4562
5 changed files with 288 additions and 199 deletions

View File

@ -2,7 +2,7 @@
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Tests</title>
<title>Jasmine Example</title>
<script type="text/javascript" src="../lib/jasmine.js"></script>
<script type="text/javascript" src="example.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/jasmine.css"/>

View File

@ -80,7 +80,7 @@
<file leaf-file-name="bootstrap.html" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="29" column="63" selection-start="1054" selection-end="1054" vertical-scroll-proportion="0.5709845">
<state line="10" column="7" selection-start="500" selection-end="500" vertical-scroll-proportion="0.19689119">
<folding />
</state>
</provider>
@ -92,7 +92,7 @@
<file leaf-file-name="json_reporter.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor">
<state line="22" column="3" selection-start="581" selection-end="581" vertical-scroll-proportion="0.40425533">
<state line="6" column="36" selection-start="284" selection-end="284" vertical-scroll-proportion="0.11025145">
<folding />
</state>
</provider>
@ -101,16 +101,16 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="693" column="63" selection-start="20819" selection-end="20819" vertical-scroll-proportion="0.55937195">
<state line="53" column="39" selection-start="1542" selection-end="1542" vertical-scroll-proportion="0.5166163">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="320" column="0" selection-start="6758" selection-end="6758" vertical-scroll-proportion="0.58531743">
<state line="198" column="17" selection-start="4329" selection-end="4329" vertical-scroll-proportion="0.7901354">
<folding />
</state>
</provider>
@ -119,7 +119,7 @@
<file leaf-file-name="example.html" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/example.html">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="7" selection-start="355" selection-end="355" vertical-scroll-proportion="0.15751295">
<state line="4" column="24" selection-start="145" selection-end="145" vertical-scroll-proportion="0.078756474">
<folding />
</state>
</provider>
@ -137,7 +137,7 @@
</provider>
</entry>
</file>
<file leaf-file-name="example.js" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="example.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/example.js">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11025145">
@ -305,6 +305,40 @@
<RUBY_DOC NAME="NUMBER" VALUE="0" />
</component>
<component name="RunManager">
<configuration default="true" type="RubyRunConfigurationType" factoryName="Ruby test">
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_CLASS_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_METHOD_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift)" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="MODULE_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="INHERITANCE_CHECK_DISABLED" VALUE="false" />
</configuration>
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
</configuration>
<configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@ -324,40 +358,6 @@
</option>
<envs />
</configuration>
<configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
</configuration>
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
</configuration>
<configuration default="true" type="RubyRunConfigurationType" factoryName="Ruby test">
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_CLASS_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_METHOD_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift)" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="MODULE_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="INHERITANCE_CHECK_DISABLED" VALUE="false" />
</configuration>
<configuration default="true" type="Applet" factoryName="Applet">
<module name="" />
<option name="MAIN_CLASS_NAME" />
@ -507,26 +507,6 @@
</GetOptions>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="29" column="63" selection-start="1054" selection-end="1054" vertical-scroll-proportion="0.5709845">
<folding />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/example.html">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="7" selection-start="355" selection-end="355" vertical-scroll-proportion="0.15751295">
<folding />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor">
<state line="16" column="8" selection-start="315" selection-end="315" vertical-scroll-proportion="0.29400387">
@ -534,27 +514,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="320" column="0" selection-start="6758" selection-end="6758" vertical-scroll-proportion="0.58531743">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor">
<state line="22" column="3" selection-start="581" selection-end="581" vertical-scroll-proportion="0.40425533">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="693" column="63" selection-start="20819" selection-end="20819" vertical-scroll-proportion="0.55937195">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/example.js">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11025145">
@ -562,6 +521,47 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="10" column="7" selection-start="500" selection-end="500" vertical-scroll-proportion="0.19689119">
<folding />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/example.html">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="24" selection-start="145" selection-end="145" vertical-scroll-proportion="0.078756474">
<folding />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="36" selection-start="284" selection-end="284" vertical-scroll-proportion="0.11025145">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="39" selection-start="1542" selection-end="1542" vertical-scroll-proportion="0.5166163">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="198" column="17" selection-start="4329" selection-end="4329" vertical-scroll-proportion="0.7901354">
<folding />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -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
*/

View File

@ -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);
write: function (text) {
if (that.element) {
that.element.innerHTML += that.output;
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;
//}

152
test/bootstrap.js vendored
View File

@ -19,7 +19,7 @@ var reporter = function () {
var fails_report = $('fails');
fails_report.show();
iconElement = $('icons');
var iconElement = $('icons');
iconElement.appendChild(new Element('img', {src: '../images/exclamation.png'}));
var failMessages = $('fail_messages');
@ -30,11 +30,11 @@ var reporter = function () {
},
summary: function () {
summary = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') });
summary.innerHTML = total + ' expectations, ' + passes + ' passing, ' + fails + ' failed.';
var el = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') });
el.innerHTML = total + ' expectations, ' + passes + ' passing, ' + fails + ' failed.';
var summaryElement = $('results_summary');
summaryElement.appendChild(summary);
summaryElement.appendChild(el);
summaryElement.show();
}
}
@ -190,6 +190,7 @@ var testAsyncSpecs = function () {
'Calling waits(): Queued expectation failed');
}
};
a_spec.execute();
waitForDone(a_spec, mockSuite);
@ -450,7 +451,7 @@ var testBeforeAndAfterCallbacks = function () {
var testSpecScope = function () {
suite = describe('one suite description', function () {
var suite = describe('one suite description', function () {
it('should be a test with queuedFunctions', function() {
runs(function() {
this.foo = 0;
@ -545,7 +546,6 @@ var testRunner = function() {
var testRunnerFinishCallback = function () {
var runner = Runner();
var foo = 0;
var s
runner.finish();
@ -644,10 +644,70 @@ var testResults = function () {
'Expectation Failed count should be 1, but was ' + runner.results.failedCount);
reporter.test((runner.results.description === 'All Jasmine Suites'),
'Jasmine Runner does not have the expected description, has: ' + runner.results.description);
}, 1000);
}, 500);
}
var testReporterWithCallbacks = function () {
var foo = 0;
var bar = 0;
var baz = 0;
var runner = Runner();
describe('Suite for JSON Reporter with Callbacks', function () {
it('should be a test', function() {
runs(function () {
this.expects_that(true).should_equal(true);
});
});
it('should be a failing test', function() {
runs(function () {
this.expects_that(false).should_equal(true);
});
});
});
describe('Suite for JSON Reporter with Callbacks 2', function () {
it('should be a test', function() {
runs(function () {
this.expects_that(true).should_equal(true);
});
});
});
var specCallback = function (results) {
foo++;
}
var suiteCallback = function (results) {
bar++;
}
var runnerCallback = function (results) {
baz++;
}
callbackFunctions = {
specCallback: specCallback,
suiteCallback: suiteCallback,
runnerCallback: runnerCallback
}
runner.reporter = JasmineReporters.reporter(callbackFunctions);
runner.execute();
setTimeout(function() {
reporter.test((foo === 3),
'foo was expected to be 1, was ' + foo);
reporter.test((bar === 2),
'bar was expected to be 2, was ' + bar);
reporter.test((baz === 1),
'baz was expected to be 1, was ' + baz);
}, 750);
}
var testJSONReporter = function () {
var runner = Runner();
describe('Suite for JSON Reporter, NO DOM', function () {
@ -660,17 +720,27 @@ var testJSONReporter = function () {
runner.reporter = JasmineReporters.JSON();
reporter.test((runner.reporter !== undefined),
"Runner's reporter is undefined");
reporter.test((runner.finishCallback !== undefined),
"Runner's finishCallback is undefined");
runner.execute();
var expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}';
setTimeout(function() {
reporter.test((runner.reporter.output === expectedJSONString),
'Jasmine Reporter with No DOM does not have the expected report.<br /> <b>Expected:</b><br /> ' + expectedJSONString + '<br /><b>Got:</b><br /> ' + runner.reporter.output);
var expectedSpecJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}';
var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}';
var expectedRunnerJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}';
specJSON = runner.reporter.specJSON;
reporter.test((specJSON === expectedSpecJSON),
'JSON Reporter does not have the expected Spec results report.<br /> <b>Expected:</b><br /> ' + expectedSpecJSON +
'<br /><b>Got:</b><br /> ' + specJSON);
suiteJSON = runner.reporter.suiteJSON;
reporter.test((suiteJSON === expectedSuiteJSON),
'JSON Reporter does not have the expected Suite results report.<br /> <b>Expected:</b><br /> ' + expectedSuiteJSON +
'<br /><b>Got:</b><br /> ' + suiteJSON);
runnerJSON = runner.reporter.runnerJSON;
reporter.test((runnerJSON === expectedRunnerJSON),
'JSON Reporter does not have the expected Runner results report.<br /> <b>Expected:</b><br /> ' + expectedRunnerJSON +
'<br /><b>Got:</b><br /> ' + runnerJSON);
}, 500);
}
@ -684,47 +754,17 @@ var testJSONReporterWithDOM = function () {
});
});
runner.reporter = JasmineReporters.JSON('json_reporter_results');
runner.reporter = JasmineReporters.JSONtoDOM('json_reporter_results');
runner.execute();
setTimeout(function() {
var expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter/DOM"}], "description": "All Jasmine Suites"}';
setTimeout(function() {
reporter.test((document.getElementById('json_reporter_results').innerHTML === expectedJSONString),
'Jasmine Reporter did not output the string to the DOM, got:' + document.getElementById('json_reporter_results').innerHTML);
}, 500);
'JSON Reporter with DOM did not write the expected report to the DOM, got:' + document.getElementById('json_reporter_results').innerHTML);
}, 250);
}
var testJSONReporterWithIncrementalSpecReports = function() {
setTimeout( function () {
var runner = Runner();
describe('Suite for Incremental JSON Reporter/DOM', function () {
it('should be a test', function() {
runs(function () {
this.expects_that(true).should_equal(true);
});
});
it('should be a failing test', function() {
runs(function () {
this.expects_that(false).should_equal(true);
});
});
});
runner.reporter = JasmineReporters.IncrementalJSON('json_reporter_results_incremental');
runner.execute();
var expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}{"totalCount": 1, "passedCount": 0, "failedCount": 1, "results": [{"passed": false, "message": "Expected true but got false."}], "description": "should be a failing test"}'
setTimeout(function() {
reporter.test((document.getElementById('json_reporter_results_incremental').innerHTML === expectedJSONString),
'Jasmine Incremental Reporter did not output the correct string to the DOM, got ' + document.getElementById('json_reporter_results_incremental').innerHTML);
}, 500);
}, 2500);
}
var runTests = function () {
$('spinner').show();
@ -740,14 +780,22 @@ var runTests = function () {
testRunnerFinishCallback();
testNestedResults();
testResults();
// Timing starts to matter with these tests; ALWAYS use setTimeout()
setTimeout(function () {
testReporterWithCallbacks();
}, 2000);
setTimeout(function () {
testJSONReporter();
}, 2750);
setTimeout(function () {
testJSONReporterWithDOM();
testJSONReporterWithIncrementalSpecReports();
}, 3000);
setTimeout(function() {
$('spinner').hide();
reporter.summary();
}, 3500);
}, 4500);
}