com.github.searls.jasmine.runner.AbstractSpecRunnerHtmlGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasmine-maven-plugin Show documentation
Show all versions of jasmine-maven-plugin Show documentation
A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with HtmlUnit, and produces JUnit XML reports
package com.github.searls.jasmine.runner;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.codehaus.plexus.util.StringUtils;
import org.stringtemplate.v4.ST;
import com.github.searls.jasmine.format.FormatsScriptTags;
public abstract class AbstractSpecRunnerHtmlGenerator {
private static final String SOURCE_ENCODING = "sourceEncoding";
private static final String CSS_DEPENDENCIES_TEMPLATE_ATTR_NAME = "cssDependencies";
protected static final String JAVASCRIPT_DEPENDENCIES_TEMPLATE_ATTR_NAME = "javascriptDependencies";
protected static final String SOURCES_TEMPLATE_ATTR_NAME = "sources";
protected static final String REPORTER_ATTR_NAME = "reporter";
private final HtmlGeneratorConfiguration configuration;
private final FormatsScriptTags formatsScriptTags = new FormatsScriptTags();
protected AbstractSpecRunnerHtmlGenerator(HtmlGeneratorConfiguration configuration) {
this.configuration = configuration;
}
protected void setEncoding(HtmlGeneratorConfiguration htmlGeneratorConfiguration, ST template) {
template.add(SOURCE_ENCODING, StringUtils.isNotBlank(htmlGeneratorConfiguration.getSourceEncoding()) ? htmlGeneratorConfiguration.getSourceEncoding() : SpecRunnerHtmlGenerator.DEFAULT_SOURCE_ENCODING);
}
protected ST resolveHtmlTemplate() throws IOException {
String htmlTemplate = configuration.getRunnerTemplate();
return new ST(htmlTemplate,'$','$');
}
protected void applyCssToTemplate(List styles, ST template) throws IOException {
StringBuilder css = new StringBuilder();
for (String cssFile : styles) {
css.append("");
}
template.add(CSS_DEPENDENCIES_TEMPLATE_ATTR_NAME, css.toString());
}
public HtmlGeneratorConfiguration getConfiguration() {
return configuration;
}
protected void applyScriptTagsToTemplate(String sourcesTemplateAttrName, Collection scripts, ST template) throws IOException {
template.add(sourcesTemplateAttrName, formatsScriptTags.format(scripts));
}
}