Browse Source

Remove dom dependency for js in TestRunner

Justin Donaldson 12 years ago
parent
commit
cdc6d9dd90
1 changed files with 15 additions and 6 deletions
  1. 15 6
      std/haxe/unit/TestRunner.hx

+ 15 - 6
std/haxe/unit/TestRunner.hx

@@ -64,12 +64,21 @@ class TestRunner {
 		#elseif cpp
 			cpp.Lib.print(v);
 		#elseif js
-			var msg = StringTools.htmlEscape(js.Boot.__string_rec(v,"")).split("\n").join("<br/>");
-			var d = document.getElementById("haxe:trace");
-			if( d == null )
-				alert("haxe:trace element not found")
-			else
-				d.innerHTML += msg;
+			var msg = js.Boot.__string_rec(v,"");
+			var d;
+            if( __js__("typeof")(document) != "undefined"
+                    && (d = document.getElementById("haxe:trace")) != null ) {
+                msg = msg.split("\n").join("<br/>");
+                d.innerHTML += StringTools.htmlEscape(msg)+"<br/>";
+            }
+			else if (  __js__("typeof process") != "undefined"
+					&& __js__("process").stdout != null
+					&& __js__("process").stdout.write != null)
+				__js__("process").stdout.write(msg); // node
+			else if (  __js__("typeof console") != "undefined"
+					&& __js__("console").log != null )
+				__js__("console").log(msg); // document-less js (which may include a line break)
+
 		#elseif cs
 			var str:String = v;
 			untyped __cs__("System.Console.Write(str)");