You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/06/26 02:51:25 UTC

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

Author: jbeard
Date: Sat Jun 26 00:51:25 2010
New Revision: 958161

URL: http://svn.apache.org/viewvc?rev=958161&view=rev
Log:
Task runInBrowserUnitTestsWithSelenium working in build script.

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=958161&r1=958160&r2=958161&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 Sat Jun 26 00:51:25 2010
@@ -366,7 +366,7 @@ require.def("build",
 
 				},
 
-				_genInBrowserHtml : function(fileDescriptor,testsGeneratedCollection){
+				_genInBrowserHtml : function(fileDescriptor,testsGeneratedCollection,callback){
 
 					//for each type of browser (IE and non-IE) [though we can make this part dynamic
 					//for each unit test script
@@ -375,51 +375,47 @@ require.def("build",
 
 					print("Generating in-browser html test files...");
 
+					tailRecurse(unitTestScripts,
+						function(testModule,step){
+							require([testModule],
+								function(testScript){
+									var pathToSCXMLTest = testScript.scxmlTest;
+
+									var compileTargets = [{scxmlTest:scxmlTest, backend:backend, isIE:isIE} 
+												for (backend in backends)
+												for each (isIE in [true,false])
+												for (scxmlTest in scxmlTests)
+													if ( scxmlTests[scxmlTest] == pathToSCXMLTest ) ];
+
+									compileTargets.forEach(function({scxmlTest:scxmlTestName, backend:backendName, isIE:isIE}){
+
+										//TODO: update this function to use RequireJS
+										var testHtml = inBrowserUnitTestHtmlTemplate(pathToSCXMLTest,testModule,backendName,isIE);
+
+										//write testHtml
+										var fpath = buildDir + "/" + fileDescriptor + "_" + scxmlTestName  + "_" + backendName 
+												+ (isIE ? "IE" : "") + ".html";
+
+										print("Writing in-browser html test file " + fpath);
+
+										utilFile.writeFile(testHtml,fpath);
+
+										//save the path to the html for running in selenium later
+										testsGeneratedCollection.push({
+											 path : fpath, 
+											 scxmlTest : scxmlTestName,
+											 testCasePath : testModule,
+											 backend : backendName,
+											 ie : isIE
+										});
 
-					var compileTargets = [{scxmlTest:scxmlTest, backend:backend, isIE:isIE} 
-								for (scxmlTest in scxmlTests) 
-								for (backend in backends)
-								for each (isIE in [true,false])];
-
-					compileTargets.forEach(function(target){
-						//run the build script on the test
-						var scxmlTestName = target.scxmlTest;
-						var backendName = target.backend;
-						var isIE = target.isIE;
-
-						var pathToSCXMLTest = scxmlTests[scxmlTestName];
-
-						var correspondingUnitTests = unitTestScripts.filter(function(t){return t.scxmlTest == pathToSCXMLTest});
-
-						correspondingUnitTests.forEach(function(unitTest){
-
-							var pathToUnitTest = unitTest.path;
-
-							var relativePathToUnitTest  = "../" + pathToUnitTest;
-
-							var testHtml = inBrowserUnitTestHtmlTemplate(pathToSCXMLTest,relativePathToUnitTest,backendName,isIE);
-
-							//write testHtml
-							var fpath = buildDir + "/" + fileDescriptor + "_" + scxmlTestName  + "_" + backendName 
-									+ (isIE ? "IE" : "") + ".html";
-
-							print("Writing in-browser html test file " + fpath);
-
-							utilFile.writeFile(testHtml,fpath);
-
-							//save the path to the html for running in selenium later
-							testsGeneratedCollection.push({
-								 path : fpath, 
-								 scxmlTest : scxmlTestName,
-								 testCasePath : pathToUnitTest,
-								 backend : backendName,
-								 ie : isIE
-							});
-
-						}); 
+										
+									});
 
-						
-					});
+									step();
+								});
+						},
+						callback);
 
 				},
 
@@ -607,81 +603,84 @@ require.def("build",
 					});
 				},
 
-				genInBrowserUnitTestHtml : function(){
+				genInBrowserUnitTestHtml : function(callback){
 					print("Generating html performance test files...");
-					this._genInBrowserHtml("in-browser-unit",htmlInBrowserUnitTestsGenerated);
+					this._genInBrowserHtml("in-browser-unit",htmlInBrowserUnitTestsGenerated,callback);
 				},
 
 				runInBrowserUnitTestsWithSelenium : function(){
-					this.genInBrowserUnitTestHtml();
+					this.genInBrowserUnitTestHtml(function(){
 
-					print("Running Selenium unit tests...");
+						print("Running Selenium unit tests...");
 
-					for(var browserName in browsers){ 
+						for(var browserName in browsers){ 
 
-						print("Running test for " + browserName + "...");
+							print("Running test for " + browserName + "...");
 
-						var bSpec = browsers[browserName];
-						var bSel = new DefaultSelenium(bSpec.host, bSpec.port, bSpec.browser, seleniumConf.rootUrl);
-						bSel.start();
+							var bSpec = browsers[browserName];
+							var bSel = new DefaultSelenium(bSpec.host, bSpec.port, bSpec.browser, seleniumConf.rootUrl);
+							bSel.start();
 
-						htmlInBrowserUnitTestsGenerated.forEach(function(htmlTest){
-							//ensure we are not testing an ie html test
-							//on a non-ie browser
-							if(htmlTest.ie == bSpec.ie){
+							htmlInBrowserUnitTestsGenerated.forEach(function(htmlTest){
+								//ensure we are not testing an ie html test
+								//on a non-ie browser
+								if(htmlTest.ie == bSpec.ie){
 
-								var unitTestResult = unitTestWithSelenium(bSel,htmlTest.path); 
+									var unitTestResult = unitTestWithSelenium(bSel,htmlTest.path); 
 
-								var unitTestResultObj = {
-									data : unitTestResult,
-									browser : browserName,
-									scxmlTest : htmlTest.scxmlTest,
-									backend : htmlTest.backend,
-								};
+									var unitTestResultObj = {
+										data : unitTestResult,
+										browser : browserName,
+										scxmlTest : htmlTest.scxmlTest,
+										backend : htmlTest.backend,
+									};
 
-								unitTestResults.push(unitTestResultObj);
+									unitTestResults.push(unitTestResultObj);
 
-								//report errors and failures that may occur
-								if(unitTestResult.failCount || unitTestResult.errorCount){
-									print("UNIT TEST ERROR");
-									print(JSON.stringify(unitTestResultObj));
+									//report errors and failures that may occur
+									if(unitTestResult.failCount || unitTestResult.errorCount){
+										print("UNIT TEST ERROR");
+										print(JSON.stringify(unitTestResultObj));
+									}
 								}
-							}
-						});
+							});
 
-						bSel.stop();
-					}
+							bSel.stop();
+						}
 
-					//make one big, self-describing data structure
-					//this is what analyze uses to do its analyses
-					allUnitTestResults = {
-						//FIXME: maybe make this an obj, so that we can add more info to it (for reports, etc.)
-						data : unitTestResults,	
-						browsers : browsers,
-						backends : backends,
-						scxmlTests : scxmlTests
-					};
+						//make one big, self-describing data structure
+						//this is what analyze uses to do its analyses
+						allUnitTestResults = {
+							//FIXME: maybe make this an obj, so that we can add more info to it (for reports, etc.)
+							data : unitTestResults,	
+							browsers : browsers,
+							backends : backends,
+							scxmlTests : scxmlTests
+						};
 
-					//stringify it, and serialize it for posterity
-					var allUnitTestResultsString = 
-							JSON.stringify(allUnitTestResults)
+						//stringify it, and serialize it for posterity
+						var allUnitTestResultsString = 
+								JSON.stringify(allUnitTestResults)
+
+
+						//print report that says whether all tests passed
+						var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
+						var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
+						var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
+						var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
+
+						print("Test Results:");
+						print("Total Tests: " + totalTests);
+						print("Total Tests Failed: " + totalTestsFailed);
+						print("Total Tests Errored: " + totalTestsErrored);
+						print("Total Tests Passed: " + totalTestsPassed);
+
+						var unitTestResultsPath = "build/allUnitTestResults.json";
+						print("writing a summary of performance results to " + unitTestResultsPath);
+						utilFile.writeFile(allUnitTestResultsString, unitTestResultsPath);
 
+					});
 
-					//print report that says whether all tests passed
-					var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
-					var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
-					var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
-					var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
-
-					print("Test Results:");
-					print("Total Tests: " + totalTests);
-					print("Total Tests Failed: " + totalTestsFailed);
-					print("Total Tests Errored: " + totalTestsErrored);
-					print("Total Tests Passed: " + totalTestsPassed);
-
-					var unitTestResultsPath = "build/allUnitTestResults.json";
-					print("writing a summary of performance results to " + unitTestResultsPath);
-					utilFile.writeFile(allUnitTestResultsString, unitTestResultsPath);
 				},
 
 
@@ -828,7 +827,7 @@ require.def("build",
 				</html>
 			}
 
-			function inBrowserUnitTestHtmlTemplate(modulePathToXMLTest,testScriptRelativePath,backendName,isIE){
+			function inBrowserUnitTestHtmlTemplate(modulePathToXMLTest,testScriptModulePath,backendName,isIE){
 				default xml namespace = "";
 				return <html>
 				<head>
@@ -842,7 +841,6 @@ require.def("build",
 						window.doh._onEnd = function() &#x7B; window.dohIsComplete = true; window.oldDohOnEnd.apply(window.doh); &#x7D;;
 					</script>
 					<script src="../test/testHelpers.js" type="text/javascript">true;</script>
-					<script src={testScriptRelativePath} type="text/javascript">true;</script>
 					<script>
 						var resultText;
 
@@ -851,8 +849,9 @@ require.def("build",
 								"baseUrl":"/"
 							&#x7D;,
 							[ "src/javascript/scxml/cgf/SCXMLCompiler",
-								"xml!{modulePathToXMLTest}"],
-							function(compiler,KitchenSink_executableContent)&#x7B;
+								"xml!{modulePathToXMLTest}",
+								"{testScriptModulePath}"],
+							function(compiler,KitchenSink_executableContent,testScriptModule)&#x7B;
 								var compileLog = true;
 
 								compiler.compile(&#x7B;
@@ -869,7 +868,9 @@ require.def("build",
 
 									//eval
 									eval(transformedJs);
-									window.StatechartExecutionContext = StatechartExecutionContext;
+
+									testScriptModule.register(StatechartExecutionContext);
+
 									dojo.require("doh.runner"); 
 									doh.run();
 								&#x7D;);