mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix scripts in Firefox
This commit is contained in:
parent
bd61e4edec
commit
44173021f2
|
@ -76,6 +76,7 @@
|
||||||
<artifactId>teavm-maven-plugin</artifactId>
|
<artifactId>teavm-maven-plugin</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
|
<!--
|
||||||
<execution>
|
<execution>
|
||||||
<id>generate-javascript-tests</id>
|
<id>generate-javascript-tests</id>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -95,6 +96,7 @@
|
||||||
<incremental>${teavm.test.incremental}</incremental>
|
<incremental>${teavm.test.incremental}</incremental>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
-->
|
||||||
<execution>
|
<execution>
|
||||||
<id>run-javascript-tests</id>
|
<id>run-javascript-tests</id>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -209,6 +209,7 @@ public class TeaVMTestTool implements BaseTeaVMTool {
|
||||||
resourceToFile("org/teavm/javascript/runtime.js", "res/runtime.js");
|
resourceToFile("org/teavm/javascript/runtime.js", "res/runtime.js");
|
||||||
String prefix = "org/teavm/tooling/test";
|
String prefix = "org/teavm/tooling/test";
|
||||||
resourceToFile(prefix + "/res/junit-support.js", "res/junit-support.js");
|
resourceToFile(prefix + "/res/junit-support.js", "res/junit-support.js");
|
||||||
|
resourceToFile(prefix + "/res/junit-client.js", "res/junit-client.js");
|
||||||
resourceToFile(prefix + "/res/junit.css", "res/junit.css");
|
resourceToFile(prefix + "/res/junit.css", "res/junit.css");
|
||||||
resourceToFile(prefix + "/res/class_obj.png", "res/class_obj.png");
|
resourceToFile(prefix + "/res/class_obj.png", "res/class_obj.png");
|
||||||
resourceToFile(prefix + "/res/control-000-small.png", "res/control-000-small.png");
|
resourceToFile(prefix + "/res/control-000-small.png", "res/control-000-small.png");
|
||||||
|
@ -219,6 +220,7 @@ public class TeaVMTestTool implements BaseTeaVMTool {
|
||||||
resourceToFile(prefix + "/res/toggle-small-expand.png", "res/toggle-small-expand.png");
|
resourceToFile(prefix + "/res/toggle-small-expand.png", "res/toggle-small-expand.png");
|
||||||
resourceToFile(prefix + "/res/toggle-small.png", "res/toggle-small.png");
|
resourceToFile(prefix + "/res/toggle-small.png", "res/toggle-small.png");
|
||||||
resourceToFile(prefix + "/junit.html", "junit.html");
|
resourceToFile(prefix + "/junit.html", "junit.html");
|
||||||
|
resourceToFile(prefix + "/junit-client.html", "junit-client.html");
|
||||||
ClassHolderSource classSource = new ClasspathClassHolderSource(classLoader);
|
ClassHolderSource classSource = new ClasspathClassHolderSource(classLoader);
|
||||||
if (incremental) {
|
if (incremental) {
|
||||||
classSource = new PreOptimizingClassHolderSource(classSource);
|
classSource = new PreOptimizingClassHolderSource(classSource);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!--
|
||||||
|
Copyright 2015 Alexey Andreev.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" src="res/junit-client.js"></script>
|
||||||
|
<script type="text/javascript" src="res/runtime.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>TeaVM JUnit tests</title>
|
<title>TeaVM JUnit tests</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
||||||
<title>TeaVM JUnit tests</title>
|
|
||||||
<link rel="stylesheet" href="res/junit.css" type="text/css"/>
|
<link rel="stylesheet" href="res/junit.css" type="text/css"/>
|
||||||
<script type="text/javascript" src="res/junit-support.js"></script>
|
<script type="text/javascript" src="res/junit-support.js"></script>
|
||||||
<script type="text/javascript" src="tests/all.js"></script>
|
<script type="text/javascript" src="tests/all.js"></script>
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
"use strict";
|
||||||
|
var JUnitClient = {};
|
||||||
|
JUnitClient.run = function() {
|
||||||
|
var handler = function(event) {
|
||||||
|
switch (event.data.command) {
|
||||||
|
case "runTest":
|
||||||
|
window.removeEventListener("message", handler);
|
||||||
|
$rt_startThread(function() {
|
||||||
|
JUnitClient.runTest();
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener("message", handler);
|
||||||
|
window.parent.postMessage("ready", "*");
|
||||||
|
}
|
||||||
|
JUnitClient.runTest = function() {
|
||||||
|
var thread = $rt_nativeThread();
|
||||||
|
var instance;
|
||||||
|
var ptr = 0;
|
||||||
|
var message;
|
||||||
|
if (thread.isResuming()) {
|
||||||
|
ptr = thread.pop();
|
||||||
|
instance = thread.pop();
|
||||||
|
}
|
||||||
|
loop: while (true) { switch (ptr) {
|
||||||
|
case 0:
|
||||||
|
instance = new TestClass();
|
||||||
|
ptr = 1;
|
||||||
|
case 1:
|
||||||
|
try {
|
||||||
|
initInstance(instance);
|
||||||
|
} catch (e) {
|
||||||
|
message = {};
|
||||||
|
JUnitClient.makeErrorMessage(message, e);
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
if (thread.isSuspending()) {
|
||||||
|
thread.push(instance);
|
||||||
|
thread.push(ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ptr = 2;
|
||||||
|
case 2:
|
||||||
|
try {
|
||||||
|
runTest(instance);
|
||||||
|
} catch (e) {
|
||||||
|
message = {};
|
||||||
|
JUnitClient.makeErrorMessage(message, e);
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
if (thread.isSuspending()) {
|
||||||
|
thread.push(instance);
|
||||||
|
thread.push(ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
message = {};
|
||||||
|
message.status = "ok";
|
||||||
|
break loop;
|
||||||
|
}}
|
||||||
|
window.parent.postMessage(message, "*");
|
||||||
|
}
|
||||||
|
JUnitClient.makeErrorMessage = function(message, e) {
|
||||||
|
message.status = "exception";
|
||||||
|
var stack = e.stack;
|
||||||
|
if (e.$javaException && e.$javaException.constructor.$meta) {
|
||||||
|
message.exception = e.$javaException.constructor.$meta.name;
|
||||||
|
message.stack = e.$javaException.constructor.$meta.name + ": ";
|
||||||
|
var exceptionMessage = extractException(e.$javaException);
|
||||||
|
message.stack += exceptionMessage ? $rt_ustr(exceptionMessage) : "";
|
||||||
|
}
|
||||||
|
message.stack += "\n" + stack;
|
||||||
|
}
|
||||||
|
JUnitClient.reportError = function(error) {
|
||||||
|
var handler = function() {
|
||||||
|
window.removeEventListener("message", handler);
|
||||||
|
var message = { status : "exception", stack : error };
|
||||||
|
window.parent.postMessage(message, "*");
|
||||||
|
};
|
||||||
|
window.addEventListener("message", handler);
|
||||||
|
}
|
||||||
|
JUnitClient.loadScript = function(scriptPath) {
|
||||||
|
var script = document.createElement("script");
|
||||||
|
script.src = scriptPath;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
window.addEventListener("message", function(event) {
|
||||||
|
var data = event.data;
|
||||||
|
switch (data.command) {
|
||||||
|
case "loadScript":
|
||||||
|
JUnitClient.loadScript(data.script);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.parent.postMessage("loaded", "*");
|
|
@ -77,34 +77,29 @@ JUnitServer.prototype.isExpectedException = function(ex) {
|
||||||
}
|
}
|
||||||
JUnitServer.prototype.loadCode = function(path, additionalScripts, callback) {
|
JUnitServer.prototype.loadCode = function(path, additionalScripts, callback) {
|
||||||
this.frame = document.createElement("iframe");
|
this.frame = document.createElement("iframe");
|
||||||
|
this.frame.src = "junit-client.html";
|
||||||
document.body.appendChild(this.frame);
|
document.body.appendChild(this.frame);
|
||||||
var frameDoc = this.frame.contentWindow.document;
|
var sequence = [];
|
||||||
var self = this;
|
|
||||||
var sequence = ["res/junit-support.js", "res/runtime.js"];
|
|
||||||
if (additionalScripts) {
|
|
||||||
for (var i = 0; i < additionalScripts.length; ++i) {
|
|
||||||
sequence.push(additionalScripts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sequence.push(path);
|
sequence.push(path);
|
||||||
self.loadScripts(sequence, 0, callback);
|
for (var i = 0; i < additionalScripts.length; ++i) {
|
||||||
}
|
sequence.push(additionalScripts[i]);
|
||||||
JUnitServer.prototype.loadScripts = function(scripts, index, callback) {
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
if (index == scripts.length) {
|
var handler = function() {
|
||||||
callback();
|
window.removeEventListener("message", handler);
|
||||||
} else {
|
self.loadScripts(sequence, callback);
|
||||||
this.loadScript(scripts[index], function() { self.loadScripts(scripts, index + 1, callback) });
|
|
||||||
}
|
}
|
||||||
|
window.addEventListener("message", handler);
|
||||||
}
|
}
|
||||||
JUnitServer.prototype.loadScript = function(name, callback) {
|
JUnitServer.prototype.loadScripts = function(scripts, callback) {
|
||||||
var doc = this.frame.contentWindow.document;
|
for (var i = 0; i < scripts.length; ++i) {
|
||||||
var script = doc.createElement("script");
|
this.frame.contentWindow.postMessage({ command : "loadScript", "script" : scripts[i] }, "*");
|
||||||
script.src = name;
|
}
|
||||||
doc.body.appendChild(script);
|
var handler = function() {
|
||||||
script.onload = function() {
|
window.removeEventListener("message", handler);
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
window.addEventListener("message", handler);
|
||||||
}
|
}
|
||||||
JUnitServer.prototype.runTest = function(node, callback) {
|
JUnitServer.prototype.runTest = function(node, callback) {
|
||||||
node.indicator.className = "complete-indicator in-progress";
|
node.indicator.className = "complete-indicator in-progress";
|
||||||
|
@ -118,10 +113,10 @@ JUnitServer.prototype.runTest = function(node, callback) {
|
||||||
window.removeEventListener("message", messageHandler);
|
window.removeEventListener("message", messageHandler);
|
||||||
var timeSpent = new Date().getTime() - startTime;
|
var timeSpent = new Date().getTime() - startTime;
|
||||||
node.timeIndicator.appendChild(document.createTextNode("(" + (timeSpent / 1000).toFixed(3) + ")"));
|
node.timeIndicator.appendChild(document.createTextNode("(" + (timeSpent / 1000).toFixed(3) + ")"));
|
||||||
self.handleEvent(JSON.parse(event.data), callback);
|
self.handleEvent(event.data, callback);
|
||||||
};
|
};
|
||||||
window.addEventListener("message", messageHandler);
|
window.addEventListener("message", messageHandler);
|
||||||
self.frame.contentWindow.postMessage("runTest", "*");
|
self.frame.contentWindow.postMessage({ command : "runTest" }, "*");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -364,72 +359,4 @@ TreeNode.prototype.select = function() {
|
||||||
for (var i = 0; i < this.tree.selectionListeners.length; ++i) {
|
for (var i = 0; i < this.tree.selectionListeners.length; ++i) {
|
||||||
this.tree.selectionListeners[i](this);
|
this.tree.selectionListeners[i](this);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var JUnitClient = {};
|
|
||||||
JUnitClient.run = function() {
|
|
||||||
var handler = window.addEventListener("message", $rt_threadStarter(function() {
|
|
||||||
var thread = $rt_nativeThread();
|
|
||||||
var instance;
|
|
||||||
var ptr = 0;
|
|
||||||
var message;
|
|
||||||
if (thread.isResuming()) {
|
|
||||||
ptr = thread.pop();
|
|
||||||
instance = thread.pop();
|
|
||||||
}
|
|
||||||
loop: while (true) { switch (ptr) {
|
|
||||||
case 0:
|
|
||||||
instance = new TestClass();
|
|
||||||
ptr = 1;
|
|
||||||
case 1:
|
|
||||||
try {
|
|
||||||
initInstance(instance);
|
|
||||||
} catch (e) {
|
|
||||||
message = {};
|
|
||||||
JUnitClient.makeErrorMessage(message, e);
|
|
||||||
break loop;
|
|
||||||
}
|
|
||||||
if (thread.isSuspending()) {
|
|
||||||
thread.push(instance);
|
|
||||||
thread.push(ptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ptr = 2;
|
|
||||||
case 2:
|
|
||||||
try {
|
|
||||||
runTest(instance);
|
|
||||||
} catch (e) {
|
|
||||||
message = {};
|
|
||||||
JUnitClient.makeErrorMessage(message, e);
|
|
||||||
break loop;
|
|
||||||
}
|
|
||||||
if (thread.isSuspending()) {
|
|
||||||
thread.push(instance);
|
|
||||||
thread.push(ptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
message = {};
|
|
||||||
message.status = "ok";
|
|
||||||
break loop;
|
|
||||||
}}
|
|
||||||
window.parent.postMessage(JSON.stringify(message), "*");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
JUnitClient.makeErrorMessage = function(message, e) {
|
|
||||||
message.status = "exception";
|
|
||||||
var stack = e.stack;
|
|
||||||
if (e.$javaException && e.$javaException.constructor.$meta) {
|
|
||||||
message.exception = e.$javaException.constructor.$meta.name;
|
|
||||||
message.stack = e.$javaException.constructor.$meta.name + ": ";
|
|
||||||
var exceptionMessage = extractException(e.$javaException);
|
|
||||||
message.stack += exceptionMessage ? $rt_ustr(exceptionMessage) : "";
|
|
||||||
}
|
|
||||||
message.stack += "\n" + stack;
|
|
||||||
}
|
|
||||||
JUnitClient.reportError = function(error) {
|
|
||||||
var handler = window.addEventListener("message", function() {
|
|
||||||
window.removeEventListener("message", handler);
|
|
||||||
var message = { status : "exception", stack : error };
|
|
||||||
window.parent.postMessage(JSON.stringify(message), "*");
|
|
||||||
});
|
|
||||||
}
|
}
|
|
@ -111,12 +111,6 @@ public class RunTestsMojo extends AbstractMojo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failedTests > 0) {
|
|
||||||
throw new MojoExecutionException(failedTests + " of " + report.getResults().size() + " test(s) failed");
|
|
||||||
} else {
|
|
||||||
getLog().info("All of " + report.getResults().size() + " tests successfully passed");
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(reportFile), "UTF-8")) {
|
try (Writer writer = new OutputStreamWriter(new FileOutputStream(reportFile), "UTF-8")) {
|
||||||
|
@ -124,5 +118,11 @@ public class RunTestsMojo extends AbstractMojo {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new MojoFailureException("Error writing test report", e);
|
throw new MojoFailureException("Error writing test report", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failedTests > 0) {
|
||||||
|
throw new MojoExecutionException(failedTests + " of " + report.getResults().size() + " test(s) failed");
|
||||||
|
} else {
|
||||||
|
getLog().info("All of " + report.getResults().size() + " tests successfully passed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user