newjs 1.5.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +162 -14
- data/{README.txt → README.rdoc} +1 -1
- data/Rakefile +25 -3
- data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +41 -13
- data/app_generators/newjs_iphone/templates/Html/test/assets/unittest.css +4 -0
- data/features/development.feature +13 -0
- data/features/imported_files_for_generators.feature +19 -0
- data/features/steps/common.rb +205 -0
- data/features/steps/env.rb +6 -0
- data/javascript_test_generators/functional_test/functional_test_generator.rb +9 -1
- data/javascript_test_generators/functional_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/functional_test/templates/test/test.html.erb +15 -1
- data/javascript_test_generators/unit_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/unit_test/templates/test/test.html.erb +18 -20
- data/javascript_test_generators/unit_test/templates/test/test_jshoulda.html.erb +45 -0
- data/javascript_test_generators/unit_test/unit_test_generator.rb +11 -3
- data/lib/newjs.rb +3 -2
- data/newjs_iphone_generators/page/USAGE +5 -0
- data/newjs_iphone_generators/page/page_generator.rb +36 -0
- data/newjs_iphone_generators/page/templates/src/name.css.erb +0 -0
- data/newjs_iphone_generators/page/templates/src/name.html.erb +13 -0
- data/newjs_iphone_generators/page/templates/src/name.js.erb +4 -0
- data/newjs_iphone_generators/page/templates/test/fixtures/name.js.erb +5 -0
- data/newjs_iphone_generators/page/templates/test/unit/name_test.html.erb +61 -0
- data/rack_generators/javascript_test/USAGE +5 -0
- data/rack_generators/javascript_test/javascript_test_generator.rb +88 -0
- data/rack_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rack_generators/javascript_test/templates/assets/jsunittest.js +1004 -0
- data/rack_generators/javascript_test/templates/assets/unittest.css +54 -0
- data/rack_generators/javascript_test/templates/ext/jquery.js +3408 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets → rack_generators/javascript_test/templates/ext}/prototype.js +56 -122
- data/rack_generators/javascript_test/templates/library.js.erb +3 -0
- data/rack_generators/javascript_test/templates/test.html.erb +59 -0
- data/rack_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/rails_generators/javascript_test/javascript_test_generator.rb +15 -3
- data/rails_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rails_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/script/console +10 -0
- data/script/destroy +1 -1
- data/tasks/vendor/update/jshoulda.rake +18 -0
- data/tasks/vendor/update/jsunittest.rake +18 -0
- data/test/test_functional_test_generator.rb +13 -0
- data/test/test_generator_helper.rb +10 -1
- data/test/test_page_generator.rb +50 -0
- data/test/test_rack_javascript_test.rb +166 -0
- data/test/{test_javascript_test_generator.rb → test_rails_javascript_test_generator.rb} +15 -1
- data/test/test_unit_test_generator.rb +13 -0
- data/vendor/jshoulda/History.txt +108 -0
- data/vendor/jshoulda/License.txt +20 -0
- data/vendor/jshoulda/README.mdown +34 -0
- data/vendor/jshoulda/Rakefile +120 -0
- data/vendor/jshoulda/config/javascript_test_autotest.yml.sample +15 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.1.js +62 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.2.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.3.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.1.js +74 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.1.js +110 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.1.js +186 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.js +141 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.x.js +142 -0
- data/vendor/jshoulda/dist/jshoulda.js +186 -0
- data/vendor/jshoulda/jshoulda/test/basic_test.html +42 -0
- data/vendor/jshoulda/lib/jstest.rb +382 -0
- data/vendor/jshoulda/lib/protodoc.rb +36 -0
- data/vendor/jshoulda/script/destroy +14 -0
- data/vendor/jshoulda/script/generate +14 -0
- data/vendor/jshoulda/script/js_autotest +1 -0
- data/vendor/jshoulda/script/rstakeout +97 -0
- data/vendor/jshoulda/site/asset_defaults.yaml +6 -0
- data/vendor/jshoulda/site/config.yaml +3 -0
- data/vendor/jshoulda/site/content/content.html +27 -0
- data/vendor/jshoulda/site/content/content.yaml +4 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.html +268 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.yaml +4 -0
- data/vendor/jshoulda/site/css/blackboard.css +88 -0
- data/vendor/jshoulda/site/css/jshoulda_site.css +33 -0
- data/vendor/jshoulda/site/css/unittest.css +42 -0
- data/vendor/jshoulda/site/example/minimal.html +55 -0
- data/vendor/jshoulda/site/js/editable.js +42 -0
- data/vendor/jshoulda/site/layouts/default/default.html +29 -0
- data/vendor/jshoulda/site/layouts/default/default.yaml +4 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.js +18 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.yaml +4 -0
- data/vendor/jshoulda/site/lib/analytics.rb +12 -0
- data/vendor/jshoulda/site/lib/default.rb +2 -0
- data/vendor/jshoulda/site/lib/example.rb +10 -0
- data/vendor/jshoulda/site/lib/hash.rb +11 -0
- data/vendor/jshoulda/site/lib/highlight.rb +17 -0
- data/vendor/jshoulda/site/page_defaults.yaml +10 -0
- data/vendor/jshoulda/site/templates/default/default.html +1 -0
- data/vendor/jshoulda/site/templates/default/default.yaml +4 -0
- data/vendor/jshoulda/src/HEADER +8 -0
- data/vendor/jshoulda/src/jshoulda.js +177 -0
- data/vendor/jshoulda/src/jshoulda.js.erb +3 -0
- data/vendor/jshoulda/tasks/bundle.rake +12 -0
- data/vendor/jshoulda/tasks/demo.rake +9 -0
- data/vendor/jshoulda/tasks/deploy.rake +29 -0
- data/{tasks → vendor/jshoulda/tasks}/environment.rake +0 -0
- data/vendor/jshoulda/tasks/javascript_test_autotest_tasks.rake +45 -0
- data/vendor/jshoulda/tasks/site.rake +74 -0
- data/vendor/jshoulda/test/assets/jsunittest.js +1004 -0
- data/vendor/jshoulda/test/assets/prototype.js +4324 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets/unittest.js → vendor/jshoulda/test/assets/prototype_unittest.js} +15 -9
- data/vendor/jshoulda/test/assets/unittest.css +50 -0
- data/vendor/jshoulda/test/unit/factory_test.html +82 -0
- data/vendor/jshoulda/test/unit/jshoulda2_test.html +85 -0
- data/vendor/jshoulda/test/unit/jshoulda_prototype_test.html +87 -0
- data/vendor/jshoulda/test/unit/jshoulda_test.html +86 -0
- data/vendor/jshoulda/test/unit/merge_methods_test.html +77 -0
- data/vendor/jshoulda/test/unit/names_and_count.html +68 -0
- data/vendor/jshoulda/test/unit/no_config_test.html +57 -0
- data/vendor/jshoulda/test/unit/styles_test.html +77 -0
- data/vendor/jshoulda/test/unit/unify_runners.html +69 -0
- data/vendor/jshoulda/test/unit/unnamed_context_test.html +67 -0
- data/vendor/jsunittest/Capfile +4 -0
- data/vendor/jsunittest/History.txt +37 -0
- data/{License.txt → vendor/jsunittest/License.txt} +0 -0
- data/vendor/jsunittest/README.txt +21 -0
- data/vendor/jsunittest/Rakefile +118 -0
- data/vendor/jsunittest/config/deploy.rb +20 -0
- data/vendor/jsunittest/config/website.yml.sample +2 -0
- data/vendor/jsunittest/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/dist/unittest.css +54 -0
- data/vendor/jsunittest/lib/jstest.rb +390 -0
- data/vendor/jsunittest/lib/protodoc.rb +36 -0
- data/vendor/jsunittest/script/destroy +14 -0
- data/vendor/jsunittest/script/generate +14 -0
- data/vendor/jsunittest/script/js_autotest +1 -0
- data/vendor/jsunittest/script/rstakeout +97 -0
- data/vendor/jsunittest/script/txt2html +75 -0
- data/vendor/jsunittest/src/HEADER +8 -0
- data/vendor/jsunittest/src/ajax.js +121 -0
- data/vendor/jsunittest/src/assertions.js +244 -0
- data/vendor/jsunittest/src/common.js +191 -0
- data/vendor/jsunittest/src/jsunittest.js +1004 -0
- data/vendor/jsunittest/src/logger.js +86 -0
- data/vendor/jsunittest/src/message_template.js +17 -0
- data/vendor/jsunittest/src/orig/unittest.js +484 -0
- data/vendor/jsunittest/src/prototype/event.js +72 -0
- data/vendor/jsunittest/src/prototype/template.js +33 -0
- data/vendor/jsunittest/src/runner.js +120 -0
- data/vendor/jsunittest/src/test_case.js +106 -0
- data/vendor/jsunittest/tasks/deploy.rake +29 -0
- data/vendor/jsunittest/tasks/environment.rake +7 -0
- data/vendor/jsunittest/tasks/javascript_test_autotest_tasks.rake +44 -0
- data/vendor/jsunittest/tasks/tmbundle.rake +24 -0
- data/vendor/jsunittest/tasks/website.rake +53 -0
- data/vendor/jsunittest/test/assets/example_test.html +50 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/prototype.js +0 -0
- data/vendor/jsunittest/test/assets/unittest.css +54 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/unittest.js +0 -0
- data/vendor/jsunittest/test/functional/jsunittest_test.html +209 -0
- data/vendor/jsunittest/test/unit/assertions_test.html +202 -0
- data/vendor/jsunittest/test/unit/common_test.html +61 -0
- data/vendor/jsunittest/test/unit/logger_test.html +98 -0
- data/vendor/jsunittest/test/unit/message_template_test.html +44 -0
- data/vendor/jsunittest/test/unit/runner_test.html +77 -0
- data/vendor/jsunittest/test/unit/template_test.html +57 -0
- data/vendor/jsunittest/test/unit/test_case_test.html +97 -0
- data/vendor/jsunittest/website/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.tar.gz +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.zip +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/unittest.css +54 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/example_test.html +50 -0
- data/vendor/jsunittest/website/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
- data/vendor/jsunittest/website/images/passing_prototypejs_unittest_tests.jpg +0 -0
- data/vendor/jsunittest/website/index.html +94 -0
- data/vendor/jsunittest/website/index.txt +80 -0
- data/vendor/jsunittest/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/vendor/jsunittest/website/stylesheets/screen.css +138 -0
- data/vendor/jsunittest/website/template.html.erb +46 -0
- data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
- metadata +189 -24
- data/config/hoe.rb +0 -75
- data/config/requirements.rb +0 -17
- data/lib/newjs/version.rb +0 -9
- data/tasks/deployment.rake +0 -34
- data/tasks/jsunittest/update.rake +0 -18
- data/tasks/website.rake +0 -17
@@ -0,0 +1,72 @@
|
|
1
|
+
JsUnitTest.Event = {};
|
2
|
+
// written by Dean Edwards, 2005
|
3
|
+
// with input from Tino Zijdel, Matthias Miller, Diego Perini
|
4
|
+
// namespaced by Dr Nic Williams 2008
|
5
|
+
|
6
|
+
// http://dean.edwards.name/weblog/2005/10/add-event/
|
7
|
+
// http://dean.edwards.name/weblog/2005/10/add-event2/
|
8
|
+
JsUnitTest.Event.addEvent = function(element, type, handler) {
|
9
|
+
if (element.addEventListener) {
|
10
|
+
element.addEventListener(type, handler, false);
|
11
|
+
} else {
|
12
|
+
// assign each event handler a unique ID
|
13
|
+
if (!handler.$$guid) handler.$$guid = JsUnitTest.Event.addEvent.guid++;
|
14
|
+
// create a hash table of event types for the element
|
15
|
+
if (!element.events) element.events = {};
|
16
|
+
// create a hash table of event handlers for each element/event pair
|
17
|
+
var handlers = element.events[type];
|
18
|
+
if (!handlers) {
|
19
|
+
handlers = element.events[type] = {};
|
20
|
+
// store the existing event handler (if there is one)
|
21
|
+
if (element["on" + type]) {
|
22
|
+
handlers[0] = element["on" + type];
|
23
|
+
}
|
24
|
+
}
|
25
|
+
// store the event handler in the hash table
|
26
|
+
handlers[handler.$$guid] = handler;
|
27
|
+
// assign a global event handler to do all the work
|
28
|
+
element["on" + type] = this.handleEvent;
|
29
|
+
}
|
30
|
+
};
|
31
|
+
// a counter used to create unique IDs
|
32
|
+
JsUnitTest.Event.addEvent.guid = 1;
|
33
|
+
|
34
|
+
JsUnitTest.Event.removeEvent = function(element, type, handler) {
|
35
|
+
if (element.removeEventListener) {
|
36
|
+
element.removeEventListener(type, handler, false);
|
37
|
+
} else {
|
38
|
+
// delete the event handler from the hash table
|
39
|
+
if (element.events && element.events[type]) {
|
40
|
+
delete element.events[type][handler.$$guid];
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
JsUnitTest.Event.handleEvent = function(event) {
|
46
|
+
var returnValue = true;
|
47
|
+
// grab the event object (IE uses a global event object)
|
48
|
+
event = event || JsUnitTest.Event.fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
49
|
+
// get a reference to the hash table of event handlers
|
50
|
+
var handlers = this.events[event.type];
|
51
|
+
// execute each event handler
|
52
|
+
for (var i in handlers) {
|
53
|
+
this.$$handleEvent = handlers[i];
|
54
|
+
if (this.$$handleEvent(event) === false) {
|
55
|
+
returnValue = false;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return returnValue;
|
59
|
+
};
|
60
|
+
|
61
|
+
JsUnitTest.Event.fixEvent = function(event) {
|
62
|
+
// add W3C standard event methods
|
63
|
+
event.preventDefault = this.fixEvent.preventDefault;
|
64
|
+
event.stopPropagation = this.fixEvent.stopPropagation;
|
65
|
+
return event;
|
66
|
+
};
|
67
|
+
JsUnitTest.Event.fixEvent.preventDefault = function() {
|
68
|
+
this.returnValue = false;
|
69
|
+
};
|
70
|
+
JsUnitTest.Event.fixEvent.stopPropagation = function() {
|
71
|
+
this.cancelBubble = true;
|
72
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
JsUnitTest.Template = function(template, pattern) {
|
2
|
+
this.template = template; //template.toString();
|
3
|
+
this.pattern = pattern || JsUnitTest.Template.Pattern;
|
4
|
+
};
|
5
|
+
|
6
|
+
JsUnitTest.Template.prototype.evaluate = function(object) {
|
7
|
+
if (typeof object.toTemplateReplacements == "function")
|
8
|
+
object = object.toTemplateReplacements();
|
9
|
+
|
10
|
+
return JsUnitTest.gsub(this.template, this.pattern, function(match) {
|
11
|
+
if (object == null) return '';
|
12
|
+
|
13
|
+
var before = match[1] || '';
|
14
|
+
if (before == '\\') return match[2];
|
15
|
+
|
16
|
+
var ctx = object, expr = match[3];
|
17
|
+
var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
|
18
|
+
match = pattern.exec(expr);
|
19
|
+
if (match == null) return before;
|
20
|
+
|
21
|
+
while (match != null) {
|
22
|
+
var comp = (match[1].indexOf('[]') === 0) ? match[2].gsub('\\\\]', ']') : match[1];
|
23
|
+
ctx = ctx[comp];
|
24
|
+
if (null == ctx || '' == match[3]) break;
|
25
|
+
expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
|
26
|
+
match = pattern.exec(expr);
|
27
|
+
}
|
28
|
+
|
29
|
+
return before + JsUnitTest.String.interpret(ctx);
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
JsUnitTest.Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
@@ -0,0 +1,120 @@
|
|
1
|
+
JsUnitTest.Unit.Runner = function(testcases) {
|
2
|
+
var argumentOptions = arguments[1] || {};
|
3
|
+
var options = this.options = {};
|
4
|
+
options.testLog = ('testLog' in argumentOptions) ? argumentOptions.testLog : 'testlog';
|
5
|
+
options.resultsURL = this.queryParams.resultsURL;
|
6
|
+
options.testLog = JsUnitTest.$(options.testLog);
|
7
|
+
|
8
|
+
this.tests = this.getTests(testcases);
|
9
|
+
this.currentTest = 0;
|
10
|
+
this.logger = new JsUnitTest.Unit.Logger(options.testLog);
|
11
|
+
|
12
|
+
var self = this;
|
13
|
+
JsUnitTest.Event.addEvent(window, "load", function() {
|
14
|
+
setTimeout(function() {
|
15
|
+
self.runTests();
|
16
|
+
}, 0.1);
|
17
|
+
});
|
18
|
+
};
|
19
|
+
|
20
|
+
JsUnitTest.Unit.Runner.prototype.queryParams = JsUnitTest.toQueryParams();
|
21
|
+
|
22
|
+
JsUnitTest.Unit.Runner.prototype.portNumber = function() {
|
23
|
+
if (window.location.search.length > 0) {
|
24
|
+
var matches = window.location.search.match(/\:(\d{3,5})\//);
|
25
|
+
if (matches) {
|
26
|
+
return parseInt(matches[1]);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return null;
|
30
|
+
};
|
31
|
+
|
32
|
+
JsUnitTest.Unit.Runner.prototype.getTests = function(testcases) {
|
33
|
+
var tests = [], options = this.options;
|
34
|
+
if (this.queryParams.tests) tests = this.queryParams.tests.split(',');
|
35
|
+
else if (options.tests) tests = options.tests;
|
36
|
+
else if (options.test) tests = [option.test];
|
37
|
+
else {
|
38
|
+
for (testname in testcases) {
|
39
|
+
if (testname.match(/^test/)) tests.push(testname);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
var results = [];
|
43
|
+
for (var i=0; i < tests.length; i++) {
|
44
|
+
var test = tests[i];
|
45
|
+
if (testcases[test])
|
46
|
+
results.push(
|
47
|
+
new JsUnitTest.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown)
|
48
|
+
);
|
49
|
+
};
|
50
|
+
return results;
|
51
|
+
};
|
52
|
+
|
53
|
+
JsUnitTest.Unit.Runner.prototype.getResult = function() {
|
54
|
+
var results = {
|
55
|
+
tests: this.tests.length,
|
56
|
+
assertions: 0,
|
57
|
+
failures: 0,
|
58
|
+
errors: 0,
|
59
|
+
warnings: 0
|
60
|
+
};
|
61
|
+
|
62
|
+
for (var i=0; i < this.tests.length; i++) {
|
63
|
+
var test = this.tests[i];
|
64
|
+
results.assertions += test.assertions;
|
65
|
+
results.failures += test.failures;
|
66
|
+
results.errors += test.errors;
|
67
|
+
results.warnings += test.warnings;
|
68
|
+
};
|
69
|
+
return results;
|
70
|
+
};
|
71
|
+
|
72
|
+
JsUnitTest.Unit.Runner.prototype.postResults = function() {
|
73
|
+
if (this.options.resultsURL) {
|
74
|
+
// new Ajax.Request(this.options.resultsURL,
|
75
|
+
// { method: 'get', parameters: this.getResult(), asynchronous: false });
|
76
|
+
var results = this.getResult();
|
77
|
+
var url = this.options.resultsURL + "?";
|
78
|
+
url += "tests="+ this.tests.length + "&";
|
79
|
+
url += "assertions="+ results.assertions + "&";
|
80
|
+
url += "warnings=" + results.warnings + "&";
|
81
|
+
url += "failures=" + results.failures + "&";
|
82
|
+
url += "errors=" + results.errors;
|
83
|
+
JsUnitTest.ajax({
|
84
|
+
url: url,
|
85
|
+
type: 'GET'
|
86
|
+
})
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
JsUnitTest.Unit.Runner.prototype.runTests = function() {
|
91
|
+
var test = this.tests[this.currentTest], actions;
|
92
|
+
|
93
|
+
if (!test) return this.finish();
|
94
|
+
if (!test.isWaiting) this.logger.start(test.name);
|
95
|
+
test.run();
|
96
|
+
var self = this;
|
97
|
+
if(test.isWaiting) {
|
98
|
+
this.logger.message("Waiting for " + test.timeToWait + "ms");
|
99
|
+
// setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
|
100
|
+
setTimeout(function() {
|
101
|
+
self.runTests();
|
102
|
+
}, test.timeToWait || 1000);
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
|
106
|
+
this.logger.finish(test.status(), test.summary());
|
107
|
+
if (actions = test.actions) this.logger.appendActionButtons(actions);
|
108
|
+
this.currentTest++;
|
109
|
+
// tail recursive, hopefully the browser will skip the stackframe
|
110
|
+
this.runTests();
|
111
|
+
};
|
112
|
+
|
113
|
+
JsUnitTest.Unit.Runner.prototype.finish = function() {
|
114
|
+
this.postResults();
|
115
|
+
this.logger.summary(this.summary());
|
116
|
+
};
|
117
|
+
|
118
|
+
JsUnitTest.Unit.Runner.prototype.summary = function() {
|
119
|
+
return new JsUnitTest.Template('#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings').evaluate(this.getResult());
|
120
|
+
};
|
@@ -0,0 +1,106 @@
|
|
1
|
+
JsUnitTest.Unit.Testcase = function(name, test, setup, teardown) {
|
2
|
+
this.name = name;
|
3
|
+
this.test = test || function() {};
|
4
|
+
this.setup = setup || function() {};
|
5
|
+
this.teardown = teardown || function() {};
|
6
|
+
this.messages = [];
|
7
|
+
this.actions = {};
|
8
|
+
};
|
9
|
+
// import JsUnitTest.Unit.Assertions
|
10
|
+
|
11
|
+
for (method in JsUnitTest.Unit.Assertions) {
|
12
|
+
JsUnitTest.Unit.Testcase.prototype[method] = JsUnitTest.Unit.Assertions[method];
|
13
|
+
}
|
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.warnings = 0;
|
21
|
+
JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port;
|
22
|
+
|
23
|
+
// JsUnitTest.Unit.Testcase.prototype.isRunningFromRake = window.location.port == 4711;
|
24
|
+
|
25
|
+
JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
|
26
|
+
this.isWaiting = true;
|
27
|
+
this.test = nextPart;
|
28
|
+
this.timeToWait = time;
|
29
|
+
};
|
30
|
+
|
31
|
+
JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
|
32
|
+
try {
|
33
|
+
try {
|
34
|
+
if (!this.isWaiting) this.setup();
|
35
|
+
this.isWaiting = false;
|
36
|
+
this.test();
|
37
|
+
} finally {
|
38
|
+
if(!this.isWaiting) {
|
39
|
+
this.teardown();
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
catch(e) {
|
44
|
+
if (rethrow) throw e;
|
45
|
+
this.error(e, this);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
JsUnitTest.Unit.Testcase.prototype.summary = function() {
|
50
|
+
var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors, #{warnings} warnings\n';
|
51
|
+
return new JsUnitTest.Template(msg).evaluate(this) +
|
52
|
+
this.messages.join("\n");
|
53
|
+
};
|
54
|
+
|
55
|
+
JsUnitTest.Unit.Testcase.prototype.pass = function() {
|
56
|
+
this.assertions++;
|
57
|
+
};
|
58
|
+
|
59
|
+
JsUnitTest.Unit.Testcase.prototype.fail = function(message) {
|
60
|
+
this.failures++;
|
61
|
+
var line = "";
|
62
|
+
try {
|
63
|
+
throw new Error("stack");
|
64
|
+
} catch(e){
|
65
|
+
line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
|
66
|
+
}
|
67
|
+
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
|
68
|
+
};
|
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
|
+
|
82
|
+
JsUnitTest.Unit.Testcase.prototype.info = function(message) {
|
83
|
+
this.messages.push("Info: " + message);
|
84
|
+
};
|
85
|
+
|
86
|
+
JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
|
87
|
+
this.errors++;
|
88
|
+
this.actions['retry with throw'] = function() { test.run(true) };
|
89
|
+
this.messages.push(error.name + ": "+ error.message + "(" + JsUnitTest.inspect(error) + ")");
|
90
|
+
};
|
91
|
+
|
92
|
+
JsUnitTest.Unit.Testcase.prototype.status = function() {
|
93
|
+
if (this.failures > 0) return 'failed';
|
94
|
+
if (this.errors > 0) return 'error';
|
95
|
+
if (this.warnings > 0) return 'warning';
|
96
|
+
return 'passed';
|
97
|
+
};
|
98
|
+
|
99
|
+
JsUnitTest.Unit.Testcase.prototype.benchmark = function(operation, iterations) {
|
100
|
+
var startAt = new Date();
|
101
|
+
(iterations || 1).times(operation);
|
102
|
+
var timeTaken = ((new Date())-startAt);
|
103
|
+
this.info((arguments[2] || 'Operation') + ' finished ' +
|
104
|
+
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
|
105
|
+
return timeTaken;
|
106
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
desc 'Package and upload the release to rubyforge.'
|
2
|
+
task :release => [:clean, :dist, :package] do |t|
|
3
|
+
require 'rubyforge'
|
4
|
+
version = APP_VERSION
|
5
|
+
name = APP_NAME
|
6
|
+
rubyforge_name = RUBYFORGE_PROJECT
|
7
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
8
|
+
abort "Versions don't match #{v} vs #{version}" if v != version
|
9
|
+
pkg = "pkg/#{name}-#{version}"
|
10
|
+
|
11
|
+
if $DEBUG then
|
12
|
+
puts "release_id = rf.add_release #{rubyforge_name.inspect}, #{name.inspect}, #{version.inspect}, \"#{pkg}.tgz\""
|
13
|
+
puts "rf.add_file #{rubyforge_name.inspect}, #{name.inspect}, release_id, \"#{pkg}.gem\""
|
14
|
+
end
|
15
|
+
|
16
|
+
rf = RubyForge.new
|
17
|
+
puts "Logging in"
|
18
|
+
rf.login
|
19
|
+
|
20
|
+
c = rf.userconfig
|
21
|
+
c["release_notes"] = APP_DESCRIPTION if Object.const_defined?("APP_DESCRIPTION")
|
22
|
+
c["release_changes"] = APP_CHANGES if Object.const_defined?("APP_CHANGES")
|
23
|
+
c["preformatted"] = true
|
24
|
+
|
25
|
+
files = ["#{pkg}.tar.gz", "dist/#{name}-#{version}.js"].compact
|
26
|
+
|
27
|
+
puts "Releasing #{name} v. #{version}"
|
28
|
+
rf.add_release rubyforge_name, name, version, *files
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
TEST_CHANGES_SINCE = Time.now - 600
|
2
|
+
|
3
|
+
namespace :test do
|
4
|
+
namespace :recent do
|
5
|
+
desc "Open recently modified files into browser"
|
6
|
+
task :javascript do
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'activesupport'
|
9
|
+
require 'active_support'
|
10
|
+
|
11
|
+
since = TEST_CHANGES_SINCE
|
12
|
+
touched = FileList[
|
13
|
+
'test/unit/*_test.html',
|
14
|
+
'src/*.js'].select { |path| File.mtime(path) > since }
|
15
|
+
next if touched.blank?
|
16
|
+
|
17
|
+
gem 'newjs'
|
18
|
+
require 'newjs'
|
19
|
+
require 'newjs/autotest'
|
20
|
+
|
21
|
+
touched.each do |file|
|
22
|
+
if file =~ /\/([^\/]+)\.js$/
|
23
|
+
file = "test/unit/#{$1}_test.html"
|
24
|
+
end
|
25
|
+
file = "#{APP_ROOT}/#{file}"
|
26
|
+
unless File.exists?(file)
|
27
|
+
puts "Notice: Test file does not exist: #{file}"
|
28
|
+
next
|
29
|
+
end
|
30
|
+
browsers = JavascriptTestAutotest::Config.get :browsers
|
31
|
+
if browsers.blank?
|
32
|
+
puts "WARNING: No browsers setup in config/javascript_test_autotest.yml"
|
33
|
+
next
|
34
|
+
end
|
35
|
+
browsers.each_pair do |name, path|
|
36
|
+
browser = JavascriptTestAutotest::Browser.browser(name, path)
|
37
|
+
browser.setup
|
38
|
+
browser.visit(file)
|
39
|
+
browser.teardown
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
namespace :bundle do
|
2
|
+
bundle_git_repo = "git://github.com/drnic/javascript-unittest-tmbundle.git"
|
3
|
+
bundle_dir = "website/tmbundle"
|
4
|
+
bundle_name = 'JavaScript\ Unit\ Testing.tmbundle'
|
5
|
+
bundle_clone_dir = "#{bundle_dir}/#{bundle_name}"
|
6
|
+
desc "Import TM bundle into website/ and compress"
|
7
|
+
task :import => [:setup, :fetch, :compress]
|
8
|
+
|
9
|
+
task :setup do
|
10
|
+
FileUtils.mkdir_p bundle_dir
|
11
|
+
end
|
12
|
+
|
13
|
+
task :fetch do
|
14
|
+
puts cmd = "git clone #{bundle_git_repo} #{bundle_clone_dir}"
|
15
|
+
`#{cmd}`
|
16
|
+
end
|
17
|
+
|
18
|
+
task :compress do
|
19
|
+
chdir(bundle_dir) do
|
20
|
+
sh %{tar zcvf #{bundle_name}.tar.gz #{bundle_name} }
|
21
|
+
end
|
22
|
+
`rm -rf #{bundle_clone_dir}`
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
def website_config
|
4
|
+
unless @website_config
|
5
|
+
begin
|
6
|
+
@website_config = YAML.load(File.read(File.expand_path(File.dirname(__FILE__) + "/../config/website.yml")))
|
7
|
+
rescue
|
8
|
+
puts <<-EOS
|
9
|
+
To upload your website to a host, you need to configure
|
10
|
+
config/website.yml. See config/website.yml.sample for
|
11
|
+
an example.
|
12
|
+
EOS
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
@website_config
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Generate website files + associated packages + bundles'
|
20
|
+
task :website_build => [:ruby_env, :dist, :website_package, "bundle:import", :website_generate]
|
21
|
+
|
22
|
+
task :website_generate => :ruby_env do
|
23
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
24
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
task :website_package do
|
29
|
+
website_package = "#{APP_NAME}-getting-started"
|
30
|
+
website_package_src = "website/dist/#{website_package}"
|
31
|
+
FileUtils.mkdir_p "#{website_package_src}/assets", :verbose => true
|
32
|
+
FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_FILE_NAME}"
|
33
|
+
FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_NAME}-#{APP_VERSION}.js"
|
34
|
+
|
35
|
+
FileUtils.copy_file "dist/#{APP_FILE_NAME}", "#{website_package_src}/assets/#{APP_FILE_NAME}"
|
36
|
+
FileUtils.copy_file "test/assets/unittest.css", "#{website_package_src}/assets/unittest.css"
|
37
|
+
FileUtils.copy_file "test/assets/example_test.html","#{website_package_src}/example_test.html"
|
38
|
+
chdir(website_package_src) do
|
39
|
+
sh %{tar zcvf ../#{website_package}.tar.gz .}
|
40
|
+
sh %{zip -r ../#{website_package}.zip .}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Upload website files to rubyforge'
|
45
|
+
task :website_upload do
|
46
|
+
host = website_config["host"] # "#{rubyforge_username}@rubyforge.org"
|
47
|
+
remote_dir = website_config["remote_dir"] # "/var/www/gforge-projects/#{PATH}/"
|
48
|
+
local_dir = 'website'
|
49
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Generate and upload website files'
|
53
|
+
task :website => [:website_build, :website_upload]
|