Merge branch 'master' of https://github.com/jefklak/jasmine-junit-runner into repackage_for_jar
This commit is contained in:
commit
c284748800
|
@ -103,6 +103,7 @@ You can still use Firebug to debug when generating a specRunner HTML file (see b
|
||||||
* specs: one or more spec file to run. Default behavior: use java Class name (replaces Test with Spec, see example)
|
* specs: one or more spec file to run. Default behavior: use java Class name (replaces Test with Spec, see example)
|
||||||
* sources: one or more JS production file which your spec needs (included before specs, d'uh)
|
* sources: one or more JS production file which your spec needs (included before specs, d'uh)
|
||||||
* generateSpecRunner: (the HTML output, useful for firefox/firebug debugging etc)
|
* generateSpecRunner: (the HTML output, useful for firefox/firebug debugging etc)
|
||||||
|
* envJs: load EnvJS support (defaults to true)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,9 @@ public @interface JasmineSuite {
|
||||||
boolean generateSpecRunner() default false;
|
boolean generateSpecRunner() default false;
|
||||||
|
|
||||||
boolean debug() default false;
|
boolean debug() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to false, does not load EnvJS support.
|
||||||
|
*/
|
||||||
|
boolean envJs() default true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,7 @@ public class JasmineTestRunner extends Runner {
|
||||||
private final Class<?> testClass;
|
private final Class<?> testClass;
|
||||||
|
|
||||||
@JasmineSuite
|
@JasmineSuite
|
||||||
private class DefaultSuite {
|
private class DefaultSuite { }
|
||||||
}
|
|
||||||
|
|
||||||
public JasmineTestRunner(Class<?> testClass) {
|
public JasmineTestRunner(Class<?> testClass) {
|
||||||
this.testClass = testClass;
|
this.testClass = testClass;
|
||||||
|
@ -56,16 +55,21 @@ public class JasmineTestRunner extends Runner {
|
||||||
|
|
||||||
pre(context);
|
pre(context);
|
||||||
|
|
||||||
|
if (suiteAnnotation.envJs()) {
|
||||||
context.loadEnv(suiteAnnotation.jsRootDir());
|
context.loadEnv(suiteAnnotation.jsRootDir());
|
||||||
|
} else {
|
||||||
|
context.load(suiteAnnotation.jsRootDir(), "/lib/no-env.js");
|
||||||
|
}
|
||||||
|
|
||||||
setUpJasmine(context);
|
setUpJasmine(context);
|
||||||
|
|
||||||
context.load(suiteAnnotation.sourcesRootDir() + "/", suiteAnnotation.sources());
|
context.load(suiteAnnotation.sourcesRootDir() + "/", suiteAnnotation.sources());
|
||||||
context.load(suiteAnnotation.jsRootDir() + "/specs/", getJasmineSpecs(suiteAnnotation));
|
context.load(suiteAnnotation.jsRootDir() + "/specs/", getJasmineSpecs(suiteAnnotation));
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void pre(RhinoContext context) {
|
protected void pre(RhinoContext context) { }
|
||||||
}
|
|
||||||
|
|
||||||
private void setUpJasmine(RhinoContext context) {
|
private void setUpJasmine(RhinoContext context) {
|
||||||
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.js");
|
context.loadFromClasspath(JASMINE_LIB_DIR + "/jasmine.js");
|
||||||
|
@ -158,7 +162,10 @@ public class JasmineTestRunner extends Runner {
|
||||||
}
|
}
|
||||||
|
|
||||||
reportSpecResultToNotifier(notifier, spec);
|
reportSpecResultToNotifier(notifier, spec);
|
||||||
|
|
||||||
|
if (suiteAnnotation.envJs()) {
|
||||||
resetEnvjsWindowSpace();
|
resetEnvjsWindowSpace();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fireMethodsWithSpecifiedAnnotationIfAny(testClassInstance, After.class);
|
fireMethodsWithSpecifiedAnnotationIfAny(testClassInstance, After.class);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +178,6 @@ public class JasmineTestRunner extends Runner {
|
||||||
this.rhinoContext.exit();
|
this.rhinoContext.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object createTestClassInstance() {
|
private Object createTestClassInstance() {
|
||||||
try {
|
try {
|
||||||
return testClass.newInstance();
|
return testClass.newInstance();
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.mozilla.javascript.EvaluatorException;
|
import org.mozilla.javascript.EvaluatorException;
|
||||||
|
|
||||||
import be.klak.junit.jasmine.JasmineTestRunner;
|
|
||||||
import be.klak.junit.jasmine.classes.JasmineTestRunnerExceptionInJSCode;
|
import be.klak.junit.jasmine.classes.JasmineTestRunnerExceptionInJSCode;
|
||||||
import be.klak.junit.jasmine.classes.JasmineTestRunnerExceptionInSpec;
|
import be.klak.junit.jasmine.classes.JasmineTestRunnerExceptionInSpec;
|
||||||
import be.klak.junit.jasmine.classes.JasmineTestRunnerFailingSpec;
|
import be.klak.junit.jasmine.classes.JasmineTestRunnerFailingSpec;
|
||||||
|
@ -58,7 +57,7 @@ public class JasmineFailingSpecsTest {
|
||||||
|
|
||||||
assertThat(failure.getDescription()).isEqualTo(startedDescription);
|
assertThat(failure.getDescription()).isEqualTo(startedDescription);
|
||||||
assertThat(failure.getDescription().getDisplayName()).isEqualTo("will always crash");
|
assertThat(failure.getDescription().getDisplayName()).isEqualTo("will always crash");
|
||||||
assertThat(failure.getMessage()).isEqualTo("ReferenceError: \"OEIWANU\" is not defined. in src/test/javascript/specs/crashingSpec.js (line 3)");
|
assertThat(failure.getMessage()).contains("ReferenceError: \"OEIWANU\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EvaluatorException.class)
|
@Test(expected = EvaluatorException.class)
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import be.klak.junit.jasmine.JasmineTestRunner;
|
import be.klak.junit.jasmine.JasmineTestRunner;
|
||||||
import be.klak.junit.jasmine.classes.JasmineTestRunnerSuccessSpec;
|
import be.klak.junit.jasmine.classes.JasmineTestRunnerSuccessSpec;
|
||||||
|
import be.klak.junit.jasmine.classes.JasmineTestRunnerDoesNotLoadEnvJS;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class JasmineFinishedSpecsTest {
|
public class JasmineFinishedSpecsTest {
|
||||||
|
@ -38,4 +39,21 @@ public class JasmineFinishedSpecsTest {
|
||||||
assertThat(startedDescription.getDisplayName()).isEqualTo("will always run");
|
assertThat(startedDescription.getDisplayName()).isEqualTo("will always run");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void doesNotLoadEnvJsWhenSoConfigured() {
|
||||||
|
new JasmineTestRunner(JasmineTestRunnerDoesNotLoadEnvJS.class).run(notifierMock);
|
||||||
|
|
||||||
|
ArgumentCaptor<Description> descriptionStartedCaptor = ArgumentCaptor.forClass(Description.class);
|
||||||
|
ArgumentCaptor<Description> descriptionFinishedCaptor = ArgumentCaptor.forClass(Description.class);
|
||||||
|
verify(notifierMock).fireTestStarted(descriptionStartedCaptor.capture());
|
||||||
|
verify(notifierMock).fireTestFinished(descriptionFinishedCaptor.capture());
|
||||||
|
verifyNoMoreInteractions(notifierMock);
|
||||||
|
|
||||||
|
Description startedDescription = descriptionStartedCaptor.getValue();
|
||||||
|
Description finishedDescription = descriptionFinishedCaptor.getValue();
|
||||||
|
|
||||||
|
assertThat(startedDescription).isSameAs(finishedDescription);
|
||||||
|
assertThat(startedDescription.getDisplayName()).isEqualTo("is not loaded");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package be.klak.junit.jasmine.classes;
|
||||||
|
|
||||||
|
import be.klak.junit.jasmine.JasmineSuite;
|
||||||
|
|
||||||
|
@JasmineSuite(specs = { "doesNotLoadEnvJSSpec.js" }, envJs = false)
|
||||||
|
public class JasmineTestRunnerDoesNotLoadEnvJS { }
|
|
@ -12,7 +12,7 @@ import be.klak.rhino.RhinoContext;
|
||||||
public class RhinoContextEnvjsLoadingTest {
|
public class RhinoContextEnvjsLoadingTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadEnvShouldSetWindowSpaceAndBeES5Complaint() {
|
public void loadEnvJSShouldSetWindowSpaceAndBeES5Complaint() {
|
||||||
RhinoContext context = new RhinoContext();
|
RhinoContext context = new RhinoContext();
|
||||||
|
|
||||||
context.loadEnv("src/test/javascript");
|
context.loadEnv("src/test/javascript");
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
// shim to allow jasmine to run in Rhino without EnvJS loaded
|
||||||
|
// inspired by
|
||||||
|
// https://groups.google.com/d/msg/jasmine-js/waor9RXUsDw/LY6gNLcMxkcJ
|
||||||
|
// implementation stolen from env.utils.js
|
||||||
|
|
||||||
|
(function(global) {
|
||||||
|
var threadTimeoutPool = new java.util.HashMap();
|
||||||
|
|
||||||
|
global.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();
|
||||||
|
};
|
||||||
|
|
||||||
|
global.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();
|
||||||
|
};
|
||||||
|
|
||||||
|
global.clearTimeout = function(threadId) {
|
||||||
|
if (threadId) {
|
||||||
|
if(threadTimeoutPool.containsKey(threadId)) {
|
||||||
|
threadTimeoutPool.remove(threadId).interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
global.clearInterval = global.clearTimeout;
|
||||||
|
})(this);
|
|
@ -0,0 +1,5 @@
|
||||||
|
describe("EnvJS", function() {
|
||||||
|
it("is not loaded", function() {
|
||||||
|
expect(typeof(window)).toBe('undefined');
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue