newjs 1.3.6 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* Jsunittest, version 0.6.
|
1
|
+
/* Jsunittest, version 0.6.3
|
2
2
|
* (c) 2008 Dr Nic Williams
|
3
3
|
*
|
4
4
|
* Jsunittest is freely distributable under
|
@@ -8,10 +8,6 @@
|
|
8
8
|
*--------------------------------------------------------------------------*/
|
9
9
|
|
10
10
|
var JsUnitTest = {
|
11
|
-
Version: '0.6.1',
|
12
|
-
};
|
13
|
-
|
14
|
-
var DrNicTest = {
|
15
11
|
Unit: {},
|
16
12
|
inspect: function(object) {
|
17
13
|
try {
|
@@ -49,7 +45,7 @@ var DrNicTest = {
|
|
49
45
|
while (source.length > 0) {
|
50
46
|
if (match = source.match(pattern)) {
|
51
47
|
result += source.slice(0, match.index);
|
52
|
-
result +=
|
48
|
+
result += JsUnitTest.String.interpret(replacement(match));
|
53
49
|
source = source.slice(match.index + match[0].length);
|
54
50
|
} else {
|
55
51
|
result += source, source = '';
|
@@ -197,22 +193,24 @@ var DrNicTest = {
|
|
197
193
|
}
|
198
194
|
};
|
199
195
|
|
200
|
-
|
196
|
+
JsUnitTest.gsub.prepareReplacement = function(replacement) {
|
201
197
|
if (typeof replacement == "function") return replacement;
|
202
198
|
var template = new Template(replacement);
|
203
199
|
return function(match) { return template.evaluate(match) };
|
204
200
|
};
|
205
201
|
|
206
|
-
|
202
|
+
JsUnitTest.Version = '0.6.3';
|
203
|
+
|
204
|
+
JsUnitTest.Template = function(template, pattern) {
|
207
205
|
this.template = template; //template.toString();
|
208
|
-
this.pattern = pattern ||
|
206
|
+
this.pattern = pattern || JsUnitTest.Template.Pattern;
|
209
207
|
};
|
210
208
|
|
211
|
-
|
209
|
+
JsUnitTest.Template.prototype.evaluate = function(object) {
|
212
210
|
if (typeof object.toTemplateReplacements == "function")
|
213
211
|
object = object.toTemplateReplacements();
|
214
212
|
|
215
|
-
return
|
213
|
+
return JsUnitTest.gsub(this.template, this.pattern, function(match) {
|
216
214
|
if (object == null) return '';
|
217
215
|
|
218
216
|
var before = match[1] || '';
|
@@ -231,24 +229,24 @@ DrNicTest.Template.prototype.evaluate = function(object) {
|
|
231
229
|
match = pattern.exec(expr);
|
232
230
|
}
|
233
231
|
|
234
|
-
return before +
|
232
|
+
return before + JsUnitTest.String.interpret(ctx);
|
235
233
|
});
|
236
234
|
}
|
237
235
|
|
238
|
-
|
239
|
-
|
236
|
+
JsUnitTest.Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
237
|
+
JsUnitTest.Event = {};
|
240
238
|
// written by Dean Edwards, 2005
|
241
239
|
// with input from Tino Zijdel, Matthias Miller, Diego Perini
|
242
240
|
// namespaced by Dr Nic Williams 2008
|
243
241
|
|
244
242
|
// http://dean.edwards.name/weblog/2005/10/add-event/
|
245
243
|
// http://dean.edwards.name/weblog/2005/10/add-event2/
|
246
|
-
|
244
|
+
JsUnitTest.Event.addEvent = function(element, type, handler) {
|
247
245
|
if (element.addEventListener) {
|
248
246
|
element.addEventListener(type, handler, false);
|
249
247
|
} else {
|
250
248
|
// assign each event handler a unique ID
|
251
|
-
if (!handler.$$guid) handler.$$guid = addEvent.guid++;
|
249
|
+
if (!handler.$$guid) handler.$$guid = JsUnitTest.Event.addEvent.guid++;
|
252
250
|
// create a hash table of event types for the element
|
253
251
|
if (!element.events) element.events = {};
|
254
252
|
// create a hash table of event handlers for each element/event pair
|
@@ -263,13 +261,13 @@ DrNicTest.Event.addEvent = function(element, type, handler) {
|
|
263
261
|
// store the event handler in the hash table
|
264
262
|
handlers[handler.$$guid] = handler;
|
265
263
|
// assign a global event handler to do all the work
|
266
|
-
element["on" + type] = handleEvent;
|
264
|
+
element["on" + type] = this.handleEvent;
|
267
265
|
}
|
268
266
|
};
|
269
267
|
// a counter used to create unique IDs
|
270
|
-
|
268
|
+
JsUnitTest.Event.addEvent.guid = 1;
|
271
269
|
|
272
|
-
|
270
|
+
JsUnitTest.Event.removeEvent = function(element, type, handler) {
|
273
271
|
if (element.removeEventListener) {
|
274
272
|
element.removeEventListener(type, handler, false);
|
275
273
|
} else {
|
@@ -280,10 +278,10 @@ DrNicTest.Event.removeEvent = function(element, type, handler) {
|
|
280
278
|
}
|
281
279
|
};
|
282
280
|
|
283
|
-
|
281
|
+
JsUnitTest.Event.handleEvent = function(event) {
|
284
282
|
var returnValue = true;
|
285
283
|
// grab the event object (IE uses a global event object)
|
286
|
-
event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
284
|
+
event = event || JsUnitTest.Event.fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
287
285
|
// get a reference to the hash table of event handlers
|
288
286
|
var handlers = this.events[event.type];
|
289
287
|
// execute each event handler
|
@@ -296,67 +294,81 @@ DrNicTest.Event.handleEvent = function(event) {
|
|
296
294
|
return returnValue;
|
297
295
|
};
|
298
296
|
|
299
|
-
|
297
|
+
JsUnitTest.Event.fixEvent = function(event) {
|
300
298
|
// add W3C standard event methods
|
301
|
-
event.preventDefault = fixEvent.preventDefault;
|
302
|
-
event.stopPropagation = fixEvent.stopPropagation;
|
299
|
+
event.preventDefault = this.fixEvent.preventDefault;
|
300
|
+
event.stopPropagation = this.fixEvent.stopPropagation;
|
303
301
|
return event;
|
304
302
|
};
|
305
|
-
|
303
|
+
JsUnitTest.Event.fixEvent.preventDefault = function() {
|
306
304
|
this.returnValue = false;
|
307
305
|
};
|
308
|
-
|
306
|
+
JsUnitTest.Event.fixEvent.stopPropagation = function() {
|
309
307
|
this.cancelBubble = true;
|
310
308
|
};
|
311
309
|
|
312
|
-
|
313
|
-
this.element =
|
310
|
+
JsUnitTest.Unit.Logger = function(element) {
|
311
|
+
this.element = JsUnitTest.$(element);
|
314
312
|
if (this.element) this._createLogTable();
|
315
313
|
};
|
316
314
|
|
317
|
-
|
315
|
+
JsUnitTest.Unit.Logger.prototype.start = function(testName) {
|
318
316
|
if (!this.element) return;
|
319
317
|
var tbody = this.element.getElementsByTagName('tbody')[0];
|
320
|
-
|
318
|
+
|
319
|
+
var tr = document.createElement('tr');
|
320
|
+
var td;
|
321
|
+
|
322
|
+
//testname
|
323
|
+
td = document.createElement('td');
|
324
|
+
td.appendChild(document.createTextNode(testName));
|
325
|
+
tr.appendChild(td)
|
326
|
+
|
327
|
+
tr.appendChild(document.createElement('td'));//status
|
328
|
+
tr.appendChild(document.createElement('td'));//message
|
329
|
+
|
330
|
+
tbody.appendChild(tr);
|
321
331
|
};
|
322
332
|
|
323
|
-
|
333
|
+
JsUnitTest.Unit.Logger.prototype.setStatus = function(status) {
|
324
334
|
var logline = this.getLastLogLine();
|
325
335
|
logline.className = status;
|
326
336
|
var statusCell = logline.getElementsByTagName('td')[1];
|
327
|
-
statusCell.
|
337
|
+
statusCell.appendChild(document.createTextNode(status));
|
328
338
|
};
|
329
339
|
|
330
|
-
|
340
|
+
JsUnitTest.Unit.Logger.prototype.finish = function(status, summary) {
|
331
341
|
if (!this.element) return;
|
332
342
|
this.setStatus(status);
|
333
343
|
this.message(summary);
|
334
344
|
};
|
335
345
|
|
336
|
-
|
346
|
+
JsUnitTest.Unit.Logger.prototype.message = function(message) {
|
337
347
|
if (!this.element) return;
|
338
348
|
var cell = this.getMessageCell();
|
349
|
+
|
350
|
+
// cell.appendChild(document.createTextNode(this._toHTML(message)));
|
339
351
|
cell.innerHTML = this._toHTML(message);
|
340
352
|
};
|
341
353
|
|
342
|
-
|
354
|
+
JsUnitTest.Unit.Logger.prototype.summary = function(summary) {
|
343
355
|
if (!this.element) return;
|
344
356
|
var div = this.element.getElementsByTagName('div')[0];
|
345
357
|
div.innerHTML = this._toHTML(summary);
|
346
358
|
};
|
347
359
|
|
348
|
-
|
360
|
+
JsUnitTest.Unit.Logger.prototype.getLastLogLine = function() {
|
349
361
|
var tbody = this.element.getElementsByTagName('tbody')[0];
|
350
362
|
var loglines = tbody.getElementsByTagName('tr');
|
351
363
|
return loglines[loglines.length - 1];
|
352
364
|
};
|
353
365
|
|
354
|
-
|
366
|
+
JsUnitTest.Unit.Logger.prototype.getMessageCell = function() {
|
355
367
|
var logline = this.getLastLogLine();
|
356
368
|
return logline.getElementsByTagName('td')[2];
|
357
369
|
};
|
358
370
|
|
359
|
-
|
371
|
+
JsUnitTest.Unit.Logger.prototype._createLogTable = function() {
|
360
372
|
var html = '<div class="logsummary">running...</div>' +
|
361
373
|
'<table class="logtable">' +
|
362
374
|
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
|
@@ -365,7 +377,7 @@ DrNicTest.Unit.Logger.prototype._createLogTable = function() {
|
|
365
377
|
this.element.innerHTML = html;
|
366
378
|
};
|
367
379
|
|
368
|
-
|
380
|
+
JsUnitTest.Unit.Logger.prototype.appendActionButtons = function(actions) {
|
369
381
|
// actions = $H(actions);
|
370
382
|
// if (!actions.any()) return;
|
371
383
|
// var div = new Element("div", {className: 'action_buttons'});
|
@@ -377,22 +389,22 @@ DrNicTest.Unit.Logger.prototype.appendActionButtons = function(actions) {
|
|
377
389
|
// this.getMessageCell().insert(div);
|
378
390
|
};
|
379
391
|
|
380
|
-
|
381
|
-
return
|
392
|
+
JsUnitTest.Unit.Logger.prototype._toHTML = function(txt) {
|
393
|
+
return JsUnitTest.escapeHTML(txt).replace(/\n/g,"<br/>");
|
382
394
|
};
|
383
|
-
|
395
|
+
JsUnitTest.Unit.MessageTemplate = function(string) {
|
384
396
|
var parts = [];
|
385
|
-
var str =
|
397
|
+
var str = JsUnitTest.scan((string || ''), /(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
|
386
398
|
parts.push(part[0]);
|
387
399
|
});
|
388
400
|
this.parts = parts;
|
389
401
|
};
|
390
402
|
|
391
|
-
|
403
|
+
JsUnitTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
|
392
404
|
var results = [];
|
393
405
|
for (var i=0; i < this.parts.length; i++) {
|
394
406
|
var part = this.parts[i];
|
395
|
-
var result = (part == '?') ?
|
407
|
+
var result = (part == '?') ? JsUnitTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
|
396
408
|
results.push(result);
|
397
409
|
};
|
398
410
|
return results.join('');
|
@@ -402,7 +414,7 @@ DrNicTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
|
|
402
414
|
// All of which are outline in the comments, below
|
403
415
|
// From John Resig's book Pro JavaScript Techniques
|
404
416
|
// published by Apress, 2006-8
|
405
|
-
|
417
|
+
JsUnitTest.ajax = function( options ) {
|
406
418
|
|
407
419
|
// Load the options object with defaults, if no
|
408
420
|
// values were provided by the user
|
@@ -518,11 +530,11 @@ DrNicTest.ajax = function( options ) {
|
|
518
530
|
}
|
519
531
|
|
520
532
|
}
|
521
|
-
|
533
|
+
JsUnitTest.Unit.Assertions = {
|
522
534
|
buildMessage: function(message, template) {
|
523
|
-
var args =
|
535
|
+
var args = JsUnitTest.arrayfromargs(arguments).slice(2);
|
524
536
|
return (message ? message + '\n' : '') +
|
525
|
-
new
|
537
|
+
new JsUnitTest.Unit.MessageTemplate(template).evaluate(args);
|
526
538
|
},
|
527
539
|
|
528
540
|
flunk: function(message) {
|
@@ -552,8 +564,8 @@ DrNicTest.Unit.Assertions = {
|
|
552
564
|
|
553
565
|
assertEnumEqual: function(expected, actual, message) {
|
554
566
|
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
|
555
|
-
var expected_array =
|
556
|
-
var actual_array =
|
567
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
568
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
557
569
|
this.assertBlock(message, function() {
|
558
570
|
if (expected_array.length == actual_array.length) {
|
559
571
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -567,8 +579,8 @@ DrNicTest.Unit.Assertions = {
|
|
567
579
|
|
568
580
|
assertEnumNotEqual: function(expected, actual, message) {
|
569
581
|
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
|
570
|
-
var expected_array =
|
571
|
-
var actual_array =
|
582
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
583
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
572
584
|
this.assertBlock(message, function() {
|
573
585
|
if (expected_array.length == actual_array.length) {
|
574
586
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -582,8 +594,8 @@ DrNicTest.Unit.Assertions = {
|
|
582
594
|
|
583
595
|
assertHashEqual: function(expected, actual, message) {
|
584
596
|
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
|
585
|
-
var expected_array =
|
586
|
-
var actual_array =
|
597
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
598
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
587
599
|
var block = function() {
|
588
600
|
if (expected_array.length == actual_array.length) {
|
589
601
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -598,8 +610,8 @@ DrNicTest.Unit.Assertions = {
|
|
598
610
|
|
599
611
|
assertHashNotEqual: function(expected, actual, message) {
|
600
612
|
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
|
601
|
-
var expected_array =
|
602
|
-
var actual_array =
|
613
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
614
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
603
615
|
// from now we recursively zip & compare nested arrays
|
604
616
|
var block = function() {
|
605
617
|
if (expected_array.length == actual_array.length) {
|
@@ -665,7 +677,7 @@ DrNicTest.Unit.Assertions = {
|
|
665
677
|
|
666
678
|
assertHidden: function(element, message) {
|
667
679
|
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
|
668
|
-
this.assertBlock(message, function() { return element.style.display == 'none' });
|
680
|
+
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
|
669
681
|
},
|
670
682
|
|
671
683
|
assertInstanceOf: function(expected, actual, message) {
|
@@ -708,10 +720,10 @@ DrNicTest.Unit.Assertions = {
|
|
708
720
|
},
|
709
721
|
|
710
722
|
_isVisible: function(element) {
|
711
|
-
element =
|
723
|
+
element = JsUnitTest.$(element);
|
712
724
|
if(!element.parentNode) return true;
|
713
725
|
this.assertNotNull(element);
|
714
|
-
if(element.style && element.style.display == 'none')
|
726
|
+
if(element.style && (element.style.display == 'none'))
|
715
727
|
return false;
|
716
728
|
|
717
729
|
return arguments.callee.call(this, element.parentNode);
|
@@ -728,7 +740,7 @@ DrNicTest.Unit.Assertions = {
|
|
728
740
|
},
|
729
741
|
|
730
742
|
assertElementsMatch: function() {
|
731
|
-
var pass = true, expressions =
|
743
|
+
var pass = true, expressions = JsUnitTest.arrayfromargs(arguments);
|
732
744
|
var elements = expressions.shift();
|
733
745
|
if (elements.length != expressions.length) {
|
734
746
|
message = this.buildMessage('assertElementsMatch', 'size mismatch: ? elements, ? expressions (?).', elements.length, expressions.length, expressions);
|
@@ -737,8 +749,8 @@ DrNicTest.Unit.Assertions = {
|
|
737
749
|
}
|
738
750
|
for (var i=0; i < expressions.length; i++) {
|
739
751
|
var expression = expressions[i];
|
740
|
-
var element =
|
741
|
-
if (
|
752
|
+
var element = JsUnitTest.$(elements[i]);
|
753
|
+
if (JsUnitTest.selectorMatch(expression, element)) {
|
742
754
|
pass = true;
|
743
755
|
break;
|
744
756
|
}
|
@@ -753,28 +765,28 @@ DrNicTest.Unit.Assertions = {
|
|
753
765
|
this.assertElementsMatch([element], expression);
|
754
766
|
}
|
755
767
|
};
|
756
|
-
|
768
|
+
JsUnitTest.Unit.Runner = function(testcases) {
|
757
769
|
var argumentOptions = arguments[1] || {};
|
758
770
|
var options = this.options = {};
|
759
771
|
options.testLog = ('testLog' in argumentOptions) ? argumentOptions.testLog : 'testlog';
|
760
772
|
options.resultsURL = this.queryParams.resultsURL;
|
761
|
-
options.testLog =
|
773
|
+
options.testLog = JsUnitTest.$(options.testLog);
|
762
774
|
|
763
775
|
this.tests = this.getTests(testcases);
|
764
776
|
this.currentTest = 0;
|
765
|
-
this.logger = new
|
777
|
+
this.logger = new JsUnitTest.Unit.Logger(options.testLog);
|
766
778
|
|
767
779
|
var self = this;
|
768
|
-
|
780
|
+
JsUnitTest.Event.addEvent(window, "load", function() {
|
769
781
|
setTimeout(function() {
|
770
782
|
self.runTests();
|
771
783
|
}, 0.1);
|
772
784
|
});
|
773
785
|
};
|
774
786
|
|
775
|
-
|
787
|
+
JsUnitTest.Unit.Runner.prototype.queryParams = JsUnitTest.toQueryParams();
|
776
788
|
|
777
|
-
|
789
|
+
JsUnitTest.Unit.Runner.prototype.portNumber = function() {
|
778
790
|
if (window.location.search.length > 0) {
|
779
791
|
var matches = window.location.search.match(/\:(\d{3,5})\//);
|
780
792
|
if (matches) {
|
@@ -784,7 +796,7 @@ DrNicTest.Unit.Runner.prototype.portNumber = function() {
|
|
784
796
|
return null;
|
785
797
|
};
|
786
798
|
|
787
|
-
|
799
|
+
JsUnitTest.Unit.Runner.prototype.getTests = function(testcases) {
|
788
800
|
var tests = [], options = this.options;
|
789
801
|
if (this.queryParams.tests) tests = this.queryParams.tests.split(',');
|
790
802
|
else if (options.tests) tests = options.tests;
|
@@ -799,13 +811,13 @@ DrNicTest.Unit.Runner.prototype.getTests = function(testcases) {
|
|
799
811
|
var test = tests[i];
|
800
812
|
if (testcases[test])
|
801
813
|
results.push(
|
802
|
-
new
|
814
|
+
new JsUnitTest.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown)
|
803
815
|
);
|
804
816
|
};
|
805
817
|
return results;
|
806
818
|
};
|
807
819
|
|
808
|
-
|
820
|
+
JsUnitTest.Unit.Runner.prototype.getResult = function() {
|
809
821
|
var results = {
|
810
822
|
tests: this.tests.length,
|
811
823
|
assertions: 0,
|
@@ -822,7 +834,7 @@ DrNicTest.Unit.Runner.prototype.getResult = function() {
|
|
822
834
|
return results;
|
823
835
|
};
|
824
836
|
|
825
|
-
|
837
|
+
JsUnitTest.Unit.Runner.prototype.postResults = function() {
|
826
838
|
if (this.options.resultsURL) {
|
827
839
|
// new Ajax.Request(this.options.resultsURL,
|
828
840
|
// { method: 'get', parameters: this.getResult(), asynchronous: false });
|
@@ -831,14 +843,14 @@ DrNicTest.Unit.Runner.prototype.postResults = function() {
|
|
831
843
|
url += "assertions="+ results.assertions + "&";
|
832
844
|
url += "failures=" + results.failures + "&";
|
833
845
|
url += "errors=" + results.errors;
|
834
|
-
|
846
|
+
JsUnitTest.ajax({
|
835
847
|
url: url,
|
836
848
|
type: 'GET'
|
837
849
|
})
|
838
850
|
}
|
839
851
|
};
|
840
852
|
|
841
|
-
|
853
|
+
JsUnitTest.Unit.Runner.prototype.runTests = function() {
|
842
854
|
var test = this.tests[this.currentTest], actions;
|
843
855
|
|
844
856
|
if (!test) return this.finish();
|
@@ -861,15 +873,15 @@ DrNicTest.Unit.Runner.prototype.runTests = function() {
|
|
861
873
|
this.runTests();
|
862
874
|
};
|
863
875
|
|
864
|
-
|
876
|
+
JsUnitTest.Unit.Runner.prototype.finish = function() {
|
865
877
|
this.postResults();
|
866
878
|
this.logger.summary(this.summary());
|
867
879
|
};
|
868
880
|
|
869
|
-
|
870
|
-
return new
|
881
|
+
JsUnitTest.Unit.Runner.prototype.summary = function() {
|
882
|
+
return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors').evaluate(this.getResult());
|
871
883
|
};
|
872
|
-
|
884
|
+
JsUnitTest.Unit.Testcase = function(name, test, setup, teardown) {
|
873
885
|
this.name = name;
|
874
886
|
this.test = test || function() {};
|
875
887
|
this.setup = setup || function() {};
|
@@ -877,27 +889,27 @@ DrNicTest.Unit.Testcase = function(name, test, setup, teardown) {
|
|
877
889
|
this.messages = [];
|
878
890
|
this.actions = {};
|
879
891
|
};
|
880
|
-
// import
|
892
|
+
// import JsUnitTest.Unit.Assertions
|
881
893
|
|
882
|
-
for (method in
|
883
|
-
|
894
|
+
for (method in JsUnitTest.Unit.Assertions) {
|
895
|
+
JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
|
884
896
|
}
|
885
897
|
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
//
|
892
|
-
|
898
|
+
JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
|
899
|
+
JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
|
900
|
+
JsUnitTest.Unit.Testcase.prototype.assertions = 0;
|
901
|
+
JsUnitTest.Unit.Testcase.prototype.failures = 0;
|
902
|
+
JsUnitTest.Unit.Testcase.prototype.errors = 0;
|
903
|
+
// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
|
904
|
+
JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
|
893
905
|
|
894
|
-
|
906
|
+
JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
|
895
907
|
this.isWaiting = true;
|
896
908
|
this.test = nextPart;
|
897
909
|
this.timeToWait = time;
|
898
910
|
};
|
899
911
|
|
900
|
-
|
912
|
+
JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
|
901
913
|
try {
|
902
914
|
try {
|
903
915
|
if (!this.isWaiting) this.setup();
|
@@ -915,17 +927,17 @@ DrNicTest.Unit.Testcase.prototype.run = function(rethrow) {
|
|
915
927
|
}
|
916
928
|
};
|
917
929
|
|
918
|
-
|
930
|
+
JsUnitTest.Unit.Testcase.prototype.summary = function() {
|
919
931
|
var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
|
920
|
-
return new
|
932
|
+
return new JsUnitTest.Template(msg).evaluate(this) +
|
921
933
|
this.messages.join("\n");
|
922
934
|
};
|
923
935
|
|
924
|
-
|
936
|
+
JsUnitTest.Unit.Testcase.prototype.pass = function() {
|
925
937
|
this.assertions++;
|
926
938
|
};
|
927
939
|
|
928
|
-
|
940
|
+
JsUnitTest.Unit.Testcase.prototype.fail = function(message) {
|
929
941
|
this.failures++;
|
930
942
|
var line = "";
|
931
943
|
try {
|
@@ -936,23 +948,23 @@ DrNicTest.Unit.Testcase.prototype.fail = function(message) {
|
|
936
948
|
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
|
937
949
|
};
|
938
950
|
|
939
|
-
|
951
|
+
JsUnitTest.Unit.Testcase.prototype.info = function(message) {
|
940
952
|
this.messages.push("Info: " + message);
|
941
953
|
};
|
942
954
|
|
943
|
-
|
955
|
+
JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
|
944
956
|
this.errors++;
|
945
957
|
this.actions['retry with throw'] = function() { test.run(true) };
|
946
|
-
this.messages.push(error.name + ": "+ error.message + "(" +
|
958
|
+
this.messages.push(error.name + ": "+ error.message + "(" + JsUnitTest.inspect(error) + ")");
|
947
959
|
};
|
948
960
|
|
949
|
-
|
961
|
+
JsUnitTest.Unit.Testcase.prototype.status = function() {
|
950
962
|
if (this.failures > 0) return 'failed';
|
951
963
|
if (this.errors > 0) return 'error';
|
952
964
|
return 'passed';
|
953
965
|
};
|
954
966
|
|
955
|
-
|
967
|
+
JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
|
956
968
|
var startAt = new Date();
|
957
969
|
(iterations || 1).times(operation);
|
958
970
|
var timeTaken = ((new Date())-startAt);
|
@@ -961,4 +973,4 @@ DrNicTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
|
|
961
973
|
return timeTaken;
|
962
974
|
};
|
963
975
|
|
964
|
-
Test =
|
976
|
+
Test = JsUnitTest
|
data/lib/newjs/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* Jsunittest, version 0.6.
|
1
|
+
/* Jsunittest, version 0.6.3
|
2
2
|
* (c) 2008 Dr Nic Williams
|
3
3
|
*
|
4
4
|
* Jsunittest is freely distributable under
|
@@ -8,10 +8,6 @@
|
|
8
8
|
*--------------------------------------------------------------------------*/
|
9
9
|
|
10
10
|
var JsUnitTest = {
|
11
|
-
Version: '0.6.1',
|
12
|
-
};
|
13
|
-
|
14
|
-
var DrNicTest = {
|
15
11
|
Unit: {},
|
16
12
|
inspect: function(object) {
|
17
13
|
try {
|
@@ -49,7 +45,7 @@ var DrNicTest = {
|
|
49
45
|
while (source.length > 0) {
|
50
46
|
if (match = source.match(pattern)) {
|
51
47
|
result += source.slice(0, match.index);
|
52
|
-
result +=
|
48
|
+
result += JsUnitTest.String.interpret(replacement(match));
|
53
49
|
source = source.slice(match.index + match[0].length);
|
54
50
|
} else {
|
55
51
|
result += source, source = '';
|
@@ -197,22 +193,24 @@ var DrNicTest = {
|
|
197
193
|
}
|
198
194
|
};
|
199
195
|
|
200
|
-
|
196
|
+
JsUnitTest.gsub.prepareReplacement = function(replacement) {
|
201
197
|
if (typeof replacement == "function") return replacement;
|
202
198
|
var template = new Template(replacement);
|
203
199
|
return function(match) { return template.evaluate(match) };
|
204
200
|
};
|
205
201
|
|
206
|
-
|
202
|
+
JsUnitTest.Version = '0.6.3';
|
203
|
+
|
204
|
+
JsUnitTest.Template = function(template, pattern) {
|
207
205
|
this.template = template; //template.toString();
|
208
|
-
this.pattern = pattern ||
|
206
|
+
this.pattern = pattern || JsUnitTest.Template.Pattern;
|
209
207
|
};
|
210
208
|
|
211
|
-
|
209
|
+
JsUnitTest.Template.prototype.evaluate = function(object) {
|
212
210
|
if (typeof object.toTemplateReplacements == "function")
|
213
211
|
object = object.toTemplateReplacements();
|
214
212
|
|
215
|
-
return
|
213
|
+
return JsUnitTest.gsub(this.template, this.pattern, function(match) {
|
216
214
|
if (object == null) return '';
|
217
215
|
|
218
216
|
var before = match[1] || '';
|
@@ -231,24 +229,24 @@ DrNicTest.Template.prototype.evaluate = function(object) {
|
|
231
229
|
match = pattern.exec(expr);
|
232
230
|
}
|
233
231
|
|
234
|
-
return before +
|
232
|
+
return before + JsUnitTest.String.interpret(ctx);
|
235
233
|
});
|
236
234
|
}
|
237
235
|
|
238
|
-
|
239
|
-
|
236
|
+
JsUnitTest.Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
237
|
+
JsUnitTest.Event = {};
|
240
238
|
// written by Dean Edwards, 2005
|
241
239
|
// with input from Tino Zijdel, Matthias Miller, Diego Perini
|
242
240
|
// namespaced by Dr Nic Williams 2008
|
243
241
|
|
244
242
|
// http://dean.edwards.name/weblog/2005/10/add-event/
|
245
243
|
// http://dean.edwards.name/weblog/2005/10/add-event2/
|
246
|
-
|
244
|
+
JsUnitTest.Event.addEvent = function(element, type, handler) {
|
247
245
|
if (element.addEventListener) {
|
248
246
|
element.addEventListener(type, handler, false);
|
249
247
|
} else {
|
250
248
|
// assign each event handler a unique ID
|
251
|
-
if (!handler.$$guid) handler.$$guid = addEvent.guid++;
|
249
|
+
if (!handler.$$guid) handler.$$guid = JsUnitTest.Event.addEvent.guid++;
|
252
250
|
// create a hash table of event types for the element
|
253
251
|
if (!element.events) element.events = {};
|
254
252
|
// create a hash table of event handlers for each element/event pair
|
@@ -263,13 +261,13 @@ DrNicTest.Event.addEvent = function(element, type, handler) {
|
|
263
261
|
// store the event handler in the hash table
|
264
262
|
handlers[handler.$$guid] = handler;
|
265
263
|
// assign a global event handler to do all the work
|
266
|
-
element["on" + type] = handleEvent;
|
264
|
+
element["on" + type] = this.handleEvent;
|
267
265
|
}
|
268
266
|
};
|
269
267
|
// a counter used to create unique IDs
|
270
|
-
|
268
|
+
JsUnitTest.Event.addEvent.guid = 1;
|
271
269
|
|
272
|
-
|
270
|
+
JsUnitTest.Event.removeEvent = function(element, type, handler) {
|
273
271
|
if (element.removeEventListener) {
|
274
272
|
element.removeEventListener(type, handler, false);
|
275
273
|
} else {
|
@@ -280,10 +278,10 @@ DrNicTest.Event.removeEvent = function(element, type, handler) {
|
|
280
278
|
}
|
281
279
|
};
|
282
280
|
|
283
|
-
|
281
|
+
JsUnitTest.Event.handleEvent = function(event) {
|
284
282
|
var returnValue = true;
|
285
283
|
// grab the event object (IE uses a global event object)
|
286
|
-
event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
284
|
+
event = event || JsUnitTest.Event.fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
287
285
|
// get a reference to the hash table of event handlers
|
288
286
|
var handlers = this.events[event.type];
|
289
287
|
// execute each event handler
|
@@ -296,67 +294,81 @@ DrNicTest.Event.handleEvent = function(event) {
|
|
296
294
|
return returnValue;
|
297
295
|
};
|
298
296
|
|
299
|
-
|
297
|
+
JsUnitTest.Event.fixEvent = function(event) {
|
300
298
|
// add W3C standard event methods
|
301
|
-
event.preventDefault = fixEvent.preventDefault;
|
302
|
-
event.stopPropagation = fixEvent.stopPropagation;
|
299
|
+
event.preventDefault = this.fixEvent.preventDefault;
|
300
|
+
event.stopPropagation = this.fixEvent.stopPropagation;
|
303
301
|
return event;
|
304
302
|
};
|
305
|
-
|
303
|
+
JsUnitTest.Event.fixEvent.preventDefault = function() {
|
306
304
|
this.returnValue = false;
|
307
305
|
};
|
308
|
-
|
306
|
+
JsUnitTest.Event.fixEvent.stopPropagation = function() {
|
309
307
|
this.cancelBubble = true;
|
310
308
|
};
|
311
309
|
|
312
|
-
|
313
|
-
this.element =
|
310
|
+
JsUnitTest.Unit.Logger = function(element) {
|
311
|
+
this.element = JsUnitTest.$(element);
|
314
312
|
if (this.element) this._createLogTable();
|
315
313
|
};
|
316
314
|
|
317
|
-
|
315
|
+
JsUnitTest.Unit.Logger.prototype.start = function(testName) {
|
318
316
|
if (!this.element) return;
|
319
317
|
var tbody = this.element.getElementsByTagName('tbody')[0];
|
320
|
-
|
318
|
+
|
319
|
+
var tr = document.createElement('tr');
|
320
|
+
var td;
|
321
|
+
|
322
|
+
//testname
|
323
|
+
td = document.createElement('td');
|
324
|
+
td.appendChild(document.createTextNode(testName));
|
325
|
+
tr.appendChild(td)
|
326
|
+
|
327
|
+
tr.appendChild(document.createElement('td'));//status
|
328
|
+
tr.appendChild(document.createElement('td'));//message
|
329
|
+
|
330
|
+
tbody.appendChild(tr);
|
321
331
|
};
|
322
332
|
|
323
|
-
|
333
|
+
JsUnitTest.Unit.Logger.prototype.setStatus = function(status) {
|
324
334
|
var logline = this.getLastLogLine();
|
325
335
|
logline.className = status;
|
326
336
|
var statusCell = logline.getElementsByTagName('td')[1];
|
327
|
-
statusCell.
|
337
|
+
statusCell.appendChild(document.createTextNode(status));
|
328
338
|
};
|
329
339
|
|
330
|
-
|
340
|
+
JsUnitTest.Unit.Logger.prototype.finish = function(status, summary) {
|
331
341
|
if (!this.element) return;
|
332
342
|
this.setStatus(status);
|
333
343
|
this.message(summary);
|
334
344
|
};
|
335
345
|
|
336
|
-
|
346
|
+
JsUnitTest.Unit.Logger.prototype.message = function(message) {
|
337
347
|
if (!this.element) return;
|
338
348
|
var cell = this.getMessageCell();
|
349
|
+
|
350
|
+
// cell.appendChild(document.createTextNode(this._toHTML(message)));
|
339
351
|
cell.innerHTML = this._toHTML(message);
|
340
352
|
};
|
341
353
|
|
342
|
-
|
354
|
+
JsUnitTest.Unit.Logger.prototype.summary = function(summary) {
|
343
355
|
if (!this.element) return;
|
344
356
|
var div = this.element.getElementsByTagName('div')[0];
|
345
357
|
div.innerHTML = this._toHTML(summary);
|
346
358
|
};
|
347
359
|
|
348
|
-
|
360
|
+
JsUnitTest.Unit.Logger.prototype.getLastLogLine = function() {
|
349
361
|
var tbody = this.element.getElementsByTagName('tbody')[0];
|
350
362
|
var loglines = tbody.getElementsByTagName('tr');
|
351
363
|
return loglines[loglines.length - 1];
|
352
364
|
};
|
353
365
|
|
354
|
-
|
366
|
+
JsUnitTest.Unit.Logger.prototype.getMessageCell = function() {
|
355
367
|
var logline = this.getLastLogLine();
|
356
368
|
return logline.getElementsByTagName('td')[2];
|
357
369
|
};
|
358
370
|
|
359
|
-
|
371
|
+
JsUnitTest.Unit.Logger.prototype._createLogTable = function() {
|
360
372
|
var html = '<div class="logsummary">running...</div>' +
|
361
373
|
'<table class="logtable">' +
|
362
374
|
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
|
@@ -365,7 +377,7 @@ DrNicTest.Unit.Logger.prototype._createLogTable = function() {
|
|
365
377
|
this.element.innerHTML = html;
|
366
378
|
};
|
367
379
|
|
368
|
-
|
380
|
+
JsUnitTest.Unit.Logger.prototype.appendActionButtons = function(actions) {
|
369
381
|
// actions = $H(actions);
|
370
382
|
// if (!actions.any()) return;
|
371
383
|
// var div = new Element("div", {className: 'action_buttons'});
|
@@ -377,22 +389,22 @@ DrNicTest.Unit.Logger.prototype.appendActionButtons = function(actions) {
|
|
377
389
|
// this.getMessageCell().insert(div);
|
378
390
|
};
|
379
391
|
|
380
|
-
|
381
|
-
return
|
392
|
+
JsUnitTest.Unit.Logger.prototype._toHTML = function(txt) {
|
393
|
+
return JsUnitTest.escapeHTML(txt).replace(/\n/g,"<br/>");
|
382
394
|
};
|
383
|
-
|
395
|
+
JsUnitTest.Unit.MessageTemplate = function(string) {
|
384
396
|
var parts = [];
|
385
|
-
var str =
|
397
|
+
var str = JsUnitTest.scan((string || ''), /(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
|
386
398
|
parts.push(part[0]);
|
387
399
|
});
|
388
400
|
this.parts = parts;
|
389
401
|
};
|
390
402
|
|
391
|
-
|
403
|
+
JsUnitTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
|
392
404
|
var results = [];
|
393
405
|
for (var i=0; i < this.parts.length; i++) {
|
394
406
|
var part = this.parts[i];
|
395
|
-
var result = (part == '?') ?
|
407
|
+
var result = (part == '?') ? JsUnitTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
|
396
408
|
results.push(result);
|
397
409
|
};
|
398
410
|
return results.join('');
|
@@ -402,7 +414,7 @@ DrNicTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
|
|
402
414
|
// All of which are outline in the comments, below
|
403
415
|
// From John Resig's book Pro JavaScript Techniques
|
404
416
|
// published by Apress, 2006-8
|
405
|
-
|
417
|
+
JsUnitTest.ajax = function( options ) {
|
406
418
|
|
407
419
|
// Load the options object with defaults, if no
|
408
420
|
// values were provided by the user
|
@@ -518,11 +530,11 @@ DrNicTest.ajax = function( options ) {
|
|
518
530
|
}
|
519
531
|
|
520
532
|
}
|
521
|
-
|
533
|
+
JsUnitTest.Unit.Assertions = {
|
522
534
|
buildMessage: function(message, template) {
|
523
|
-
var args =
|
535
|
+
var args = JsUnitTest.arrayfromargs(arguments).slice(2);
|
524
536
|
return (message ? message + '\n' : '') +
|
525
|
-
new
|
537
|
+
new JsUnitTest.Unit.MessageTemplate(template).evaluate(args);
|
526
538
|
},
|
527
539
|
|
528
540
|
flunk: function(message) {
|
@@ -552,8 +564,8 @@ DrNicTest.Unit.Assertions = {
|
|
552
564
|
|
553
565
|
assertEnumEqual: function(expected, actual, message) {
|
554
566
|
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
|
555
|
-
var expected_array =
|
556
|
-
var actual_array =
|
567
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
568
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
557
569
|
this.assertBlock(message, function() {
|
558
570
|
if (expected_array.length == actual_array.length) {
|
559
571
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -567,8 +579,8 @@ DrNicTest.Unit.Assertions = {
|
|
567
579
|
|
568
580
|
assertEnumNotEqual: function(expected, actual, message) {
|
569
581
|
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
|
570
|
-
var expected_array =
|
571
|
-
var actual_array =
|
582
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
583
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
572
584
|
this.assertBlock(message, function() {
|
573
585
|
if (expected_array.length == actual_array.length) {
|
574
586
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -582,8 +594,8 @@ DrNicTest.Unit.Assertions = {
|
|
582
594
|
|
583
595
|
assertHashEqual: function(expected, actual, message) {
|
584
596
|
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
|
585
|
-
var expected_array =
|
586
|
-
var actual_array =
|
597
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
598
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
587
599
|
var block = function() {
|
588
600
|
if (expected_array.length == actual_array.length) {
|
589
601
|
for (var i=0; i < expected_array.length; i++) {
|
@@ -598,8 +610,8 @@ DrNicTest.Unit.Assertions = {
|
|
598
610
|
|
599
611
|
assertHashNotEqual: function(expected, actual, message) {
|
600
612
|
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
|
601
|
-
var expected_array =
|
602
|
-
var actual_array =
|
613
|
+
var expected_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(expected));
|
614
|
+
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
603
615
|
// from now we recursively zip & compare nested arrays
|
604
616
|
var block = function() {
|
605
617
|
if (expected_array.length == actual_array.length) {
|
@@ -665,7 +677,7 @@ DrNicTest.Unit.Assertions = {
|
|
665
677
|
|
666
678
|
assertHidden: function(element, message) {
|
667
679
|
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
|
668
|
-
this.assertBlock(message, function() { return element.style.display == 'none' });
|
680
|
+
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
|
669
681
|
},
|
670
682
|
|
671
683
|
assertInstanceOf: function(expected, actual, message) {
|
@@ -708,10 +720,10 @@ DrNicTest.Unit.Assertions = {
|
|
708
720
|
},
|
709
721
|
|
710
722
|
_isVisible: function(element) {
|
711
|
-
element =
|
723
|
+
element = JsUnitTest.$(element);
|
712
724
|
if(!element.parentNode) return true;
|
713
725
|
this.assertNotNull(element);
|
714
|
-
if(element.style && element.style.display == 'none')
|
726
|
+
if(element.style && (element.style.display == 'none'))
|
715
727
|
return false;
|
716
728
|
|
717
729
|
return arguments.callee.call(this, element.parentNode);
|
@@ -728,7 +740,7 @@ DrNicTest.Unit.Assertions = {
|
|
728
740
|
},
|
729
741
|
|
730
742
|
assertElementsMatch: function() {
|
731
|
-
var pass = true, expressions =
|
743
|
+
var pass = true, expressions = JsUnitTest.arrayfromargs(arguments);
|
732
744
|
var elements = expressions.shift();
|
733
745
|
if (elements.length != expressions.length) {
|
734
746
|
message = this.buildMessage('assertElementsMatch', 'size mismatch: ? elements, ? expressions (?).', elements.length, expressions.length, expressions);
|
@@ -737,8 +749,8 @@ DrNicTest.Unit.Assertions = {
|
|
737
749
|
}
|
738
750
|
for (var i=0; i < expressions.length; i++) {
|
739
751
|
var expression = expressions[i];
|
740
|
-
var element =
|
741
|
-
if (
|
752
|
+
var element = JsUnitTest.$(elements[i]);
|
753
|
+
if (JsUnitTest.selectorMatch(expression, element)) {
|
742
754
|
pass = true;
|
743
755
|
break;
|
744
756
|
}
|
@@ -753,28 +765,28 @@ DrNicTest.Unit.Assertions = {
|
|
753
765
|
this.assertElementsMatch([element], expression);
|
754
766
|
}
|
755
767
|
};
|
756
|
-
|
768
|
+
JsUnitTest.Unit.Runner = function(testcases) {
|
757
769
|
var argumentOptions = arguments[1] || {};
|
758
770
|
var options = this.options = {};
|
759
771
|
options.testLog = ('testLog' in argumentOptions) ? argumentOptions.testLog : 'testlog';
|
760
772
|
options.resultsURL = this.queryParams.resultsURL;
|
761
|
-
options.testLog =
|
773
|
+
options.testLog = JsUnitTest.$(options.testLog);
|
762
774
|
|
763
775
|
this.tests = this.getTests(testcases);
|
764
776
|
this.currentTest = 0;
|
765
|
-
this.logger = new
|
777
|
+
this.logger = new JsUnitTest.Unit.Logger(options.testLog);
|
766
778
|
|
767
779
|
var self = this;
|
768
|
-
|
780
|
+
JsUnitTest.Event.addEvent(window, "load", function() {
|
769
781
|
setTimeout(function() {
|
770
782
|
self.runTests();
|
771
783
|
}, 0.1);
|
772
784
|
});
|
773
785
|
};
|
774
786
|
|
775
|
-
|
787
|
+
JsUnitTest.Unit.Runner.prototype.queryParams = JsUnitTest.toQueryParams();
|
776
788
|
|
777
|
-
|
789
|
+
JsUnitTest.Unit.Runner.prototype.portNumber = function() {
|
778
790
|
if (window.location.search.length > 0) {
|
779
791
|
var matches = window.location.search.match(/\:(\d{3,5})\//);
|
780
792
|
if (matches) {
|
@@ -784,7 +796,7 @@ DrNicTest.Unit.Runner.prototype.portNumber = function() {
|
|
784
796
|
return null;
|
785
797
|
};
|
786
798
|
|
787
|
-
|
799
|
+
JsUnitTest.Unit.Runner.prototype.getTests = function(testcases) {
|
788
800
|
var tests = [], options = this.options;
|
789
801
|
if (this.queryParams.tests) tests = this.queryParams.tests.split(',');
|
790
802
|
else if (options.tests) tests = options.tests;
|
@@ -799,13 +811,13 @@ DrNicTest.Unit.Runner.prototype.getTests = function(testcases) {
|
|
799
811
|
var test = tests[i];
|
800
812
|
if (testcases[test])
|
801
813
|
results.push(
|
802
|
-
new
|
814
|
+
new JsUnitTest.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown)
|
803
815
|
);
|
804
816
|
};
|
805
817
|
return results;
|
806
818
|
};
|
807
819
|
|
808
|
-
|
820
|
+
JsUnitTest.Unit.Runner.prototype.getResult = function() {
|
809
821
|
var results = {
|
810
822
|
tests: this.tests.length,
|
811
823
|
assertions: 0,
|
@@ -822,7 +834,7 @@ DrNicTest.Unit.Runner.prototype.getResult = function() {
|
|
822
834
|
return results;
|
823
835
|
};
|
824
836
|
|
825
|
-
|
837
|
+
JsUnitTest.Unit.Runner.prototype.postResults = function() {
|
826
838
|
if (this.options.resultsURL) {
|
827
839
|
// new Ajax.Request(this.options.resultsURL,
|
828
840
|
// { method: 'get', parameters: this.getResult(), asynchronous: false });
|
@@ -831,14 +843,14 @@ DrNicTest.Unit.Runner.prototype.postResults = function() {
|
|
831
843
|
url += "assertions="+ results.assertions + "&";
|
832
844
|
url += "failures=" + results.failures + "&";
|
833
845
|
url += "errors=" + results.errors;
|
834
|
-
|
846
|
+
JsUnitTest.ajax({
|
835
847
|
url: url,
|
836
848
|
type: 'GET'
|
837
849
|
})
|
838
850
|
}
|
839
851
|
};
|
840
852
|
|
841
|
-
|
853
|
+
JsUnitTest.Unit.Runner.prototype.runTests = function() {
|
842
854
|
var test = this.tests[this.currentTest], actions;
|
843
855
|
|
844
856
|
if (!test) return this.finish();
|
@@ -861,15 +873,15 @@ DrNicTest.Unit.Runner.prototype.runTests = function() {
|
|
861
873
|
this.runTests();
|
862
874
|
};
|
863
875
|
|
864
|
-
|
876
|
+
JsUnitTest.Unit.Runner.prototype.finish = function() {
|
865
877
|
this.postResults();
|
866
878
|
this.logger.summary(this.summary());
|
867
879
|
};
|
868
880
|
|
869
|
-
|
870
|
-
return new
|
881
|
+
JsUnitTest.Unit.Runner.prototype.summary = function() {
|
882
|
+
return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors').evaluate(this.getResult());
|
871
883
|
};
|
872
|
-
|
884
|
+
JsUnitTest.Unit.Testcase = function(name, test, setup, teardown) {
|
873
885
|
this.name = name;
|
874
886
|
this.test = test || function() {};
|
875
887
|
this.setup = setup || function() {};
|
@@ -877,27 +889,27 @@ DrNicTest.Unit.Testcase = function(name, test, setup, teardown) {
|
|
877
889
|
this.messages = [];
|
878
890
|
this.actions = {};
|
879
891
|
};
|
880
|
-
// import
|
892
|
+
// import JsUnitTest.Unit.Assertions
|
881
893
|
|
882
|
-
for (method in
|
883
|
-
|
894
|
+
for (method in JsUnitTest.Unit.Assertions) {
|
895
|
+
JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
|
884
896
|
}
|
885
897
|
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
//
|
892
|
-
|
898
|
+
JsUnitTest.Unit.Testcase.prototype.isWaiting = false;
|
899
|
+
JsUnitTest.Unit.Testcase.prototype.timeToWait = 1000;
|
900
|
+
JsUnitTest.Unit.Testcase.prototype.assertions = 0;
|
901
|
+
JsUnitTest.Unit.Testcase.prototype.failures = 0;
|
902
|
+
JsUnitTest.Unit.Testcase.prototype.errors = 0;
|
903
|
+
// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
|
904
|
+
JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
|
893
905
|
|
894
|
-
|
906
|
+
JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
|
895
907
|
this.isWaiting = true;
|
896
908
|
this.test = nextPart;
|
897
909
|
this.timeToWait = time;
|
898
910
|
};
|
899
911
|
|
900
|
-
|
912
|
+
JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
|
901
913
|
try {
|
902
914
|
try {
|
903
915
|
if (!this.isWaiting) this.setup();
|
@@ -915,17 +927,17 @@ DrNicTest.Unit.Testcase.prototype.run = function(rethrow) {
|
|
915
927
|
}
|
916
928
|
};
|
917
929
|
|
918
|
-
|
930
|
+
JsUnitTest.Unit.Testcase.prototype.summary = function() {
|
919
931
|
var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
|
920
|
-
return new
|
932
|
+
return new JsUnitTest.Template(msg).evaluate(this) +
|
921
933
|
this.messages.join("\n");
|
922
934
|
};
|
923
935
|
|
924
|
-
|
936
|
+
JsUnitTest.Unit.Testcase.prototype.pass = function() {
|
925
937
|
this.assertions++;
|
926
938
|
};
|
927
939
|
|
928
|
-
|
940
|
+
JsUnitTest.Unit.Testcase.prototype.fail = function(message) {
|
929
941
|
this.failures++;
|
930
942
|
var line = "";
|
931
943
|
try {
|
@@ -936,23 +948,23 @@ DrNicTest.Unit.Testcase.prototype.fail = function(message) {
|
|
936
948
|
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
|
937
949
|
};
|
938
950
|
|
939
|
-
|
951
|
+
JsUnitTest.Unit.Testcase.prototype.info = function(message) {
|
940
952
|
this.messages.push("Info: " + message);
|
941
953
|
};
|
942
954
|
|
943
|
-
|
955
|
+
JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
|
944
956
|
this.errors++;
|
945
957
|
this.actions['retry with throw'] = function() { test.run(true) };
|
946
|
-
this.messages.push(error.name + ": "+ error.message + "(" +
|
958
|
+
this.messages.push(error.name + ": "+ error.message + "(" + JsUnitTest.inspect(error) + ")");
|
947
959
|
};
|
948
960
|
|
949
|
-
|
961
|
+
JsUnitTest.Unit.Testcase.prototype.status = function() {
|
950
962
|
if (this.failures > 0) return 'failed';
|
951
963
|
if (this.errors > 0) return 'error';
|
952
964
|
return 'passed';
|
953
965
|
};
|
954
966
|
|
955
|
-
|
967
|
+
JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
|
956
968
|
var startAt = new Date();
|
957
969
|
(iterations || 1).times(operation);
|
958
970
|
var timeTaken = ((new Date())-startAt);
|
@@ -961,4 +973,4 @@ DrNicTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
|
|
961
973
|
return timeTaken;
|
962
974
|
};
|
963
975
|
|
964
|
-
Test =
|
976
|
+
Test = JsUnitTest
|
data/website/index.html
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
<h1>JavaScript Project Generator</h1>
|
32
32
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/newjs"; return false'>
|
33
33
|
<p>Get Version</p>
|
34
|
-
<a href="http://rubyforge.org/projects/newjs" class="numbers">1.3.
|
34
|
+
<a href="http://rubyforge.org/projects/newjs" class="numbers">1.3.7</a>
|
35
35
|
</div>
|
36
36
|
<h1>→ ‘newjs’</h1>
|
37
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-04 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|