Merge pull request #8 from mederel/master
Added sub dir feature for the HTML runner generation
This commit is contained in:
commit
277e44ca0a
|
@ -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)
|
||||
* 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)
|
||||
* specRunnerSubDir: a subsidiary path to the default runner root directory where generated spec runners will be placed
|
||||
* envJs: load EnvJS support (defaults to true)
|
||||
|
||||
## Requirements
|
||||
|
|
|
@ -3,6 +3,8 @@ package be.klak.junit.jasmine;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JasmineSuite {
|
||||
|
||||
|
@ -22,4 +24,6 @@ public @interface JasmineSuite {
|
|||
* If set to false, does not load EnvJS support.
|
||||
*/
|
||||
boolean envJs() default true;
|
||||
|
||||
String specRunnerSubDir() default StringUtils.EMPTY;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class JasmineTestRunner extends Runner {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -212,7 +212,11 @@ public class JasmineTestRunner extends Runner {
|
|||
private void generateSpecRunnerIfNeeded() {
|
||||
if (suiteAnnotation.generateSpecRunner()) {
|
||||
String[] jasmineSpecs = getJasmineSpecs(suiteAnnotation);
|
||||
new JasmineSpecRunnerGenerator(jasmineSpecs, suiteAnnotation, suiteAnnotation.jsRootDir() + "/runners",
|
||||
StringBuffer outputPath = new StringBuffer(suiteAnnotation.jsRootDir()).append("/runners");
|
||||
if (StringUtils.isNotBlank(suiteAnnotation.specRunnerSubDir())) {
|
||||
outputPath.append('/').append(suiteAnnotation.specRunnerSubDir());
|
||||
}
|
||||
new JasmineSpecRunnerGenerator(jasmineSpecs, suiteAnnotation, outputPath.toString(),
|
||||
testClass.getSimpleName()
|
||||
+ "Runner.html")
|
||||
.generate();
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -16,6 +17,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
|||
|
||||
import be.klak.junit.jasmine.JasmineTestRunner;
|
||||
import be.klak.junit.jasmine.classes.JasmineSuiteGeneratorClassWithRunner;
|
||||
import be.klak.junit.jasmine.classes.JasmineSuiteGeneratorClassWithRunnerInSubDir;
|
||||
import be.klak.junit.jasmine.classes.JasmineSuiteGeneratorClassWithoutRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
@ -57,8 +59,41 @@ public class JasmineSuiteGeneratesRunnerTest {
|
|||
"./../specs/spec2.js");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateJasmineTestRunnerAfterRunningTestsWithSubDir() throws IOException {
|
||||
Class<JasmineSuiteGeneratorClassWithRunnerInSubDir> testClass =
|
||||
JasmineSuiteGeneratorClassWithRunnerInSubDir.class;
|
||||
new JasmineTestRunner(testClass).run(notifierMock);
|
||||
|
||||
File runnerResult = getTestRunnerResultFile(testClass, "subDir1/subDir2");
|
||||
assertThat(runnerResult.isFile()).isTrue();
|
||||
|
||||
String runnerContent = FileUtils.readFileToString(runnerResult);
|
||||
|
||||
assertThat(runnerContent).contains("jasmine.getEnv().addReporter(new jasmine.TrivialReporter());");
|
||||
assertJSFileIncluded(runnerContent,
|
||||
"./../../../main/webapp/js/source1.js",
|
||||
"./../../../main/webapp/js/source2.js",
|
||||
"./../specs/spec1.js",
|
||||
"./../specs/spec2.js");
|
||||
|
||||
}
|
||||
|
||||
private File getTestRunnerResultFile(Class<?> testClass) {
|
||||
return new File(RUNNERS_OUTPUT_DIR + testClass.getSimpleName() + "Runner.html");
|
||||
return getTestRunnerResultFile(testClass, StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
// private File getTestRunnerResultFile(Class<?> testClass) {
|
||||
// return new File(RUNNERS_OUTPUT_DIR + testClass.getSimpleName() + "Runner.html");
|
||||
// }
|
||||
|
||||
private File getTestRunnerResultFile(Class<?> testClass, String subDir) {
|
||||
StringBuffer filePath = new StringBuffer(RUNNERS_OUTPUT_DIR);
|
||||
if (StringUtils.isNotBlank(subDir)) {
|
||||
filePath.append(subDir).append('/');
|
||||
}
|
||||
filePath.append(testClass.getSimpleName()).append("Runner.html");
|
||||
return new File(filePath.toString());
|
||||
}
|
||||
|
||||
private void assertJSFileIncluded(String rawContent, String... files) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package be.klak.junit.jasmine.classes;
|
||||
|
||||
import be.klak.junit.jasmine.JasmineSuite;
|
||||
|
||||
@JasmineSuite(
|
||||
specs = { "spec1.js", "spec2.js" },
|
||||
sources = { "source1.js", "source2.js" },
|
||||
sourcesRootDir = "src/test/javascript/sources/",
|
||||
generateSpecRunner = true,
|
||||
specRunnerSubDir = "subDir1/subDir2")
|
||||
public class JasmineSuiteGeneratorClassWithRunnerInSubDir {
|
||||
|
||||
}
|
Reference in New Issue