commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r958146 - /commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
Date Fri, 25 Jun 2010 22:52:39 GMT
Author: jbeard
Date: Fri Jun 25 22:52:38 2010
New Revision: 958146

URL: http://svn.apache.org/viewvc?rev=958146&view=rev
Log:
Still updating build script. runUnitTestsWithSelenium now works in addition to runUnitTestsWithRhino.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js

Modified: commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js?rev=958146&r1=958145&r2=958146&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/core-module.SCXML-137/build.js Fri Jun 25
22:52:38 2010
@@ -236,9 +236,8 @@ require.def("build",
 								for (scxmlTest in scxmlTests) 
 								for (backend in backends)];
 
-					(function compileTarget(compileTargetsList){
-						var target = compileTargetsList.pop();
-						if(target){
+					tailRecurse(compileTargets,
+						function(target,step){
 							//do action
 
 							//run the build script on the test
@@ -313,20 +312,13 @@ require.def("build",
 											utilFile.writeFile(sc,fpath); 
 
 											//recursive callback
-											compileTarget(compileTargetsList);
+											step();
 										}
 									)
 								}
 							)
-
-						}else{
-							//base case
-							if(compilerCallback){
-								compilerCallback();
-							}
-						}
-
-					})(compileTargets);
+						},
+						compilerCallback);
 
 				},
 
@@ -335,36 +327,41 @@ require.def("build",
 
 						print("Generating html test files...");
 
-						testScripts.forEach(function(testScript){
-							var testScriptPath = testScript.path;
-							var testScriptRelativePath = "../" + testScriptPath;
-
-							scriptsGenerated.
-								filter(function(s){return scxmlTests[s.scxmlTest] == testScript.scxmlTest}).
-								forEach(function(generatedScript){
-								
-								//FIXME: this may need to be refactored
-								var testHtml = htmlGenFn(generatedScript.name,testScriptRelativePath);
-
-								//write testHtml
-								var fpath = buildDir + "/" + fileDescriptor + "_" + generatedScript.scxmlTest  +
"_" + generatedScript.label + ".html";
-
-								print("Writing html test file " + fpath);
-
-								utilFile.writeFile(testHtml,fpath);
-
-								//save the path to the html for running in selenium later
-								testsGeneratedCollection.push({
-									 path : fpath, 
-									 scxmlTest : generatedScript.scxmlTest,
-									 testCasePath : generatedScript.path,
-									 backend : generatedScript.backend,
-									 ie : generatedScript.ie
-								});
-							});
-						});
+						//we use tail recurse, because we are requiring each unit test module, which is asynchronous
+						//we require each module, one at a time, rather than all-together, so as to keep the

+						//relationship between its module path, and the module itself. DRY
+						tailRecurse(testScripts,
+							function(testModulePath,step){
+								require([testModulePath],
+									function(testScript){
+
+										scriptsGenerated.
+											filter(function(s){return scxmlTests[s.scxmlTest] == testScript.scxmlTest}).
+											forEach(function(generatedScript){
+											
+											var testHtml = htmlGenFn(generatedScript.name,testModulePath);
+
+											//write testHtml
+											var fpath = buildDir + "/" + fileDescriptor + "_" + generatedScript.scxmlTest
 + "_" + generatedScript.label + ".html";
+
+											print("Writing html test file " + fpath);
+
+											utilFile.writeFile(testHtml,fpath);
+
+											//save the path to the html for running in selenium later
+											testsGeneratedCollection.push({
+												 path : fpath, 
+												 scxmlTest : generatedScript.scxmlTest,
+												 testCasePath : generatedScript.path,
+												 backend : generatedScript.backend,
+												 ie : generatedScript.ie
+											});
+										});
 
-						callback();
+										step();
+									});
+							},
+							callback);
 					});
 
 				},
@@ -797,12 +794,13 @@ require.def("build",
 			}
 
 
-			function unitTestHtmlTemplate(generatedJsCodeRelativePath,testScriptRelativePath){
+			function unitTestHtmlTemplate(generatedJsCodeRelativePath,testScriptModulePath){
 				//fixme: we probably want to put all unit test scripts in one html file
 				//but this may ential a different flow than the performance tests, so i'm marking it
as a todo
 				default xml namespace = "";
 				return <html>
 					<head>
+						<script src="../lib/js/requirejs/require.js" type="text/javascript">true;</script>
 						<script type="text/javascript" src="../lib/test-js/dojo-release-1.4.2-src/dojo/dojo.js"
djConfig="isDebug:true">true;</script>
 						<script type="text/javascript">
 							dojo.require("doh.runner");
@@ -812,10 +810,16 @@ require.def("build",
 						</script>
 						<script type="text/javascript" src="../test/testHelpers.js">true;</script>
 						<script type="text/javascript" src={generatedJsCodeRelativePath}>true;</script>
-						<script type="text/javascript" src={testScriptRelativePath}>true;</script>
 						<script type="text/javascript">
-							dojo.require("doh.runner");
-							doh.run();
+							require(
+								&#x7B; baseUrl : "/" &#x7D;,
+								["{testScriptModulePath}"],
+								function(unitTestModule)&#x7B; 
+									unitTestModule.register(StatechartExecutionContext);
+
+									dojo.require("doh.runner");
+									doh.run();
+								&#x7D;);
 						</script>
 					</head>
 					<body>
@@ -879,8 +883,20 @@ require.def("build",
 				</html>
 			}
 
+			//helper function that abstracts out the process of iteration using tail recursion
+			//useful for much of the asynchronous programming that happens with RequireJS and scxml-js's
async API
+			function tailRecurse(list,stepCallback,baseCaseCallback){
+				var target = list.pop();
+				
+				if(target){
+					stepCallback(target, 
+						function(){tailRecurse(list,stepCallback,baseCaseCallback)});
+				}else{
+					if(baseCaseCallback) baseCaseCallback();
+				}
+			}
 
-
+			
 			if(args.length){
 				for(var i=0; i<args.length; i++){
 					if(tasks[args[i]]){



Mime
View raw message