Commit 7448c61e authored by John Resig's avatar John Resig

Massive overhauls to the test suite - it is now generated dynamically, along...

Massive overhauls to the test suite - it is now generated dynamically, along with the documentation.
parent 61aab47b
...@@ -6,14 +6,18 @@ DOCS_DIR = ${PREFIX}/docs ...@@ -6,14 +6,18 @@ DOCS_DIR = ${PREFIX}/docs
TEST_DIR = ${PREFIX}/test TEST_DIR = ${PREFIX}/test
DIST_DIR = ${PREFIX}/dist DIST_DIR = ${PREFIX}/dist
MODULES = jquery event fx ajax MODULES = ${SRC_DIR}/jquery/*\
${SRC_DIR}/event/*\
${SRC_DIR}/fx/*\
${SRC_DIR}/ajax/*
JQ = ${DIST_DIR}/jquery.js JQ = ${DIST_DIR}/jquery.js
JQ_LITE = ${DIST_DIR}/jquery.lite.js JQ_LITE = ${DIST_DIR}/jquery.lite.js
JQ_PACK = ${DIST_DIR}/jquery.pack.js JQ_PACK = ${DIST_DIR}/jquery.pack.js
JAR = java -jar ${BUILD_DIR}/js.jar JAR = java -jar ${BUILD_DIR}/js.jar
all: jquery lite pack docs all: jquery lite pack docs test
@@echo "jQuery build complete." @@echo "jQuery build complete."
${DIST_DIR}: ${DIST_DIR}:
...@@ -21,32 +25,34 @@ ${DIST_DIR}: ...@@ -21,32 +25,34 @@ ${DIST_DIR}:
jquery: ${DIST_DIR} ${JQ} jquery: ${DIST_DIR} ${JQ}
${JQ}: ${JQ}: ${MODULES}
@@echo "Building" ${JQ} @@echo "Building" ${JQ}
@@for f in ${MODULES}; do \ @@mkdir -p ${DIST_DIR}
echo " - Adding module:" $$f;\ @@cat ${MODULES} > ${JQ};
cat ${SRC_DIR}/$$f/$$f.js >> ${JQ};\
done
@@echo ${JQ} "Built" @@echo ${JQ} "Built"
@@echo @@echo
lite: ${JQ_LITE} lite: ${JQ_LITE}
${JQ_LITE}: jquery ${JQ_LITE}: ${JQ}
@@echo "Building" ${JQ_LITE} @@echo "Building" ${JQ_LITE}
@@echo " - Removing ScriptDoc from" ${JQ} @@echo " - Removing ScriptDoc from" ${JQ}
@@${JAR} ${BUILD_DIR}/build/lite.js ${JQ} ${JQ_LITE} @@${JAR} ${BUILD_DIR}/build/lite.js ${JQ} ${JQ_LITE}
@@echo ${JQ_LITE} "Built" @@echo ${JQ_LITE} "Built"
@@echo @@echo
pack: ${JQ_PACK} pack: ${JQ_PACK}
${JQ_PACK}: jquery ${JQ_PACK}: ${JQ}
@@echo "Building" ${JQ_PACK} @@echo "Building" ${JQ_PACK}
@@echo " - Compressing using Packer" @@echo " - Compressing using Packer"
@@${JAR} ${BUILD_DIR}/build/pack.js ${JQ} ${JQ_PACK} @@${JAR} ${BUILD_DIR}/build/pack.js ${JQ} ${JQ_PACK}
@@echo ${JQ_PACK} "Built" @@echo ${JQ_PACK} "Built"
@@echo @@echo
...@@ -55,9 +61,13 @@ test: ${JQ} ...@@ -55,9 +61,13 @@ test: ${JQ}
@@echo " - Making Test Suite Directory:" ${TEST_DIR} @@echo " - Making Test Suite Directory:" ${TEST_DIR}
@@mkdir -p ${TEST_DIR} @@mkdir -p ${TEST_DIR}
@@mkdir -p ${TEST_DIR}/tests/
@@echo " - Removing any old tests"
@@rm -f ${TEST_DIR}/tests/*
@@echo " - Copying over script files." @@echo " - Copying over script files."
@@cp -R ${BUILD_DIR}/test/js ${TEST_DIR}/js @@cp -nR ${BUILD_DIR}/test/js ${TEST_DIR}/js
@@echo " - Compiling Test Cases" @@echo " - Compiling Test Cases"
@@${JAR} ${BUILD_DIR}/test/test.js ${JQ} ${TEST_DIR} @@${JAR} ${BUILD_DIR}/test/test.js ${JQ} ${TEST_DIR}
...@@ -73,10 +83,10 @@ docs: ${JQ} ...@@ -73,10 +83,10 @@ docs: ${JQ}
@@mkdir -p ${DOCS_DIR}/data @@mkdir -p ${DOCS_DIR}/data
@@echo " - Copying over script files." @@echo " - Copying over script files."
@@cp -R ${BUILD_DIR}/docs/js ${DOCS_DIR}/js @@cp -nR ${BUILD_DIR}/docs/js ${DOCS_DIR}/js
@@echo " - Copying over style files." @@echo " - Copying over style files."
@@cp -R ${BUILD_DIR}/docs/style ${DOCS_DIR}/style @@cp -nR ${BUILD_DIR}/docs/style ${DOCS_DIR}/style
@@echo " - Extracting ScriptDoc from" ${JQ} @@echo " - Extracting ScriptDoc from" ${JQ}
@@${JAR} ${BUILD_DIR}/docs/docs.js ${JQ} ${DOCS_DIR} @@${JAR} ${BUILD_DIR}/docs/docs.js ${JQ} ${DOCS_DIR}
......
load("build/js/json.js", "build/js/xml.js", "build/js/writeFile.js"); load("build/js/json.js", "build/js/xml.js", "build/js/writeFile.js", "build/js/parse.js");
var types = {
jQuery: "A jQuery object.",
Object: "A simple Javascript object. For example, it could be a String or a Number.",
String: "A string of characters.",
Number: "A numeric valid.",
Element: "The Javascript object representation of a DOM Element.",
Hash: "A Javascript object that contains key/value pairs in the form of properties and values.",
"Array<Element>": "An Array of DOM Elements.",
"Array<String>": "An Array of strings.",
Function: "A reference to a Javascript function."
};
var f = readFile(arguments[0]);
var c = [], bm, m;
var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g;
var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m;
while ( bm = blockMatch.exec(f) ) {
block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!";
var ret = { params: [], examples: [] };
while ( m = paramMatch.exec( block ) ) {
block = block.replace( paramMatch, "" );
var n = m[1];
var v = m[2]
.replace(/\s*$/g,"")
.replace(/^\s*/g,"")
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\n/g, "<br/>")
/*.replace(/(\s\s+)/g, function(a){
var ret = "";
for ( var i = 0; i < a.length; i++ )
ret += "&nbsp;";
return ret;
})*/ || 1;
if ( n == 'param' || n == 'any' ) {
var args = v.split(/\s+/);
v = args.slice( 2, args.length );
v = { type: args[0], name: args[1], desc: v.join(' ') };
if ( n == 'any' ) v.any = 1;
n = "params";
} else if ( n == 'example' ) {
v = { code: v };
n = "examples";
}
if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) {
ret.examples[ ret.examples.length - 1 ][ n ] = v;
} else {
if ( ret[ n ] ) {
if ( ret[ n ].constructor == Array ) {
ret[ n ].push( v );
} else {
ret[ n ] = [ ret[ n ], v ];
}
} else {
ret[ n ] = v;
}
}
}
ret.desc = block.replace(/\s*!!!$/,"")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
//.replace(/\n\n/g, "<br/><br/>")
//.replace(/\n/g, " ");
var m = /^((.|\n)*?(\.|$))/.exec( ret.desc );
if ( m ) ret['short'] = m[1];
if ( ret.name ) c.push( ret );
}
var c = parse( readFile(arguments[0]) );
var json = Object.toJSON( c ); var json = Object.toJSON( c );
writeFile( arguments[1] + "/data/jquery-docs-json.js", json ); writeFile( arguments[1] + "/data/jquery-docs-json.js", json );
......
...@@ -11,7 +11,10 @@ var types = { ...@@ -11,7 +11,10 @@ var types = {
}; };
$(document).ready(function(){ $(document).ready(function(){
$("span.tooltip").ToolTipDemo('#fff'); $("span.tooltip").each(function(){
if ( types[ this.innerHTML ] )
this.title = types[ this.innerHTML ];
}).ToolTipDemo('#fff');
$("a.name").click(function(){ $("a.name").click(function(){
$("div.more,div.short",this.parentNode.parentNode).toggle().find("div.desc",function(){ $("div.more,div.short",this.parentNode.parentNode).toggle().find("div.desc",function(){
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<head> <head>
<title>jQuery Docs - API</title> <title>jQuery Docs - API</title>
<link rel="stylesheet" href="style/style.css"/> <link rel="stylesheet" href="style/style.css"/>
<script src="../dist/jquery-svn.js"></script> <script src="../dist/jquery.js"></script>
<script src="js/tooltip.js"></script> <script src="js/tooltip.js"></script>
<script src="js/pager.js"></script> <script src="js/pager.js"></script>
<script src="js/doc.js"></script> <script src="js/doc.js"></script>
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
<xsl:sort select="@name"/> <xsl:sort select="@name"/>
<xsl:sort select="count(params)"/> <xsl:sort select="count(params)"/>
<li> <li>
<span class='type'><span title='TYPE' class='tooltip'><xsl:value-of select="@type"/></span></span> <span class='type'><span class='tooltip'><xsl:value-of select="@type"/></span></span>
<span class='fn'> <span class='fn'>
<a href='#{@name}' class='name' title=''><xsl:value-of select="@name"/></a> <a href='#{@name}' class='name' title=''><xsl:value-of select="@name"/></a>
<xsl:if test="not(@property)">( <xsl:if test="not(@property)">(
<xsl:for-each select="params"> <xsl:for-each select="params">
<span class='arg-type tooltip' title='TYPE'><xsl:value-of select="@type"/></span><xsl:text> </xsl:text> <span class='arg-type tooltip'><xsl:value-of select="@type"/></span><xsl:text> </xsl:text>
<span class='arg-name tooltip' title='{@desc}'><xsl:value-of select="@name"/></span> <span class='arg-name tooltip' title='{desc}'><xsl:value-of select="@name"/></span>
<xsl:if test="position() != last()"> <xsl:if test="position() != last()">
<xsl:if test="@any"> or </xsl:if> <xsl:if test="@any"> or </xsl:if>
<xsl:if test="not(@any)">, </xsl:if> <xsl:if test="not(@any)">, </xsl:if>
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
</li> </li>
</xsl:for-each> </xsl:for-each>
</ul> </ul>
<p class="raw"><b>Raw Data:</b><xsl:text> </xsl:text><a href="data/jquery-docs-json.js">JSON</a>, <a href="data/jquery-docs-jsonp.js">JSONP</a>, <a href="data/jquery-docs-xml.xml">XML</a></p>
</body> </body>
</html> </html>
</xsl:template> </xsl:template>
......
...@@ -126,3 +126,15 @@ ul#docs li div.example pre { ...@@ -126,3 +126,15 @@ ul#docs li div.example pre {
padding: 5px; padding: 5px;
overflow: auto; overflow: auto;
} }
p.raw {
font-size: 11px;
color: #FFF;
margin: 5px auto;
width: 600px;
text-align: right;
}
p.raw a {
color: #FFF;
}
function parse( f ) {
var c = [], bm, m;
var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g;
var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m;
while ( bm = blockMatch.exec(f) ) {
block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!";
var ret = { params: [], examples: [], tests: [] };
while ( m = paramMatch.exec( block ) ) {
block = block.replace( paramMatch, "" );
var n = m[1];
var v = m[2]
.replace(/\s*$/g,"")
.replace(/^\s*/g,"")
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
//.replace(/\n/g, "<br/>")
/*.replace(/(\s\s+)/g, function(a){
var ret = "";
for ( var i = 0; i < a.length; i++ )
ret += "&nbsp;";
return ret;
})*/ || 1;
if ( n == 'param' || n == 'any' ) {
var args = v.split(/\s+/);
v = args.slice( 2, args.length );
v = { type: args[0], name: args[1], desc: v.join(' ') };
if ( n == 'any' ) v.any = 1;
n = "params";
} else if ( n == 'example' ) {
v = { code: v };
n = "examples";
} else if ( n == 'test' ) {
n = "tests";
}
if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) {
ret.examples[ ret.examples.length - 1 ][ n ] = v;
} else {
if ( ret[ n ] ) {
if ( ret[ n ].constructor == Array ) {
ret[ n ].push( v );
} else {
ret[ n ] = [ ret[ n ], v ];
}
} else {
ret[ n ] = v;
}
}
}
ret.desc = block.replace(/\s*!!!$/,"")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
//.replace(/\n\n/g, "<br/><br/>")
//.replace(/\n/g, " ");
var m = /^((.|\n)*?(\.|$))/.exec( ret.desc );
if ( m ) ret['short'] = m[1];
if ( ret.name ) c.push( ret );
}
return c;
}
<html> <html id="html">
<head> <head>
<script type="text/javascript" src="lib/Test/Harness.js"></script> <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="lib/Test/Harness/Browser.js"></script> <script type="text/javascript" src="js/test.js"></script>
<script>
$(document).ready(function(){
runTests([{FILES}]);
});
</script>
<style>.pass { color: green; } .fail { color: red; } #tests ol { display: none; }</style>
</head> </head>
<body> <body id="body">
<h1>jQuery - Test Suite</h1> <h1>jQuery - Test Suite</h1>
<!-- Test HTML -->
<dl style="display:none;">
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
<p id="ap">
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
<a id="groups" href="http://groups.google.com/">Google Groups</a>.
This link has <code><a href="#" id="anchor1">class="blog"</a></code>:
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
<script type="text/javascript"> </p>
new Test.Harness.Browser().runTests( <div id="foo">
"tests/prereq.html", <p id="sndp">Everything inside the red border is inside a div with
"tests/css1.html", <code>id="foo"</code>.</p>
"tests/css2.html", <p lang="en" id="en">This is a normal link:
"tests/css3.html", <a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
"tests/xpath.html", <p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
"tests/custom.html", <a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
"tests/basic.html"
); </div>
</script> <p id="first">Try them out: </p>
<ul id="firstUL"></ul>
<ol id="empty"></ol>
<form id="form">
<input type="text" value="Test" id="text1"/>
<input type="text" value="Test" id="text2" disabled="disabled"/>
<input type="radio" name="radio1" id="radio1"/>
<input type="radio" name="radio2" id="radio2" checked/>
<input type="checkbox" name="check" id="check1" checked/>
<input type="checkbox" name="check" id="check2"/>
<input type="hidden" name="hidden" id="hidden1"/>
<input type="text" style="display:none;" id="hidden2"/>
</form>
</div>
</dl>
<ol id="tests"></ol>
</body> </body>
</html> </html>
function runTests(files) {
runTest( files, 0 );
}
function runTest( files, num ) {
$.get(files[num],function(js){
js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
try {
eval(js);
} catch(e) {
Test.push( [ false, "Died on test #" + Test.length + ": " + e ] );
}
var good = 0, bad = 0;
var ol = document.createElement("ol");
var li = "", state = "pass";
for ( var i = 0; i < Test.length; i++ ) {
var li = document.createElement("li");
li.className = Test[i][0] ? "pass" : "fail";
li.innerHTML = Test[i][1];
ol.appendChild( li );
if ( !Test[i][0] ) {
state = "fail";
bad++;
} else good++;
}
var li = document.createElement("li");
li.className = state;
var b = document.createElement("b");
b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
b.onclick = function(){
var n = this.nextSibling;
if ( jQuery.css( n, "display" ) == "none" )
n.style.display = "block";
else
n.style.display = "none";
};
li.appendChild( b );
li.appendChild( ol );
document.getElementById("tests").appendChild( li );
Test = [];
if ( ++num < files.length ) runTest( files, num );
});
}
var Test = [];
function ok(a, msg) {
Test.push( [ !!a, msg ] );
}
function cmpOK( a, c, b, msg ) {
var res;
eval( "res = (a " + c + " b)" );
Test.push( [ res, msg ] );
}
function isSet(a, b, msg) {
var ret = true;
if ( a && b && a.length == b.length ) {
for ( var i in a )
if ( a[i] != b[i] )
ret = false;
} else
ret = false;
if ( !ret && console )
console.log( msg, a, b );
Test.push( [ ret, msg ] );
}
function q() {
var r = [];
for ( var i = 0; i < arguments.length; i++ )
r.push( document.getElementById( arguments[i] ) );
return r;
}
function t(a,b,c) {
var f = jQuery.find(b);
var s = "";
for ( var i = 0; i < f.length; i++ )
s += (s && ",") + '"' + f[i].id + '"';
isSet(f, q.apply(q,c), a + " (" + b + ")");
}
function o(a) {
var li = document.createElement("li");
li.innerHTML = a;
if ( a.indexOf("#") == 0 )
li.className = "comment";
else if ( a.indexOf("TODO") >= 0 )
li.className = "todo";
else if ( a.indexOf("not ok") == 0 )
li.classname = "fail";
else
li.className = "pass";
document.getElementById("test").appendChild(li);
}
//plan({noPlan: true});
...@@ -1657,9 +1657,9 @@ new function(){ ...@@ -1657,9 +1657,9 @@ new function(){
jQuery.ready(); jQuery.ready();
} }
}, 10); }, 10);
} else { }
// A fallback to window.onload, that will always work
jQuery.event.add( window, "load", jQuery.ready ); // A fallback to window.onload, that will always work
} jQuery.event.add( window, "load", jQuery.ready );
}; };
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment