Skip to content
Browse files

0.7.0 - added warning test helper method (use like error/fail; has al…

…ias warn)
  • Loading branch information...
1 parent b3107a6 commit ab3eee2cd19c22c8df51ea9623ec8b16aa5ee91c @drnic committed Aug 11, 2008
Showing with 40 additions and 12 deletions.
  1. +1 −1 Rakefile
  2. +9 −2 lib/jstest.rb
  3. +3 −1 src/runner.js
  4. +23 −8 src/test_case.js
  5. +4 −0 test/assets/unittest.css
View
2 Rakefile
@@ -12,7 +12,7 @@ require 'rake/packagetask'
$:.unshift File.dirname(__FILE__) + "/lib"
-APP_VERSION = '0.6.3'
+APP_VERSION = '0.7.0'
APP_NAME = 'jsunittest'
RUBYFORGE_PROJECT = 'drnicjavascript'
APP_FILE_NAME= "#{APP_NAME}.js"
View
11 lib/jstest.rb
@@ -302,9 +302,10 @@ def define
@browsers.each do |browser|
if browser.supported?
t0 = Time.now
- results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0}
+ results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0, :warnings => 0}
errors = []
failures = []
+ warnings = []
browser.setup
puts "\nStarted tests in #{browser}"
@tests.each do |test|
@@ -329,13 +330,19 @@ def define
errors.push(test)
end
+ if result[:warnings] > 0
+ value = "W"
+ warnings.push(test)
+ end
+
print value
end
puts "\nFinished in #{(Time.now - t0).round.to_s} seconds."
puts " Failures: #{failures.join(', ')}" unless failures.empty?
puts " Errors: #{errors.join(', ')}" unless errors.empty?
- puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors"
+ puts " Warnings: #{warnings.join(', ')}" unless warnings.empty?
+ puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors, #{results[:warnings]} errors"
browser.teardown
else
puts "\nSkipping #{browser}, not supported on this OS"
View
4 src/runner.js
@@ -63,6 +63,7 @@ JsUnitTest.Unit.Runner.prototype.getResult = function() {
results.assertions += test.assertions;
results.failures += test.failures;
results.errors += test.errors;
+ warnings.errors += test.warnings;
};
return results;
};
@@ -74,6 +75,7 @@ JsUnitTest.Unit.Runner.prototype.postResults = function() {
var results = this.getResult();
var url = this.options.resultsURL + "?";
url += "assertions="+ results.assertions + "&";
+ url += "warnings=" + results.warnings + "&";
url += "failures=" + results.failures + "&";
url += "errors=" + results.errors;
JsUnitTest.ajax({
@@ -112,5 +114,5 @@ JsUnitTest.Unit.Runner.prototype.finish = function() {
};
JsUnitTest.Unit.Runner.prototype.summary = function() {
- return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors').evaluate(this.getResult());
+ return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings').evaluate(this.getResult());
};
View
31 src/test_case.js
@@ -12,14 +12,16 @@ for (method in JsUnitTest.Unit.Assertions) {
JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
}
-JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
-JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
-JsUnitTest.Unit.Testcase.prototype.assertions = 0;
-JsUnitTest.Unit.Testcase.prototype.failures = 0;
-JsUnitTest.Unit.Testcase.prototype.errors = 0;
-// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
+JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
+JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
+JsUnitTest.Unit.Testcase.prototype.assertions = 0;
+JsUnitTest.Unit.Testcase.prototype.failures = 0;
+JsUnitTest.Unit.Testcase.prototype.errors = 0;
+JsUnitTest.Unit.Testcase.prototype.warnings = 0;
JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
+// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
+
JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
this.isWaiting = true;
this.test = nextPart;
@@ -45,7 +47,7 @@ JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
};
JsUnitTest.Unit.Testcase.prototype.summary = function() {
- var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
+ var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings\n';
return new JsUnitTest.Template(msg).evaluate(this) +
this.messages.join("\n");
};
@@ -65,6 +67,18 @@ JsUnitTest.Unit.Testcase.prototype.fail = function(message) {
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
};
+JsUnitTest.Unit.Testcase.prototype.warning = function(message) {
+ this.warnings++;
+ var line = "";
+ try {
+ throw new Error("stack");
+ } catch(e){
+ line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
+ }
+ this.messages.push("Warning: " + message + (line ? " Line #" + line : ""));
+};
+JsUnitTest.Unit.Testcase.prototype.warn = JsUnitTest.Unit.Testcase.prototype.warning;
+
JsUnitTest.Unit.Testcase.prototype.info = function(message) {
this.messages.push("Info: " + message);
};
@@ -78,6 +92,7 @@ JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
JsUnitTest.Unit.Testcase.prototype.status = function() {
if (this.failures > 0) return 'failed';
if (this.errors > 0) return 'error';
+ if (this.warnings > 0) return 'warning';
return 'passed';
};
@@ -88,4 +103,4 @@ JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
this.info((arguments[2] || 'Operation') + ' finished ' +
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
return timeTaken;
-};
+};
View
4 test/assets/unittest.css
@@ -40,6 +40,10 @@ body {
background-color: #fcc;
}
+.logtable .warning {
+ background-color: #FC6;
+}
+
.logtable td div.action_buttons {
display: inline;
}

0 comments on commit ab3eee2

Please sign in to comment.
Something went wrong with that request. Please try again.