Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ias warn)
  • Loading branch information...
commit ab3eee2cd19c22c8df51ea9623ec8b16aa5ee91c 1 parent b3107a6
Dr Nic Williams authored
2  Rakefile
@@ -12,7 +12,7 @@ require 'rake/packagetask'
12 12
13 13 $:.unshift File.dirname(__FILE__) + "/lib"
14 14
15   -APP_VERSION = '0.6.3'
  15 +APP_VERSION = '0.7.0'
16 16 APP_NAME = 'jsunittest'
17 17 RUBYFORGE_PROJECT = 'drnicjavascript'
18 18 APP_FILE_NAME= "#{APP_NAME}.js"
11 lib/jstest.rb
@@ -302,9 +302,10 @@ def define
302 302 @browsers.each do |browser|
303 303 if browser.supported?
304 304 t0 = Time.now
305   - results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0}
  305 + results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0, :warnings => 0}
306 306 errors = []
307 307 failures = []
  308 + warnings = []
308 309 browser.setup
309 310 puts "\nStarted tests in #{browser}"
310 311 @tests.each do |test|
@@ -329,13 +330,19 @@ def define
329 330 errors.push(test)
330 331 end
331 332
  333 + if result[:warnings] > 0
  334 + value = "W"
  335 + warnings.push(test)
  336 + end
  337 +
332 338 print value
333 339 end
334 340
335 341 puts "\nFinished in #{(Time.now - t0).round.to_s} seconds."
336 342 puts " Failures: #{failures.join(', ')}" unless failures.empty?
337 343 puts " Errors: #{errors.join(', ')}" unless errors.empty?
338   - puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors"
  344 + puts " Warnings: #{warnings.join(', ')}" unless warnings.empty?
  345 + puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors, #{results[:warnings]} errors"
339 346 browser.teardown
340 347 else
341 348 puts "\nSkipping #{browser}, not supported on this OS"
4 src/runner.js
@@ -63,6 +63,7 @@ JsUnitTest.Unit.Runner.prototype.getResult = function() {
63 63 results.assertions += test.assertions;
64 64 results.failures += test.failures;
65 65 results.errors += test.errors;
  66 + warnings.errors += test.warnings;
66 67 };
67 68 return results;
68 69 };
@@ -74,6 +75,7 @@ JsUnitTest.Unit.Runner.prototype.postResults = function() {
74 75 var results = this.getResult();
75 76 var url = this.options.resultsURL + "?";
76 77 url += "assertions="+ results.assertions + "&";
  78 + url += "warnings=" + results.warnings + "&";
77 79 url += "failures=" + results.failures + "&";
78 80 url += "errors=" + results.errors;
79 81 JsUnitTest.ajax({
@@ -112,5 +114,5 @@ JsUnitTest.Unit.Runner.prototype.finish = function() {
112 114 };
113 115
114 116 JsUnitTest.Unit.Runner.prototype.summary = function() {
115   - return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors').evaluate(this.getResult());
  117 + return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings').evaluate(this.getResult());
116 118 };
31 src/test_case.js
@@ -12,14 +12,16 @@ for (method in JsUnitTest.Unit.Assertions) {
12 12 JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
13 13 }
14 14
15   -JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
16   -JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
17   -JsUnitTest.Unit.Testcase.prototype.assertions = 0;
18   -JsUnitTest.Unit.Testcase.prototype.failures = 0;
19   -JsUnitTest.Unit.Testcase.prototype.errors = 0;
20   -// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
  15 +JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
  16 +JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
  17 +JsUnitTest.Unit.Testcase.prototype.assertions = 0;
  18 +JsUnitTest.Unit.Testcase.prototype.failures = 0;
  19 +JsUnitTest.Unit.Testcase.prototype.errors = 0;
  20 +JsUnitTest.Unit.Testcase.prototype.warnings = 0;
21 21 JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
22 22
  23 +// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
  24 +
23 25 JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
24 26 this.isWaiting = true;
25 27 this.test = nextPart;
@@ -45,7 +47,7 @@ JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
45 47 };
46 48
47 49 JsUnitTest.Unit.Testcase.prototype.summary = function() {
48   - var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
  50 + var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings\n';
49 51 return new JsUnitTest.Template(msg).evaluate(this) +
50 52 this.messages.join("\n");
51 53 };
@@ -65,6 +67,18 @@ JsUnitTest.Unit.Testcase.prototype.fail = function(message) {
65 67 this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
66 68 };
67 69
  70 +JsUnitTest.Unit.Testcase.prototype.warning = function(message) {
  71 + this.warnings++;
  72 + var line = "";
  73 + try {
  74 + throw new Error("stack");
  75 + } catch(e){
  76 + line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
  77 + }
  78 + this.messages.push("Warning: " + message + (line ? " Line #" + line : ""));
  79 +};
  80 +JsUnitTest.Unit.Testcase.prototype.warn = JsUnitTest.Unit.Testcase.prototype.warning;
  81 +
68 82 JsUnitTest.Unit.Testcase.prototype.info = function(message) {
69 83 this.messages.push("Info: " + message);
70 84 };
@@ -78,6 +92,7 @@ JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
78 92 JsUnitTest.Unit.Testcase.prototype.status = function() {
79 93 if (this.failures > 0) return 'failed';
80 94 if (this.errors > 0) return 'error';
  95 + if (this.warnings > 0) return 'warning';
81 96 return 'passed';
82 97 };
83 98
@@ -88,4 +103,4 @@ JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
88 103 this.info((arguments[2] || 'Operation') + ' finished ' +
89 104 iterations + ' iterations in ' + (timeTaken/1000)+'s' );
90 105 return timeTaken;
91   -};
  106 +};
4 test/assets/unittest.css
@@ -40,6 +40,10 @@ body {
40 40 background-color: #fcc;
41 41 }
42 42
  43 +.logtable .warning {
  44 + background-color: #FC6;
  45 +}
  46 +
43 47 .logtable td div.action_buttons {
44 48 display: inline;
45 49 }

0 comments on commit ab3eee2

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