use of com.google.jstestdriver.config.ParsedConfiguration in project intellij-plugins by JetBrains.
the class TestRunner method runTests.
@SuppressWarnings("deprecation")
private void runTests(@NotNull final File configFile, @NotNull String[] extraArgs, final boolean dryRun) throws ConfigurationException {
JsTestDriverBuilder builder = new JsTestDriverBuilder();
final ParsedConfiguration parsedConfiguration;
try {
parsedConfiguration = JstdConfigParsingUtils.parseConfiguration(configFile);
} catch (Exception e) {
throw new ConfigurationException("Configuration file parsing failed.\n" + "See http://code.google.com/p/js-test-driver/wiki/ConfigurationFile for clarification.\n\n" + "Details:", e);
}
final File singleBasePath = JstdConfigParsingUtils.getSingleBasePath(parsedConfiguration.getBasePaths(), configFile);
myTreeManager.setCurrentBasePath(singleBasePath.getAbsolutePath());
JstdConfigParsingUtils.wipeCoveragePlugin(parsedConfiguration);
builder.setDefaultConfiguration(parsedConfiguration);
builder.withPluginInitializer(new PluginInitializer() {
@Override
public Module initializeModule(Flags flags, Configuration config) {
return new AbstractModule() {
@Override
public void configure() {
Multibinder<TestListener> testListeners = Multibinder.newSetBinder(binder(), TestListener.class);
testListeners.addBinding().to(TestResultHolder.class);
testListeners.addBinding().toInstance(new IdeaTestListener(myTreeManager, configFile, singleBasePath, dryRun, mySettings.getTestFileScope()));
}
};
}
});
builder.setRunnerMode(RunnerMode.QUIET);
builder.setServer(mySettings.getServerUrl());
List<String> flagArgs = Lists.newArrayList("--captureConsole", "--server", mySettings.getServerUrl());
ResolvedConfiguration resolvedConfiguration = JstdConfigParsingUtils.resolveConfiguration(parsedConfiguration);
if (dryRun && JstdUtils.isJasmineTests(resolvedConfiguration)) {
// https://github.com/ibolmo/jasmine-jstd-adapter/pull/21
flagArgs.add("--reset");
}
flagArgs.addAll(Arrays.asList(extraArgs));
List<String> coverageExcludedFiles = null;
File emptyOutputDir = null;
boolean runCoverage = false;
if (myCoverageSession != null && !dryRun) {
emptyOutputDir = createTempDir();
if (emptyOutputDir != null) {
flagArgs.add("--testOutput");
flagArgs.add(emptyOutputDir.getAbsolutePath());
List<String> testPaths = getTestFilePaths(resolvedConfiguration);
coverageExcludedFiles = Lists.newArrayList(testPaths);
coverageExcludedFiles.addAll(mySettings.getFilesExcludedFromCoverageRec());
PluginInitializer coverageInitializer = getCoverageInitializer(coverageExcludedFiles);
if (coverageInitializer != null) {
builder.withPluginInitializer(coverageInitializer);
builder.withPluginInitializer(new DependenciesTouchFix());
runCoverage = true;
}
}
}
builder.setFlags(toStringArray(flagArgs));
builder.setFlagsParser(new IntelliJFlagParser(mySettings, dryRun));
JsTestDriver jstd = builder.build();
jstd.runConfiguration();
if (runCoverage) {
File[] coverageReportFiles = emptyOutputDir.listFiles((dir, name) -> name.endsWith("-coverage.dat"));
if (coverageReportFiles != null && coverageReportFiles.length == 1) {
try {
CoverageReport coverageReport = CoverageSerializationUtils.readLCOV(coverageReportFiles[0]);
for (String excludedPath : coverageExcludedFiles) {
coverageReport.clearReportByFilePath(excludedPath);
}
myCoverageSession.mergeReport(coverageReport);
} catch (Exception e) {
myTreeManager.printThrowable(e);
}
}
}
}
use of com.google.jstestdriver.config.ParsedConfiguration in project intellij-plugins by JetBrains.
the class JstdTestFilePathIndex method doIndexConfigFile.
@NotNull
private static Map<String, Void> doIndexConfigFile(@NotNull Reader configFileReader, @NotNull BasePaths initialBasePaths) {
YamlParser yamlParser = new YamlParser();
final Map<String, Void> map = new THashMap<>();
ParsedConfiguration parsedConfiguration = (ParsedConfiguration) yamlParser.parse(configFileReader, initialBasePaths);
PathResolver pathResolver = new PathResolver(parsedConfiguration.getBasePaths(), Collections.emptySet(), new DisplayPathSanitizer());
FlagsImpl flags = new FlagsImpl();
flags.setServer("test:1");
ResolvedConfiguration resolvedConfiguration = (ResolvedConfiguration) parsedConfiguration.resolvePaths(pathResolver, flags);
doPutAll(map, resolvedConfiguration.getTests());
doPutAll(map, resolvedConfiguration.getFilesList());
return map;
}
use of com.google.jstestdriver.config.ParsedConfiguration in project intellij-plugins by JetBrains.
the class JstdDebuggingFileFinderProvider method resolveConfiguration.
@NotNull
private ResolvedConfiguration resolveConfiguration() throws ExecutionException {
VirtualFile configVirtualFile = VfsUtil.findFileByIoFile(myConfigFile, false);
if (configVirtualFile == null) {
throw new ExecutionException("Cannot find JsTestDriver configuration file " + myConfigFile.getAbsolutePath());
}
BasePaths dirBasePaths = new BasePaths(myConfigFile.getParentFile());
final byte[] content;
try {
content = configVirtualFile.contentsToByteArray();
} catch (IOException e) {
throw new ExecutionException("Cannot read JsTestDriver configuration file " + configVirtualFile.getPath());
}
Reader reader = new InputStreamReader(new ByteArrayInputStream(content), Charset.defaultCharset());
try {
YamlParser yamlParser = new YamlParser();
ParsedConfiguration parsedConfiguration = (ParsedConfiguration) yamlParser.parse(reader, dirBasePaths);
JstdConfigParsingUtils.wipeCoveragePlugin(parsedConfiguration);
return JstdConfigParsingUtils.resolveConfiguration(parsedConfiguration);
} catch (Exception e) {
String message = "Malformed JsTestDriver configuration file " + configVirtualFile.getPath();
LOG.warn(message, e);
throw new ExecutionException(message);
} finally {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
Aggregations