Merge pull request #7 from blalor/repackage_for_jar

Repackage for JAR
This commit is contained in:
jefklak 2012-11-24 06:36:02 -08:00
commit 56fba96f71
67 changed files with 17421 additions and 17376 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ eclipsecompiled
.classpath
.project
.settings
*.iml
.idea

0
bin/bootstrap.js vendored Executable file → Normal file
View File

0
bin/js.jar Executable file → Normal file
View File

0
bin/rhino.bat Executable file → Normal file
View File

0
bin/rhino.debug.bat Executable file → Normal file
View File

0
jasmine-junit-runner.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

7
pom.xml Executable file → Normal file
View File

@ -11,9 +11,9 @@
<dependencies>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.7R2</version>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7R4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -60,6 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>

View File

View File

0
src/main/java/be/klak/junit/jasmine/JasmineSpec.java Executable file → Normal file
View File

View File

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
class JasmineSpecRunnerGenerator {
@ -66,12 +67,17 @@ class JasmineSpecRunnerGenerator {
}
private String loadTemplate() {
String template = null;
try {
template = FileUtils.readFileToString(new File(suite.jsRootDir() + "/lib/specRunner.tpl"));
return IOUtils.toString(
Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream("js/lib/specRunner.tpl")
);
} catch (NullPointerException e) {
throw new IllegalStateException("spec runner template file not found!");
} catch (IOException e) {
throw new RuntimeException("spec runner template file not found!", e);
throw new IllegalStateException("spec runner template file could not be read!", e);
}
return template;
}
}

0
src/main/java/be/klak/junit/jasmine/JasmineSuite.java Executable file → Normal file
View File

View File

@ -4,6 +4,9 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.apache.commons.lang.StringUtils;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.Description;
@ -18,7 +21,9 @@ import be.klak.rhino.RhinoContext;
public class JasmineTestRunner extends Runner {
private static final int SLEEP_TIME_MILISECONDS = 50;
private static final String JASMINE_LIB_DIR = "/lib/jasmine-1.0.2/";
// relative to classpath
private static final String JASMINE_LIB_DIR = "js/lib/jasmine-1.0.2";
private JasmineDescriptions jasmineSuite;
@ -67,8 +72,8 @@ public class JasmineTestRunner extends Runner {
protected void pre(RhinoContext context) { }
private void setUpJasmine(RhinoContext context) {
context.load(getJsLibDir() + "jasmine.js");
context.load(getJsLibDir() + "jasmine.delegator_reporter.js");
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.js");
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.delegator_reporter.js");
context.evalJS("jasmine.getEnv().addReporter(new jasmine.DelegatorJUnitReporter());");
}
@ -106,11 +111,26 @@ public class JasmineTestRunner extends Runner {
}
private void resetEnvjsWindowSpace() {
this.rhinoContext.evalJS("window.location = '" + suiteAnnotation.jsRootDir() + "/lib/blank.html';");
}
URL blankUrl = Thread
.currentThread()
.getContextClassLoader()
.getResource("js/lib/blank.html");
private String getJsLibDir() {
return suiteAnnotation.jsRootDir() + JASMINE_LIB_DIR;
if (blankUrl == null) {
throw new IllegalStateException("Unable to load js/lib/blank.html from classpath");
}
String blankUrlStr = blankUrl.toExternalForm();
// "file:/path/to/file" is not legal, but "file:///path/to/file" is
if (blankUrlStr.startsWith("file:/") && (! blankUrlStr.startsWith("file:///"))) {
blankUrlStr = "file://" + blankUrlStr.substring(5);
}
this.rhinoContext.evalJS(String.format(
"window.location = '%s';",
blankUrlStr
));
}
private JasmineDescriptions getJasmineDescriptions() {

0
src/main/java/be/klak/rhino/ChainedErrorReporter.java Executable file → Normal file
View File

29
src/main/java/be/klak/rhino/RhinoContext.java Executable file → Normal file
View File

@ -1,5 +1,7 @@
package be.klak.rhino;
import java.net.URL;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Function;
@ -86,6 +88,24 @@ public class RhinoContext {
// Main.processFile(this.jsContext, this.jsScope, fileName);
}
// {{{ loadFromClasspath
/**
* Loads a resource from the classpath.
*
* @param resource the resource to resolve from the classpath
*/
public void loadFromClasspath(final String resource) {
URL rsrcUrl =
Thread.currentThread().getContextClassLoader().getResource(resource);
if (rsrcUrl == null) {
throw new IllegalArgumentException("resource " + resource + " not found on classpath");
}
evalJS(String.format("load('%s')", rsrcUrl.toExternalForm()));
}
// }}}
public Object executeFunction(ScriptableObject object, String fnName, Object[] arguments) {
Object fnPointer = object.get(fnName, object);
if (fnPointer == null || !(fnPointer instanceof Function)) {
@ -108,11 +128,8 @@ public class RhinoContext {
}
public void loadEnv(String jsDir) {
// TODO ensure rhino 1.7R3 instead of R2 -> geen shim nodig + paths
// gedoe in orde zetten hier
load(jsDir + "/lib/es5-shim-0.0.4.min.js");
load(jsDir + "/lib/env.rhino.1.2.js");
load(jsDir + "/lib/env.utils.js");
loadFromClasspath("js/lib/env.rhino.1.2.js");
loadFromClasspath("js/lib/env.utils.js");
load(jsDir + "/envJsOptions.js");
}
@ -125,7 +142,7 @@ public class RhinoContext {
private Context createJavascriptContext() {
Context jsContext = ContextFactory.getGlobal().enterContext();
jsContext.setOptimizationLevel(-1);
jsContext.setLanguageVersion(Context.VERSION_1_5); // TODO 1.8 plx
jsContext.setLanguageVersion(Context.VERSION_1_8);
jsContext.setErrorReporter(new ChainedErrorReporter(jsContext.getErrorReporter()));
return jsContext;
}

0
src/main/java/be/klak/rhino/RhinoRunnable.java Executable file → Normal file
View File

File diff suppressed because one or more lines are too long

View File

@ -1,191 +1,189 @@
/**
* Rhino and Envjs additions, filling the missing pieces such as a decent stacktrace
* 1) Firefox knows new Error().stack but Envjs does not.
*/
(function() {
var NEWLINE = "\r\n";
function manuallyTriggerException() {
var manuallyTriggeredExMessage = "";
try {
OEIWABEZIG
} catch(e) {
// TODO knip- en plakwerk: de eerste lijn moet natuurlijk weg etc...
return e;
}
}
function stripRhinoSpecificExceptionLines(stack) {
var ignoreTracingInStackFor = [ "env.utils.js", "org.mozilla.javascript" ];
return stack.split(NEWLINE).filter(function(stackLine) {
return ignoreTracingInStackFor.every(function(ignoreThisInTrace) {
return stackLine.indexOf(ignoreThisInTrace) < 0;
});
}).reduce(function(prev, curr) {
return prev + NEWLINE + curr;
});
}
window.Error.writeStackTrace = function(e) {
var stringWriter = new java.io.StringWriter();
var printWriter = new java.io.PrintWriter(stringWriter);
e.rhinoException.printStackTrace(printWriter);
return stringWriter.toString() + "" // I don't want the java.lang.String object!
};
window.Error.prototype.getStackTrace = function() {
// TODO add other stuff from Object.keys(new Error("bla")) (see Firebug)
var trace = this.message + NEWLINE;
if(this.stack) {
trace += this.stack;
} else if(this.rhinoException) {
trace += window.Error.writeStackTrace(this.rhinoException);
} else {
trace += stripRhinoSpecificExceptionLines(window.Error.writeStackTrace(manuallyTriggerException()));
}
return trace;
}
})();
/**
* Envjs specific hacks
* 1) Fix Envjs relative path system to work with Windows path systems
* 2) Fix CSS2Properties support for parsing style attributes: get from raw node context.
* 3) Fix CSS2Properties support for setting values: all properties have the same objmaps, wtf?
* 4) Fix focus() which sets document.activeElement correctly for jQuery:focus
* 5) Fix Input click() behavior for checkboxes. Warning: jQ's click() <-> DOM's click (checked value too late set)!
**/
(function() {
var oldEnvjsUriFn = Envjs.uri;
Envjs.uri = function(path, baseDir) {
if(baseDir) {
return oldEnvjsUriFn(path, baseDir);
}
return oldEnvjsUriFn(path, "file:///" + ("" + Envjs.getcwd()).replace(/\\/g, '/') + "/");
};
(function(Element) {
var style = "style";
function lookupStyleInNodeAttributes(el) {
if(el.attributes) {
for(var i = 0; i < el.attributes.length; i++) {
if(el.attributes[i].nodeName === style) {
return el.attributes[i].nodeValue;
}
}
}
}
var styleSetFn = Element.__lookupGetter__(style);
Element.__defineGetter__(style, function() {
if(!this.cssText) {
this.cssText = lookupStyleInNodeAttributes(this);
}
return styleSetFn.apply(this);
});
})(HTMLElement.prototype);
(function(input) {
var oldClick = input.prototype.click;
input.prototype.click = function() {
if(this.type === "checkbox") {
this.checked = !this.checked;
}
oldClick.apply(this, arguments);
}
})(HTMLInputElement);
(function(Input, Textarea, document) {
var activeElement;
function fixFocusForPrototype(element) {
var originalFocus = element.prototype.focus;
element.prototype.focus = function(element) {
activeElement = this;
originalFocus.apply(this, arguments);
}
}
fixFocusForPrototype(Input);
fixFocusForPrototype(Textarea);
document.__defineGetter__("activeElement", function() {
return activeElement;
});
})(HTMLInputElement, HTMLTextAreaElement, document);
(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);
})();
/**
* Envjs timeout fixes which use native Java code to re-implement setTimeout and setInterval
* also sets clearTimeout & clearInterval on same level.
*/
(function() {
var threadTimeoutPool = {};
window.setTimeout = function(closure, timeout) {
var thread = spawn(function() {
try {
java.lang.Thread.sleep(timeout);
closure();
} catch(e) {
// ignore InterruptedExceptions, is probably due to clearTimeout
if (!(e.javaException instanceof java.lang.InterruptedException)) {
throw(e);
}
}
});
threadTimeoutPool[thread.getId()] = thread;
return thread.getId();
};
window.setInterval = function(closure, timeout) {
var thread = spawn(function() {
try {
while(true) {
java.lang.Thread.sleep(timeout);
closure();
}
} catch(e) {
// ignore InterruptedExceptions, is probably due to clearTimeout
if (!(e.javaException instanceof java.lang.InterruptedException)) {
throw(e);
}
}
});
threadTimeoutPool[thread.getId()] = thread;
return thread.getId();
};
window.clearTimeout = function(threadId) {
if (threadId) {
if(threadTimeoutPool[threadId]) {
threadTimeoutPool[threadId].interrupt();
delete threadTimeoutPool[threadId];
}
}
};
window.clearInterval = window.clearTimeout;
})();
/**
* Rhino and Envjs additions, filling the missing pieces such as a decent stacktrace
* 1) Firefox knows new Error().stack but Envjs does not.
*/
(function() {
var NEWLINE = "\r\n";
function manuallyTriggerException() {
var manuallyTriggeredExMessage = "";
try {
OEIWABEZIG
} catch(e) {
// TODO knip- en plakwerk: de eerste lijn moet natuurlijk weg etc...
return e;
}
}
function stripRhinoSpecificExceptionLines(stack) {
var ignoreTracingInStackFor = [ "env.utils.js", "org.mozilla.javascript" ];
return stack.split(NEWLINE).filter(function(stackLine) {
return ignoreTracingInStackFor.every(function(ignoreThisInTrace) {
return stackLine.indexOf(ignoreThisInTrace) < 0;
});
}).reduce(function(prev, curr) {
return prev + NEWLINE + curr;
});
}
window.Error.writeStackTrace = function(e) {
var stringWriter = new java.io.StringWriter();
var printWriter = new java.io.PrintWriter(stringWriter);
e.rhinoException.printStackTrace(printWriter);
return stringWriter.toString() + "" // I don't want the java.lang.String object!
};
window.Error.prototype.getStackTrace = function() {
// TODO add other stuff from Object.keys(new Error("bla")) (see Firebug)
var trace = this.message + NEWLINE;
if(this.stack) {
trace += this.stack;
} else if(this.rhinoException) {
trace += window.Error.writeStackTrace(this.rhinoException);
} else {
trace += stripRhinoSpecificExceptionLines(window.Error.writeStackTrace(manuallyTriggerException()));
}
return trace;
}
})();
/**
* Envjs specific hacks
* 1) Fix Envjs relative path system to work with Windows path systems
* 2) Fix CSS2Properties support for parsing style attributes: get from raw node context.
* 3) Fix CSS2Properties support for setting values: all properties have the same objmaps, wtf?
* 4) Fix focus() which sets document.activeElement correctly for jQuery:focus
* 5) Fix Input click() behavior for checkboxes. Warning: jQ's click() <-> DOM's click (checked value too late set)!
**/
(function() {
var oldEnvjsUriFn = Envjs.uri;
Envjs.uri = function(path, baseDir) {
if(baseDir) {
return oldEnvjsUriFn(path, baseDir);
}
return oldEnvjsUriFn(path, "file:///" + ("" + Envjs.getcwd()).replace(/\\/g, '/') + "/");
};
(function(Element) {
var style = "style";
function lookupStyleInNodeAttributes(el) {
if(el.attributes) {
for(var i = 0; i < el.attributes.length; i++) {
if(el.attributes[i].nodeName === style) {
return el.attributes[i].nodeValue;
}
}
}
}
var styleSetFn = Element.__lookupGetter__(style);
Element.__defineGetter__(style, function() {
if(!this.cssText) {
this.cssText = lookupStyleInNodeAttributes(this);
}
return styleSetFn.apply(this);
});
})(HTMLElement.prototype);
(function(input) {
var oldClick = input.prototype.click;
input.prototype.click = function() {
if(this.type === "checkbox") {
this.checked = !this.checked;
}
oldClick.apply(this, arguments);
}
})(HTMLInputElement);
(function(Input, Textarea, document) {
var activeElement;
function fixFocusForPrototype(element) {
var originalFocus = element.prototype.focus;
element.prototype.focus = function(element) {
activeElement = this;
originalFocus.apply(this, arguments);
}
}
fixFocusForPrototype(Input);
fixFocusForPrototype(Textarea);
document.__defineGetter__("activeElement", function() {
return activeElement;
});
})(HTMLInputElement, HTMLTextAreaElement, document);
(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);
})();
/**
* Envjs timeout fixes which use native Java code to re-implement setTimeout and setInterval
* also sets clearTimeout & clearInterval on same level.
*/
(function() {
var threadTimeoutPool = new java.util.HashMap();
window.setTimeout = function(closure, timeout) {
var thread = spawn(function() {
try {
java.lang.Thread.sleep(timeout);
closure();
} catch(e) {
// ignore InterruptedExceptions, is probably due to clearTimeout
if (!(e.javaException instanceof java.lang.InterruptedException)) {
throw(e);
}
}
});
threadTimeoutPool.put(thread.getId(), thread);
return thread.getId();
};
window.setInterval = function(closure, timeout) {
var thread = spawn(function() {
try {
while(true) {
java.lang.Thread.sleep(timeout);
closure();
}
} catch(e) {
// ignore InterruptedExceptions, is probably due to clearTimeout
if (!(e.javaException instanceof java.lang.InterruptedException)) {
throw(e);
}
}
});
threadTimeoutPool.put(thread.getId(), thread);
return thread.getId();
};
window.clearTimeout = function(threadId) {
if (threadId) {
if(threadTimeoutPool.containsKey(threadId)) {
threadTimeoutPool.remove(threadId).interrupt();
}
}
};
window.clearInterval = window.clearTimeout;
})();

View File

@ -1,20 +1,20 @@
Copyright (c) 2008-2010 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2008-2010 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,188 +1,188 @@
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
};
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
};

View File

@ -1,64 +1,64 @@
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
/**
* Basic reporter that outputs spec results to the browser console.
* Useful if you need to test an html page and don't want the TrivialReporter
* markup mucking things up.
*
* Usage:
*
* jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
* jasmine.getEnv().execute();
*/
var ConsoleReporter = function() {
this.started = false;
this.finished = false;
};
ConsoleReporter.prototype = {
reportRunnerResults: function(runner) {
this.finished = true;
this.log("Runner Finished.");
},
reportRunnerStarting: function(runner) {
this.started = true;
this.log("Runner Started.");
},
reportSpecResults: function(spec) {
var resultText = "Failed.";
if (spec.results().passed()) {
resultText = "Passed.";
}
this.log(resultText);
},
reportSpecStarting: function(spec) {
this.log(spec.suite.description + ' : ' + spec.description + ' ... ');
},
reportSuiteResults: function(suite) {
var results = suite.results();
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.");
},
log: function(str) {
var console = jasmine.getGlobal().console;
if (console && console.log) {
console.log(str);
}
}
};
// export public
jasmine.ConsoleReporter = ConsoleReporter;
})();
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
/**
* Basic reporter that outputs spec results to the browser console.
* Useful if you need to test an html page and don't want the TrivialReporter
* markup mucking things up.
*
* Usage:
*
* jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
* jasmine.getEnv().execute();
*/
var ConsoleReporter = function() {
this.started = false;
this.finished = false;
};
ConsoleReporter.prototype = {
reportRunnerResults: function(runner) {
this.finished = true;
this.log("Runner Finished.");
},
reportRunnerStarting: function(runner) {
this.started = true;
this.log("Runner Started.");
},
reportSpecResults: function(spec) {
var resultText = "Failed.";
if (spec.results().passed()) {
resultText = "Passed.";
}
this.log(resultText);
},
reportSpecStarting: function(spec) {
this.log(spec.suite.description + ' : ' + spec.description + ' ... ');
},
reportSuiteResults: function(suite) {
var results = suite.results();
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.");
},
log: function(str) {
var console = jasmine.getGlobal().console;
if (console && console.log) {
console.log(str);
}
}
};
// export public
jasmine.ConsoleReporter = ConsoleReporter;
})();

View File

@ -1,166 +1,166 @@
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}
.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}
.jasmine_reporter {
margin: 0 5px;
}
.banner {
color: #303;
background-color: #fef;
padding: 5px;
}
.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}
.logo .version {
font-size: .6em;
padding-left: 1em;
}
.runner.running {
background-color: yellow;
}
.options {
text-align: right;
font-size: .8em;
}
.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}
.suite .suite {
margin: 5px;
}
.suite.passed {
background-color: #dfd;
}
.suite.failed {
background-color: #fdd;
}
.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}
.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}
.spec.failed {
background-color: #fbb;
border-color: red;
}
.spec.passed {
background-color: #bfb;
border-color: green;
}
.spec.skipped {
background-color: #bbb;
}
.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}
.passed {
background-color: #cfc;
display: none;
}
.failed {
background-color: #fbb;
}
.skipped {
color: #777;
background-color: #eee;
display: none;
}
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}
.resultMessage .mismatch {
color: black;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}
.finished-at {
padding-left: 1em;
font-size: .6em;
}
.show-passed .passed,
.show-skipped .skipped {
display: block;
}
#jasmine_content {
position:fixed;
right: 100%;
}
.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}
.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}
.jasmine_reporter {
margin: 0 5px;
}
.banner {
color: #303;
background-color: #fef;
padding: 5px;
}
.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}
.logo .version {
font-size: .6em;
padding-left: 1em;
}
.runner.running {
background-color: yellow;
}
.options {
text-align: right;
font-size: .8em;
}
.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}
.suite .suite {
margin: 5px;
}
.suite.passed {
background-color: #dfd;
}
.suite.failed {
background-color: #fdd;
}
.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}
.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}
.spec.failed {
background-color: #fbb;
border-color: red;
}
.spec.passed {
background-color: #bfb;
border-color: green;
}
.spec.skipped {
background-color: #bbb;
}
.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}
.passed {
background-color: #cfc;
display: none;
}
.failed {
background-color: #fbb;
}
.skipped {
color: #777;
background-color: #eee;
display: none;
}
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}
.resultMessage .mismatch {
color: black;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}
.finished-at {
padding-left: 1em;
font-size: .6em;
}
.show-passed .passed,
.show-skipped .skipped {
display: block;
}
#jasmine_content {
position:fixed;
right: 100%;
}
.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}

View File

@ -1,53 +1,53 @@
(function() {
if (!jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
/**
* Hooks up into the JUnit TestRunner system to allow Jasmine tests to run in Eclipse!
* Also sets a "done" flag on the spec itself since there is nothing like it in Jasmine
*/
var DelegatorJUnitReporter = function() {
this.javaReporter = jasmine.DelegatorJUnitReporter.javaReporter;
};
DelegatorJUnitReporter.prototype = {
reportRunnerStarting: function(runner) {
if(this.javaReporter) {
this.javaReporter.reportRunnerStarting(runner);
}
},
reportSpecStarting: function(spec) {
spec.done = false;
if(this.javaReporter) {
this.javaReporter.reportSpecStarting(spec);
}
},
reportSpecResults: function(spec) {
spec.done = true;
if(this.javaReporter) {
this.javaReporter.reportSpecResults(spec);
}
},
reportSuiteResults: function(suite) {
if(this.javaReporter) {
this.javaReporter.reportSuiteResults(suite);
}
},
reportRunnerResults: function(runner) {
if(this.javaReporter) {
this.javaReporter.reportRunnerResults(runner);
}
}
};
// export public
jasmine.DelegatorJUnitReporter = DelegatorJUnitReporter;
})();
(function() {
if (!jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
/**
* Hooks up into the JUnit TestRunner system to allow Jasmine tests to run in Eclipse!
* Also sets a "done" flag on the spec itself since there is nothing like it in Jasmine
*/
var DelegatorJUnitReporter = function() {
this.javaReporter = jasmine.DelegatorJUnitReporter.javaReporter;
};
DelegatorJUnitReporter.prototype = {
reportRunnerStarting: function(runner) {
if(this.javaReporter) {
this.javaReporter.reportRunnerStarting(runner);
}
},
reportSpecStarting: function(spec) {
spec.done = false;
if(this.javaReporter) {
this.javaReporter.reportSpecStarting(spec);
}
},
reportSpecResults: function(spec) {
spec.done = true;
if(this.javaReporter) {
this.javaReporter.reportSpecResults(spec);
}
},
reportSuiteResults: function(suite) {
if(this.javaReporter) {
this.javaReporter.reportSuiteResults(suite);
}
},
reportRunnerResults: function(runner) {
if(this.javaReporter) {
this.javaReporter.reportRunnerResults(runner);
}
}
};
// export public
jasmine.DelegatorJUnitReporter = DelegatorJUnitReporter;
})();

File diff suppressed because it is too large Load Diff

View File

@ -1,204 +1,204 @@
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
function elapsed(startTime, endTime) {
return (endTime - startTime)/1000;
}
function ISODateString(d) {
function pad(n) { return n < 10 ? '0'+n : n; }
return d.getFullYear() + '-'
+ pad(d.getMonth()+1) +'-'
+ pad(d.getDate()) + 'T'
+ pad(d.getHours()) + ':'
+ pad(d.getMinutes()) + ':'
+ pad(d.getSeconds());
}
function trim(str) {
return str.replace(/^\s+/, "" ).replace(/\s+$/, "" );
}
function escapeInvalidXmlChars(str) {
return str.replace(/\&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/\>/g, "&gt;")
.replace(/\"/g, "&quot;")
.replace(/\'/g, "&apos;");
}
/**
* Generates JUnit XML for the given spec run.
* Allows the test results to be used in java based CI
* systems like CruiseControl and Hudson.
*
* @param {string} savePath where to save the files
* @param {boolean} consolidate whether to save nested describes within the
* same file as their parent; default: true
* @param {boolean} useDotNotation whether to separate suite names with
* dots rather than spaces (ie "Class.init" not
* "Class init"); default: true
*/
var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) {
this.savePath = savePath || '';
this.consolidate = consolidate === jasmine.undefined ? true : consolidate;
this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation;
};
JUnitXmlReporter.prototype = {
reportRunnerStarting: function(runner) {
this.log("Runner Started.");
},
reportSpecStarting: function(spec) {
spec.startTime = new Date();
if (! spec.suite.startTime) {
spec.suite.startTime = spec.startTime;
}
this.log(spec.suite.description + ' : ' + spec.description + ' ... ');
},
reportSpecResults: function(spec) {
var results = spec.results();
spec.didFail = !results.passed();
spec.status = spec.didFail ? 'Failed.' : 'Passed.';
if (results.skipped) {
spec.status = 'Skipped.';
}
this.log(spec.status);
spec.duration = elapsed(spec.startTime, new Date());
spec.output = '<testcase classname="' + this.getFullName(spec.suite) +
'" name="' + escapeInvalidXmlChars(spec.description) + '" time="' + spec.duration + '">';
var failure = "";
var failures = 0;
var resultItems = results.getItems();
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'expect' && result.passed && !result.passed()) {
failures += 1;
failure += (failures + ": " + escapeInvalidXmlChars(result.trace ? result.trace.getStackTrace() : result.message) + " ");
}
}
if (failure) {
spec.output += "<failure>" + trim(failure) + "</failure>";
}
spec.output += "</testcase>";
},
reportSuiteResults: function(suite) {
var results = suite.results();
var specs = suite.specs();
var specOutput = "";
// for JUnit results, let's only include directly failed tests (not nested suites')
var failedCount = 0;
suite.status = results.passed() ? 'Passed.' : 'Failed.';
if (results.totalCount === 0) { // todo: change this to check results.skipped
suite.status = 'Skipped.';
}
// if a suite has no (active?) specs, reportSpecStarting is never called
// and thus the suite has no startTime -- account for that here
suite.startTime = suite.startTime || new Date();
suite.duration = elapsed(suite.startTime, new Date());
for (var i = 0; i < specs.length; i++) {
failedCount += specs[i].didFail ? 1 : 0;
specOutput += "\n " + specs[i].output;
}
suite.output = '\n<testsuite name="' + this.getFullName(suite) +
'" errors="0" tests="' + specs.length + '" failures="' + failedCount +
'" time="' + suite.duration + '" timestamp="' + ISODateString(suite.startTime) + '">';
suite.output += specOutput;
suite.output += "\n</testsuite>";
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " expectations passed.");
},
reportRunnerResults: function(runner) {
this.log("Runner Finished.");
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml';
var output = '<?xml version="1.0" encoding="UTF-8" ?>';
// if we are consolidating, only write out top-level suites
if (this.consolidate && suite.parentSuite) {
continue;
}
else if (this.consolidate) {
output += "\n<testsuites>";
output += this.getNestedOutput(suite);
output += "\n</testsuites>";
this.writeFile(this.savePath + fileName, output);
}
else {
output += suite.output;
this.writeFile(this.savePath + fileName, output);
}
}
},
getNestedOutput: function(suite) {
var output = suite.output;
for (var i = 0; i < suite.suites().length; i++) {
output += this.getNestedOutput(suite.suites()[i]);
}
return output;
},
writeFile: function(filename, text) {
// Rhino
try {
var out = new java.io.BufferedWriter(new java.io.FileWriter(filename));
out.write(text);
out.close();
} catch (e) {}
// PhantomJS, via pyphantomjs and the saveToFile plugin
// http://dev.umaclan.com/projects/pyphantomjs/wiki/Plugins#Save-to-File
try {
phantom.saveToFile(text, filename);
} catch (f) {
}
},
getFullName: function(suite, isFilename) {
var fullName;
if (this.useDotNotation) {
fullName = suite.description;
for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + '.' + fullName;
}
}
else {
fullName = suite.getFullName();
}
// Either remove or escape invalid XML characters
if (isFilename) {
return fullName.replace(/[^\w]/g, "");
}
return escapeInvalidXmlChars(fullName);
},
log: function(str) {
var console = jasmine.getGlobal().console;
if (console && console.log) {
console.log(str);
}
}
};
// export public
jasmine.JUnitXmlReporter = JUnitXmlReporter;
})();
(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
function elapsed(startTime, endTime) {
return (endTime - startTime)/1000;
}
function ISODateString(d) {
function pad(n) { return n < 10 ? '0'+n : n; }
return d.getFullYear() + '-'
+ pad(d.getMonth()+1) +'-'
+ pad(d.getDate()) + 'T'
+ pad(d.getHours()) + ':'
+ pad(d.getMinutes()) + ':'
+ pad(d.getSeconds());
}
function trim(str) {
return str.replace(/^\s+/, "" ).replace(/\s+$/, "" );
}
function escapeInvalidXmlChars(str) {
return str.replace(/\&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/\>/g, "&gt;")
.replace(/\"/g, "&quot;")
.replace(/\'/g, "&apos;");
}
/**
* Generates JUnit XML for the given spec run.
* Allows the test results to be used in java based CI
* systems like CruiseControl and Hudson.
*
* @param {string} savePath where to save the files
* @param {boolean} consolidate whether to save nested describes within the
* same file as their parent; default: true
* @param {boolean} useDotNotation whether to separate suite names with
* dots rather than spaces (ie "Class.init" not
* "Class init"); default: true
*/
var JUnitXmlReporter = function(savePath, consolidate, useDotNotation) {
this.savePath = savePath || '';
this.consolidate = consolidate === jasmine.undefined ? true : consolidate;
this.useDotNotation = useDotNotation === jasmine.undefined ? true : useDotNotation;
};
JUnitXmlReporter.prototype = {
reportRunnerStarting: function(runner) {
this.log("Runner Started.");
},
reportSpecStarting: function(spec) {
spec.startTime = new Date();
if (! spec.suite.startTime) {
spec.suite.startTime = spec.startTime;
}
this.log(spec.suite.description + ' : ' + spec.description + ' ... ');
},
reportSpecResults: function(spec) {
var results = spec.results();
spec.didFail = !results.passed();
spec.status = spec.didFail ? 'Failed.' : 'Passed.';
if (results.skipped) {
spec.status = 'Skipped.';
}
this.log(spec.status);
spec.duration = elapsed(spec.startTime, new Date());
spec.output = '<testcase classname="' + this.getFullName(spec.suite) +
'" name="' + escapeInvalidXmlChars(spec.description) + '" time="' + spec.duration + '">';
var failure = "";
var failures = 0;
var resultItems = results.getItems();
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'expect' && result.passed && !result.passed()) {
failures += 1;
failure += (failures + ": " + escapeInvalidXmlChars(result.trace ? result.trace.getStackTrace() : result.message) + " ");
}
}
if (failure) {
spec.output += "<failure>" + trim(failure) + "</failure>";
}
spec.output += "</testcase>";
},
reportSuiteResults: function(suite) {
var results = suite.results();
var specs = suite.specs();
var specOutput = "";
// for JUnit results, let's only include directly failed tests (not nested suites')
var failedCount = 0;
suite.status = results.passed() ? 'Passed.' : 'Failed.';
if (results.totalCount === 0) { // todo: change this to check results.skipped
suite.status = 'Skipped.';
}
// if a suite has no (active?) specs, reportSpecStarting is never called
// and thus the suite has no startTime -- account for that here
suite.startTime = suite.startTime || new Date();
suite.duration = elapsed(suite.startTime, new Date());
for (var i = 0; i < specs.length; i++) {
failedCount += specs[i].didFail ? 1 : 0;
specOutput += "\n " + specs[i].output;
}
suite.output = '\n<testsuite name="' + this.getFullName(suite) +
'" errors="0" tests="' + specs.length + '" failures="' + failedCount +
'" time="' + suite.duration + '" timestamp="' + ISODateString(suite.startTime) + '">';
suite.output += specOutput;
suite.output += "\n</testsuite>";
this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " expectations passed.");
},
reportRunnerResults: function(runner) {
this.log("Runner Finished.");
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var fileName = 'TEST-' + this.getFullName(suite, true) + '.xml';
var output = '<?xml version="1.0" encoding="UTF-8" ?>';
// if we are consolidating, only write out top-level suites
if (this.consolidate && suite.parentSuite) {
continue;
}
else if (this.consolidate) {
output += "\n<testsuites>";
output += this.getNestedOutput(suite);
output += "\n</testsuites>";
this.writeFile(this.savePath + fileName, output);
}
else {
output += suite.output;
this.writeFile(this.savePath + fileName, output);
}
}
},
getNestedOutput: function(suite) {
var output = suite.output;
for (var i = 0; i < suite.suites().length; i++) {
output += this.getNestedOutput(suite.suites()[i]);
}
return output;
},
writeFile: function(filename, text) {
// Rhino
try {
var out = new java.io.BufferedWriter(new java.io.FileWriter(filename));
out.write(text);
out.close();
} catch (e) {}
// PhantomJS, via pyphantomjs and the saveToFile plugin
// http://dev.umaclan.com/projects/pyphantomjs/wiki/Plugins#Save-to-File
try {
phantom.saveToFile(text, filename);
} catch (f) {
}
},
getFullName: function(suite, isFilename) {
var fullName;
if (this.useDotNotation) {
fullName = suite.description;
for (var parentSuite = suite.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + '.' + fullName;
}
}
else {
fullName = suite.getFullName();
}
// Either remove or escape invalid XML characters
if (isFilename) {
return fullName.replace(/[^\w]/g, "");
}
return escapeInvalidXmlChars(fullName);
},
log: function(str) {
var console = jasmine.getGlobal().console;
if (console && console.log) {
console.log(str);
}
}
};
// export public
jasmine.JUnitXmlReporter = JUnitXmlReporter;
})();

View File

@ -1,23 +1,23 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="./../lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine-html.js"></script>
<!-- dit zijn de productie source js files: -->
<!--SourceFileIncludes-->
<!-- dit zijn de jasmine spec js files: -->
<!--SpecFileIncludes-->
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="./../lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine-html.js"></script>
<!-- dit zijn de productie source js files: -->
<!--SourceFileIncludes-->
<!-- dit zijn de jasmine spec js files: -->
<!--SpecFileIncludes-->
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

2
src/test/java/be/klak/env/EnvUtilsTest.java vendored Executable file → Normal file
View File

@ -13,7 +13,7 @@ public class EnvUtilsTest {
@Before
public void loadJasmineJQueryMatchers(RhinoContext context) {
context.load("src/test/javascript/lib/jasmine-1.0.2/jasmine-jquery-rhino.js");
context.loadFromClasspath("js/lib/jasmine-1.0.2/jasmine-jquery-rhino.js");
}
}

View File

View File

0
src/test/java/be/klak/rhino/ClassInJS.java Executable file → Normal file
View File

View File

View File

10
src/test/java/be/klak/rhino/RhinoContextTest.java Executable file → Normal file
View File

@ -80,4 +80,14 @@ public class RhinoContextTest {
assertThat(context.evalJS("loaded")).isEqualTo(true);
assertThat(context.evalJS("loadedTwo")).isEqualTo(true);
}
// {{{ loadsJSFilesFromClasspath
@Test
public void loadsJSFilesFromClasspath() {
RhinoContext context = new RhinoContext();
context.loadFromClasspath("js/lib/loadsJSFilesFromClasspathTarget.js");
assertThat(context.evalJS("target.theAnswer")).isEqualTo("forty two");
}
// }}}
}

0
src/test/javascript/envJsOptions.js Executable file → Normal file
View File

0
src/test/javascript/jquery-1.6.1.js vendored Executable file → Normal file
View File

View File

@ -1,13 +0,0 @@
(function(){var j=Object.prototype.hasOwnProperty;if(!Array.isArray)Array.isArray=function(a){return Object.prototype.toString.call(a)=="[object Array]"};if(!Array.prototype.forEach)Array.prototype.forEach=function(a,c){for(var b=this.length>>>0,d=0;d<b;d++)d in this&&a.call(c,this[d],d,this)};if(!Array.prototype.map)Array.prototype.map=function(a,c){var b=this.length>>>0;if(typeof a!="function")throw new TypeError;for(var d=Array(b),e=0;e<b;e++)if(e in this)d[e]=a.call(c,this[e],e,this);return d};
if(!Array.prototype.filter)Array.prototype.filter=function(a,c){for(var b=[],d=0;d<this.length;d++)a.call(c,this[d])&&b.push(this[d]);return b};if(!Array.prototype.every)Array.prototype.every=function(a,c){for(var b=0;b<this.length;b++)if(!a.call(c,this[b]))return false;return true};if(!Array.prototype.some)Array.prototype.some=function(a,c){for(var b=0;b<this.length;b++)if(a.call(c,this[b]))return true;return false};if(!Array.prototype.reduce)Array.prototype.reduce=function(a){var c=this.length>>>
0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;var b=0;if(arguments.length>=2)var d=arguments[1];else{do{if(b in this){d=this[b++];break}if(++b>=c)throw new TypeError;}while(1)}for(;b<c;b++)if(b in this)d=a.call(null,d,this[b],b,this);return d};if(!Array.prototype.reduceRight)Array.prototype.reduceRight=function(a){var c=this.length>>>0;if(typeof a!="function")throw new TypeError;if(c==0&&arguments.length==1)throw new TypeError;c=c-1;if(arguments.length>=
2)var b=arguments[1];else{do{if(c in this){b=this[c--];break}if(--c<0)throw new TypeError;}while(1)}for(;c>=0;c--)if(c in this)b=a.call(null,b,this[c],c,this);return b};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a,c){var b=this.length;if(!b)return-1;var d=c||0;if(d>=b)return-1;if(d<0)d+=b;for(;d<b;d++)if(j.call(this,d))if(a===this[d])return d;return-1};if(!Array.prototype.lastIndexOf)Array.prototype.lastIndexOf=function(a,c){var b=this.length;if(!b)return-1;var d=c||b;if(d<0)d+=
b;for(d=Math.min(d,b-1);d>=0;d--)if(j.call(this,d))if(a===this[d])return d;return-1};if(!Object.getPrototypeOf)Object.getPrototypeOf=function(a){return a.__proto__||a.constructor.prototype};if(!Object.getOwnPropertyDescriptor)Object.getOwnPropertyDescriptor=function(){return{}};if(!Object.getOwnPropertyNames)Object.getOwnPropertyNames=function(a){return Object.keys(a)};if(!Object.create)Object.create=function(a,c){var b;if(a===null)b={__proto__:null};else{if(typeof a!="object")throw new TypeError("typeof prototype["+
typeof a+"] != 'object'");b=function(){};b.prototype=a;b=new b}typeof c!=="undefined"&&Object.defineProperties(b,c);return b};if(!Object.defineProperty)Object.defineProperty=function(a,c,b){if(typeof b=="object"&&a.__defineGetter__){if(j.call(b,"value")){if(!a.__lookupGetter__(c)&&!a.__lookupSetter__(c))a[c]=b.value;if(j.call(b,"get")||j.call(b,"set"))throw new TypeError("Object doesn't support this action");}else typeof b.get=="function"&&a.__defineGetter__(c,b.get);typeof b.set=="function"&&a.__defineSetter__(c,
b.set)}return a};if(!Object.defineProperties)Object.defineProperties=function(a,c){for(var b in c)j.call(c,b)&&Object.defineProperty(a,b,c[b]);return a};if(!Object.seal)Object.seal=function(a){return a};if(!Object.freeze)Object.freeze=function(a){return a};try{Object.freeze(function(){})}catch(u){Object.freeze=function(a){return function(c){return typeof c=="function"?c:a(c)}}(Object.freeze)}if(!Object.preventExtensions)Object.preventExtensions=function(a){return a};if(!Object.isSealed)Object.isSealed=
function(){return false};if(!Object.isFrozen)Object.isFrozen=function(){return false};if(!Object.isExtensible)Object.isExtensible=function(){return true};if(!Object.keys){var m=true,n=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],p=n.length,q;for(q in{toString:null})m=false;Object.keys=function(a){if(typeof a!=="object"&&typeof a!=="function"||a===null)throw new TypeError("Object.keys called on a non-object");var c=[],b;for(b in a)j.call(a,
b)&&c.push(b);if(m)for(b=0;b<p;b++){var d=n[b];j.call(a,d)&&c.push(d)}return c}}if(!Date.prototype.toISOString)Date.prototype.toISOString=function(){return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate()+"T"+this.getHours()+":"+this.getMinutes()+":"+this.getSeconds()+"Z"};if(!Date.now)Date.now=function(){return(new Date).getTime()};if(!Date.prototype.toJSON)Date.prototype.toJSON=function(){if(typeof this.toISOString!="function")throw new TypeError;return this.toISOString()};if(isNaN(Date.parse("T00:00")))Date=
function(a){var c=function(e,f,h,g,k,o,r){var i=arguments.length;if(this instanceof a){i=i===1&&String(e)===e?new a(c.parse(e)):i>=7?new a(e,f,h,g,k,o,r):i>=6?new a(e,f,h,g,k,o):i>=5?new a(e,f,h,g,k):i>=4?new a(e,f,h,g):i>=3?new a(e,f,h):i>=2?new a(e,f):i>=1?new a(e):new a;i.constructor=c;return i}return a.apply(this,arguments)},b=RegExp("^(?:((?:[+-]\\d\\d)?\\d\\d\\d\\d)(?:-(\\d\\d)(?:-(\\d\\d))?)?)?(?:T(\\d\\d):(\\d\\d)(?::(\\d\\d)(?:\\.(\\d\\d\\d))?)?)?(?:Z|([+-])(\\d\\d):(\\d\\d))?$"),d;for(d in a)c[d]=
a[d];c.now=a.now;c.UTC=a.UTC;c.prototype=a.prototype;c.prototype.constructor=c;c.parse=function(e){var f=b.exec(e);if(f){f.shift();for(var h=f[0]===undefined,g=0;g<10;g++)if(g!==7){f[g]=+(f[g]||(g<3?1:0));g===1&&f[g]--}if(h)return((f[3]*60+f[4])*60+f[5])*1E3+f[6];h=(f[8]*60+f[9])*60*1E3;if(f[6]==="-")h=-h;return a.UTC.apply(this,f.slice(0,7))+h}return a.parse.apply(this,arguments)};return c}(Date);var l=Array.prototype.slice;if(!Function.prototype.bind)Function.prototype.bind=function(a){var c=this;
if(typeof c.apply!="function"||typeof c.call!="function")return new TypeError;var b=l.call(arguments),d=function(){if(this instanceof d){var e=Object.create(c.prototype);c.apply(e,b.concat(l.call(arguments)));return e}else return c.call.apply(c,b.concat(l.call(arguments)))};d.bound=c;d.boundTo=a;d.boundArgs=b;d.length=typeof c=="function"?Math.max(c.length-b.length,0):0;return d};if(!String.prototype.trim){var s=/^\s\s*/,t=/\s\s*$/;String.prototype.trim=function(){return String(this).replace(s,"").replace(t,
"")}}})();

0
src/test/javascript/loadTest.js Executable file → Normal file
View File

0
src/test/javascript/loadTestTwo.js Executable file → Normal file
View File

View File

@ -1,27 +1,27 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="./../lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine-html.js"></script>
<!-- dit zijn de productie source js files: -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="./../lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="./../lib/jasmine-1.0.2/jasmine-html.js"></script>
<!-- dit zijn de productie source js files: -->
<script type='text/javascript' src='./../../../main/webapp/js/source1.js'></script>
<script type='text/javascript' src='./../../../main/webapp/js/source2.js'></script>
<!-- dit zijn de jasmine spec js files: -->
<!-- dit zijn de jasmine spec js files: -->
<script type='text/javascript' src='./../specs/spec1.js'></script>
<script type='text/javascript' src='./../specs/spec2.js'></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

0
src/test/javascript/sources/source1.js Executable file → Normal file
View File

0
src/test/javascript/sources/source2.js Executable file → Normal file
View File

0
src/test/javascript/specs/crashingJSCode.js Executable file → Normal file
View File

0
src/test/javascript/specs/crashingSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/emptySpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/envUtilsSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/failingSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/fixtures/formevents.html vendored Executable file → Normal file
View File

0
src/test/javascript/specs/fixtures/styleAttributes.html vendored Executable file → Normal file
View File

0
src/test/javascript/specs/recursiveSpec.js Executable file → Normal file
View File

0
src/test/javascript/specs/spec1.js Executable file → Normal file
View File

0
src/test/javascript/specs/spec2.js Executable file → Normal file
View File

View File

@ -0,0 +1,4 @@
// loadsJSFilesFromClasspathTarget.js
var target = {
theAnswer: "forty two"
};