Browse files

Updated to run the jQuery test runner. The runner goes to completion …

…now (for core, selectors, and events) although only selectors and events completely pass.
  • Loading branch information...
1 parent a2175bb commit 76ce0a77bb0541745d79a73cd8ae2faa33f69590 John Resig committed Jun 17, 2008
Showing with 111 additions and 10 deletions.
  1. +3 −0 Makefile
  2. +41 −4 src/env.js
  3. +52 −0 test/debug.js
  4. +4 −4 test/test.js
  5. +9 −2 test/testrunner.js
  6. +2 −0 test/unit/core.js
View
3 Makefile
@@ -6,3 +6,6 @@ JAR = java -jar rhino/js.jar
test-rhino:
@@${JAR} ${TEST}
+
+run-rhino:
+ echo "load('src/env.js');window.location='test/index.html';" | ${JAR}
View
45 src/env.js
@@ -143,6 +143,9 @@ var window = this;
};
DOMDocument.prototype = {
+ get nodeType(){
+ return 9;
+ },
createTextNode: function(text){
return makeNode( this._dom.createTextNode(
text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")) );
@@ -154,6 +157,19 @@ var window = this;
return new DOMNodeList( this._dom.getElementsByTagName(
name.toLowerCase()) );
},
+ getElementsByName: function(name){
+ var elems = this._dom.getElementsByTagName("*"), ret = [];
+ ret.item = function(i){ return this[i]; };
+ ret.getLength = function(){ return this.length; };
+
+ for ( var i = 0; i < elems.length; i++ ) {
+ var elem = elems.item(i);
+ if ( elem.getAttribute("name") == name )
+ ret.push( elem );
+ }
+
+ return new DOMNodeList( ret );
+ },
getElementById: function(id){
var elems = this._dom.getElementsByTagName("*");
@@ -264,6 +280,9 @@ var window = this;
get nodeName() {
return this._dom.getNodeName();
},
+ get childNodes(){
+ return new DOMNodeList( this._dom.getChildNodes() );
+ },
cloneNode: function(deep){
return makeNode( this._dom.cloneNode(deep) );
},
@@ -290,6 +309,19 @@ var window = this;
}
};
+ window.DOMComment = function(node){
+ this._dom = node;
+ };
+
+ DOMComment.prototype = extend(new DOMNode(), {
+ get nodeType(){
+ return 8;
+ },
+ get outerHTML(){
+ return "<!--" + this.nodeValue + "-->";
+ }
+ });
+
// DOM Element
window.DOMElement = function(elem){
@@ -349,7 +381,7 @@ var window = this;
set innerHTML(html){
html = html.replace(/<\/?([A-Z]+)/g, function(m){
return m.toLowerCase();
- });
+ }).replace(/&nbsp;/g, " ");
var nodes = this.ownerDocument.importNode(
new DOMDocument( new java.io.ByteArrayInputStream(
@@ -505,6 +537,9 @@ var window = this;
get elements(){
return this.getElementsByTagName("*");
},
+ get options(){
+ return this.getElementsByTagName("option");
+ },
get contentWindow(){
return this.nodeName == "IFRAME" ? {
document: this.contentDocument
@@ -548,9 +583,11 @@ var window = this;
function makeNode(node){
if ( node ) {
if ( !obj_nodes.containsKey( node ) )
- obj_nodes.put( node, node.getNodeType() ==
- Packages.org.w3c.dom.Node.ELEMENT_NODE ?
- new DOMElement( node ) : new DOMNode( node ) );
+ obj_nodes.put( node, node.getNodeType() == 1?
+ new DOMElement( node ) :
+ node.getNodeType() == 8 ?
+ new DOMComment( node ) :
+ new DOMNode( node ) );
return obj_nodes.get(node);
} else
View
52 test/debug.js
@@ -0,0 +1,52 @@
+// Init
+load("src/env.js");
+
+window.location = "test/index.html";
+
+window.onload = function(){
+ load("test/testrunner.js");
+ load("test/jquery.js");
+
+ var depth = 0;
+
+ function indent(){
+ var str = "";
+ for ( var i = 0; i < depth; i++ ) {
+ str += " ";
+ }
+ return str;
+ }
+
+ function dump(name, args, ret){
+ print(name + ": " + Array.prototype.slice.call(args) + " - Return: " + ret);
+ }
+
+ for ( var method in jQuery.fn ) (function(method){ if ( method != "init" ) {
+ var old = jQuery.fn[method];
+ jQuery.fn[method] = function(){
+ print(indent() + method + ": " + Array.prototype.slice.call(arguments));
+ depth++;
+ var ret = old.apply(this, arguments);
+ depth--;
+ print(indent() + method + ": Return " + ret);
+ return ret;
+ };
+ } })(method);
+
+ for ( var method in jQuery ) (function(method){ if ( method != "prototype" && method != "fn" ) {
+ var old = jQuery[method];
+ jQuery[method] = function(){
+ print(indent() + "$." + method + ": " + Array.prototype.slice.call(arguments));
+ depth++;
+ var ret = old.apply(this, arguments);
+ depth--;
+ print(indent() + "$." + method + ": Return " + ret);
+ return ret;
+ };
+ } })(method);
+
+ jQuery.prototype.toString = DOMNodeList.prototype.toString;
+ Function.prototype.toString = function(){ return "function()"; };
+
+ print("Ready.");
+};
View
8 test/test.js
@@ -5,13 +5,13 @@ window.location = "test/index.html";
window.onload = function(){
// Load the test runner
- load("test/jquery.js","test/testrunner.js");
+ load("test/testrunner.js", "test/jquery.js");
// Load the tests
load(
- "test/unit/core.js"
- //"test/unit/selector.js",
- //"test/unit/event.js",
+ "test/unit/core.js",
+ "test/unit/selector.js",
+ "test/unit/event.js"
//"test/unit/fx.js",
//"test/unit/ajax.js"
);
View
11 test/testrunner.js
@@ -1,3 +1,10 @@
+var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
+ $ = this.$ || "$",
+ originaljQuery = jQuery,
+ original$ = $;
+
+var isLocal = true;
+
function test(name, fn){
expected = -1;
numTests = 0;
@@ -138,7 +145,7 @@ function t(a,b,c) {
function equals(expected, actual, message) {
var result = expected == actual;
message = message || (result ? "okay" : "failed");
- log( result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual );
+ log( result, result ? message + ": " + expected : message + " actual: " + expected + " expected: " + actual );
}
var numTests = 0, total = 0, pass = 0, fail = 0;
@@ -194,4 +201,4 @@ function triggerEvent( elem, type, event ) {
*/
function url(value) {
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
-}
+}
View
2 test/unit/core.js
@@ -1388,6 +1388,8 @@ test("text(String)", function() {
expect(4);
equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
+print(jQuery("#nonnodes")[0].innerHTML);
+
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
j.text("hi!");

0 comments on commit 76ce0a7

Please sign in to comment.