use of com.google.jstestdriver.idea.rt.coverage.CoverageReport in project intellij-plugins by JetBrains.
the class JstdCoverageEngine method generateReport.
@Override
public void generateReport(@NotNull Project project, @NotNull DataContext dataContext, @NotNull CoverageSuitesBundle currentSuiteBundle) {
CoverageReport coverageReport = new CoverageReport();
for (CoverageSuite suite : currentSuiteBundle.getSuites()) {
ProjectData projectData = suite.getCoverageData(CoverageDataManager.getInstance(project));
if (projectData != null) {
@SuppressWarnings("unchecked") Map<String, ClassData> classDataMap = projectData.getClasses();
for (Map.Entry<String, ClassData> classDataEntry : classDataMap.entrySet()) {
String fileName = classDataEntry.getKey();
ClassData classData = classDataEntry.getValue();
List<CoverageReport.LineHits> lineHitsList = convertClassDataToLineHits(classData);
coverageReport.mergeFileReport(fileName, lineHitsList);
}
}
}
final ExportToHTMLSettings settings = ExportToHTMLSettings.getInstance(project);
final File outputDir = new File(settings.OUTPUT_DIRECTORY);
FileUtil.createDirectory(outputDir);
String outputFileName = getOutputFileName(currentSuiteBundle);
String title = "Coverage Report Generation";
try {
File output = new File(outputDir, outputFileName);
CoverageSerializationUtils.writeLCOV(coverageReport, output);
refresh(output);
String url = "http://ltp.sourceforge.net/coverage/lcov.php";
Messages.showInfoMessage("<html>Coverage report has been successfully saved as '" + outputFileName + "' file.<br>Use <a href='" + url + "'>" + url + "</a>" + " to generate HTML output." + "</html>", title);
} catch (IOException e) {
LOG.warn("Can not export coverage data", e);
Messages.showErrorDialog("Can not generate coverage report: " + e.getMessage(), title);
}
}
use of com.google.jstestdriver.idea.rt.coverage.CoverageReport in project intellij-plugins by JetBrains.
the class JstdCoverageRunner method readProjectData.
@NotNull
private static ProjectData readProjectData(@NotNull File dataFile) throws IOException {
CoverageReport report = CoverageSerializationUtils.readLCOV(dataFile);
ProjectData projectData = new ProjectData();
for (Map.Entry<String, List<CoverageReport.LineHits>> entry : report.getInfo().entrySet()) {
String filePath = SimpleCoverageAnnotator.getFilePath(entry.getKey());
ClassData classData = projectData.getOrCreateClassData(filePath);
int max = 0;
List<CoverageReport.LineHits> lineHitsList = entry.getValue();
if (lineHitsList.size() > 0) {
CoverageReport.LineHits lastLineHits = lineHitsList.get(lineHitsList.size() - 1);
max = lastLineHits.getLineNumber();
}
LineData[] lines = new LineData[max + 1];
for (CoverageReport.LineHits lineHits : lineHitsList) {
LineData lineData = new LineData(lineHits.getLineNumber(), null);
lineData.setHits(lineHits.getHits());
lines[lineHits.getLineNumber()] = lineData;
}
classData.setLines(lines);
}
return projectData;
}
use of com.google.jstestdriver.idea.rt.coverage.CoverageReport 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.idea.rt.coverage.CoverageReport in project intellij-plugins by JetBrains.
the class CoverageSerializationUtils method readLCOV.
public static CoverageReport readLCOV(@NotNull File file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
try {
String currentFileName = null;
String line;
List<CoverageReport.LineHits> lineDataList = null;
CoverageReport report = new CoverageReport();
while ((line = reader.readLine()) != null) {
if (line.startsWith(SOURCE_FILE_PREFIX)) {
currentFileName = line.substring(SOURCE_FILE_PREFIX.length());
lineDataList = Lists.newArrayList();
} else if (line.startsWith(LINE_HIT_PREFIX)) {
if (lineDataList == null) {
throw new RuntimeException("lineDataList is null!");
}
String[] values = line.substring(LINE_HIT_PREFIX.length()).split(",");
Preconditions.checkState(values.length == 2);
int lineNum = Integer.parseInt(values[0]);
int hitCount = Integer.parseInt(values[1]);
CoverageReport.LineHits lineHits = new CoverageReport.LineHits(lineNum, hitCount);
lineDataList.add(lineHits);
} else if (END_OF_RECORD.equals(line)) {
if (lineDataList == null) {
throw new RuntimeException("lineDataList is null!");
}
Preconditions.checkNotNull(currentFileName);
report.mergeFileReport(currentFileName, lineDataList);
currentFileName = null;
lineDataList = null;
}
}
Preconditions.checkState(lineDataList == null && currentFileName == null);
return report;
} finally {
reader.close();
}
}
Aggregations