fixed Envjs 1.2 CSS2Properties value maps + rhino shortcuts in bin

This commit is contained in:
Wouter Groeneveld 2011-06-28 12:11:30 +02:00
parent 38514a392d
commit 2ce4f02f97
11 changed files with 9102 additions and 67 deletions

9
bin/bootstrap.js vendored Executable file
View File

@ -0,0 +1,9 @@
load("./../src/test/javascript/lib/env.rhino.1.2.js");
load("./../src/test/javascript/lib/env.utils.js");
load("./../src/test/javascript/envJsOptions.js");
load("jquery-1.6.1.js");
function append(itm) {
$('body').append($(itm));
}

8936
bin/jquery-1.6.1.js vendored Executable file

File diff suppressed because it is too large Load Diff

BIN
bin/js.jar Executable file

Binary file not shown.

7
bin/rhino.bat Executable file
View File

@ -0,0 +1,7 @@
@echo off
REM -opt -1 is needed for Envjs (interpretation, not compilation mode)
REM Rhino JAR options: See https://developer.mozilla.org/en/Rhino_Shell
REM EnvJS usage: See http://www.envjs.com/doc/guides#running-rhino
java -cp js.jar org.mozilla.javascript.tools.shell.Main -opt -1

2
bin/rhino.debug.bat Executable file
View File

@ -0,0 +1,2 @@
@echo off
java -cp js.jar org.mozilla.javascript.tools.debugger.Main -opt -1

View File

@ -10,7 +10,7 @@ import org.mozilla.javascript.NativeObject;
import be.klak.rhino.RhinoContext;
public class JasmineJSSuiteConverter {
class JasmineJSSuiteConverter {
private final RhinoContext context;

View File

@ -3,17 +3,17 @@ package be.klak.junit.jasmine;
import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.ScriptableObject;
public class JasmineSpecFailureException extends Exception {
class JasmineSpecFailureException extends Exception {
private final ScriptableObject trace;
private final ScriptableObject trace;
public JasmineSpecFailureException(NativeObject specResultItem) {
this.trace = (ScriptableObject) specResultItem.get("trace", specResultItem);
}
public JasmineSpecFailureException(NativeObject specResultItem) {
this.trace = (ScriptableObject) specResultItem.get("trace", specResultItem);
}
@Override
public String getMessage() {
return (String) trace.get("message", trace);
}
@Override
public String getMessage() {
return (String) trace.get("message", trace);
}
}

View File

@ -5,73 +5,73 @@ import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class JasmineSpecRunnerGenerator {
class JasmineSpecRunnerGenerator {
private enum TemplatePlaceholders {
RELATIVE_PATH("<!--RelativePath-->"),
SOURCE_FILES_TO_INCLUDE("<!--SourceFileIncludes-->"),
SPEC_FILES_TO_INCLUDE("<!--SpecFileIncludes-->");
private enum TemplatePlaceholders {
RELATIVE_PATH("<!--RelativePath-->"),
SOURCE_FILES_TO_INCLUDE("<!--SourceFileIncludes-->"),
SPEC_FILES_TO_INCLUDE("<!--SpecFileIncludes-->");
private final String placeholder;
private final String placeholder;
private TemplatePlaceholders(String placeholder) {
this.placeholder = placeholder;
}
private TemplatePlaceholders(String placeholder) {
this.placeholder = placeholder;
}
public String getPlaceholder() {
return placeholder;
}
public String getPlaceholder() {
return placeholder;
}
}
}
private final JasmineSuite suite;
private final String[] jasmineSpecs;
private final String outputPath;
private final String outputFileName;
private final JasmineSuite suite;
private final String[] jasmineSpecs;
private final String outputPath;
private final String outputFileName;
public JasmineSpecRunnerGenerator(String[] jasmineSpecs, JasmineSuite suite, String outputPath, String outputFileName) {
this.jasmineSpecs = jasmineSpecs;
this.suite = suite;
this.outputPath = outputPath;
this.outputFileName = outputFileName;
}
public JasmineSpecRunnerGenerator(String[] jasmineSpecs, JasmineSuite suite, String outputPath, String outputFileName) {
this.jasmineSpecs = jasmineSpecs;
this.suite = suite;
this.outputPath = outputPath;
this.outputFileName = outputFileName;
}
public void generate() {
// TODO hardcoded relative path stuff wat configureerbaar maken
String template = loadTemplate();
template = replaceRelativePathsForLibs(template);
template = template.replaceAll(TemplatePlaceholders.SOURCE_FILES_TO_INCLUDE.getPlaceholder(),
getJavascriptFileIncludes("./../../../main/webapp/js", suite.sources()));
template = template.replaceAll(TemplatePlaceholders.SPEC_FILES_TO_INCLUDE.getPlaceholder(),
getJavascriptFileIncludes("./../specs", jasmineSpecs));
public void generate() {
// TODO hardcoded relative path stuff wat configureerbaar maken
String template = loadTemplate();
template = replaceRelativePathsForLibs(template);
template = template.replaceAll(TemplatePlaceholders.SOURCE_FILES_TO_INCLUDE.getPlaceholder(),
getJavascriptFileIncludes("./../../../main/webapp/js", suite.sources()));
template = template.replaceAll(TemplatePlaceholders.SPEC_FILES_TO_INCLUDE.getPlaceholder(),
getJavascriptFileIncludes("./../specs", jasmineSpecs));
try {
FileUtils.writeStringToFile(new File(outputPath + "/" + outputFileName), template);
} catch (IOException e) {
throw new RuntimeException("unable to write spec runner contents to destination", e);
}
}
try {
FileUtils.writeStringToFile(new File(outputPath + "/" + outputFileName), template);
} catch (IOException e) {
throw new RuntimeException("unable to write spec runner contents to destination", e);
}
}
private String replaceRelativePathsForLibs(String template) {
return template.replaceAll(TemplatePlaceholders.RELATIVE_PATH.getPlaceholder(), suite.jsRootDir());
}
private String replaceRelativePathsForLibs(String template) {
return template.replaceAll(TemplatePlaceholders.RELATIVE_PATH.getPlaceholder(), suite.jsRootDir());
}
private String getJavascriptFileIncludes(String path, String[] jsFiles) {
StringBuilder sourceFileIncludes = new StringBuilder();
for (String sourceFile : jsFiles) {
sourceFileIncludes.append("\t\t<script type='text/javascript' src='" + path + "/" + sourceFile
+ "'></script>\r\n");
}
return sourceFileIncludes.toString();
}
private String getJavascriptFileIncludes(String path, String[] jsFiles) {
StringBuilder sourceFileIncludes = new StringBuilder();
for (String sourceFile : jsFiles) {
sourceFileIncludes.append("\t\t<script type='text/javascript' src='" + path + "/" + sourceFile
+ "'></script>\r\n");
}
return sourceFileIncludes.toString();
}
private String loadTemplate() {
String template = null;
try {
template = FileUtils.readFileToString(new File(suite.jsRootDir() + "/lib/specRunner.tpl"));
} catch (IOException e) {
throw new RuntimeException("spec runner template file not found!", e);
}
return template;
}
private String loadTemplate() {
String template = null;
try {
template = FileUtils.readFileToString(new File(suite.jsRootDir() + "/lib/specRunner.tpl"));
} catch (IOException e) {
throw new RuntimeException("spec runner template file not found!", e);
}
return template;
}
}

12
src/test/java/be/klak/env/EnvUtilsTest.java vendored Executable file
View File

@ -0,0 +1,12 @@
package be.klak.env;
import org.junit.runner.RunWith;
import be.klak.junit.jasmine.JasmineSuite;
import be.klak.junit.jasmine.JasmineTestRunner;
@RunWith(JasmineTestRunner.class)
@JasmineSuite
public class EnvUtilsTest {
}

View File

@ -55,6 +55,7 @@
* Envjs specific hacks
* 1) Fix Envjs relative path system to work with Windows path systems
* 2) Fix window.setTimeout() using Rhino specific functions
* 3) Fix CSS2Properties support: all properties have the same objmaps, wtf?
*/
(function() {
@ -73,4 +74,17 @@
});
};
(function(css) {
var setCssProperty = css.prototype.setProperty;
css.prototype.setProperty = function(name, value) {
// create a shallow clone of __supportedStyles__ (styleIndex' default value) if prototype not yet set
if(Object.keys(Object.getPrototypeOf(this.styleIndex)).length === 0) {
this.styleIndex = Object.create(this.styleIndex);
}
return setCssProperty.call(this, name, value);
}
})(CSS2Properties);
})();

View File

@ -0,0 +1,55 @@
describe("envjs fixes", function() {
describe("CSS2 style property support", function() {
var someColor = "#FFFFFF";
var someFont = "12px 'Bitstream Vera Sans Mono','Courier',monospace";
it("should be visible and displayed by default for all new elements", function() {
var elStyle = document.createElement("b").style;
expect(elStyle.display).toBeFalsy();
expect(elStyle.visibility).toBeFalsy();
});
it("should be able to set a style value through setters", function() {
var someB = document.createElement("b");
someB.style.color = someColor;
expect(someB.style.color).toBe(someColor);
});
it("should have unique style values per DOM element", function() {
var someEl1 = document.createElement("b");
var someEl2 = document.createElement("b");
someEl1.style.color = someColor;
someEl2.style.font = someFont;
expect(someEl1.style.font).toBeFalsy();
expect(someEl2.style.color).toBeFalsy();
});
});
describe("window setTimeout", function() {
it("should wait one second before executing", function() {
var done = false;
window.setTimeout(function() {
done = true;
}, 1000);
waitsFor(function() {
return done === true;
});
runs(function() {
expect(done).toBeTruthy();
});
});
});
});