use of com.google.jstestdriver.idea.execution.settings.TestType in project intellij-plugins by JetBrains.
the class JstdRunProfileState method buildTestFileScope.
@NotNull
private static TestFileScope buildTestFileScope(@NotNull Project project, @NotNull JstdRunSettings settings) throws ExecutionException {
TestType testType = settings.getTestType();
if (testType == TestType.ALL_CONFIGS_IN_DIRECTORY || testType == TestType.CONFIG_FILE) {
return TestFileScope.allScope();
}
if (testType == TestType.JS_FILE) {
File jsFile = new File(settings.getJsFilePath());
if (jsFile.isAbsolute() && jsFile.isFile()) {
VirtualFile virtualFile = VfsUtil.findFileByIoFile(jsFile, true);
if (virtualFile != null) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof JSFile) {
JSFile jsPsiFile = (JSFile) psiFile;
TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsPsiFile);
if (pack != null) {
List<String> testCases = pack.getTopLevelElements();
if (testCases.isEmpty()) {
throw new ExecutionException("No tests found in " + jsPsiFile.getName());
}
Map<String, Set<String>> scope = ContainerUtil.newHashMap();
for (String testCase : testCases) {
scope.put(testCase, Collections.emptySet());
}
return TestFileScope.customScope(scope);
}
}
}
}
throw new ExecutionException("Unable to extract tests from " + jsFile.getName());
}
if (testType == TestType.TEST_CASE) {
Map<String, Set<String>> scope = Collections.singletonMap(settings.getTestCaseName(), Collections.<String>emptySet());
return TestFileScope.customScope(scope);
}
if (testType == TestType.TEST_METHOD) {
Map<String, Set<String>> scope = Collections.singletonMap(settings.getTestCaseName(), Collections.singleton(settings.getTestMethodName()));
return TestFileScope.customScope(scope);
}
throw new RuntimeException("Unexpected test type: " + testType);
}
use of com.google.jstestdriver.idea.execution.settings.TestType in project intellij-plugins by JetBrains.
the class JstdRunConfiguration method generateName.
@NotNull
private String generateName() {
TestType testType = myRunSettings.getTestType();
if (testType == TestType.ALL_CONFIGS_IN_DIRECTORY) {
String directoryPath = myRunSettings.getDirectory();
String rootRelativePath = ProjectRootUtils.getRootRelativePath(getProject(), directoryPath);
if (rootRelativePath == null) {
rootRelativePath = directoryPath;
}
return "All in " + rootRelativePath;
} else if (testType == TestType.CONFIG_FILE) {
File file = new File(myRunSettings.getConfigFile());
return file.getName();
} else if (testType == TestType.JS_FILE) {
File file = new File(myRunSettings.getJsFilePath());
return file.getName();
} else if (testType == TestType.TEST_CASE) {
return myRunSettings.getTestCaseName();
} else if (testType == TestType.TEST_METHOD) {
return myRunSettings.getTestCaseName() + "." + myRunSettings.getTestMethodName();
}
return "Unnamed";
}
use of com.google.jstestdriver.idea.execution.settings.TestType in project intellij-plugins by JetBrains.
the class JstdRunProfileState method createParameterMap.
@NotNull
private Map<TestRunner.ParameterKey, String> createParameterMap(@NotNull String serverUrl) throws ExecutionException {
Map<TestRunner.ParameterKey, String> parameters = Maps.newLinkedHashMap();
parameters.put(TestRunner.ParameterKey.SERVER_URL, serverUrl);
TestType testType = myRunSettings.getTestType();
if (testType == TestType.ALL_CONFIGS_IN_DIRECTORY) {
parameters.put(TestRunner.ParameterKey.ALL_CONFIGS_IN_DIRECTORY, myRunSettings.getDirectory());
}
List<VirtualFile> jstdConfigs = JstdSettingsUtil.collectJstdConfigs(myEnvironment.getProject(), myRunSettings);
if (jstdConfigs.isEmpty()) {
throw new ExecutionException("Can't find JsTestDriver configuration file.");
}
parameters.put(TestRunner.ParameterKey.CONFIG_FILES, joinJstdConfigs(jstdConfigs));
TestFileScope testFileScope = buildTestFileScope(myEnvironment.getProject(), myRunSettings);
if (!testFileScope.isAll()) {
parameters.put(TestRunner.ParameterKey.TESTS, testFileScope.serialize());
}
if (myCoverageFilePath != null) {
parameters.put(TestRunner.ParameterKey.COVERAGE_OUTPUT_FILE, myCoverageFilePath);
if (!myRunSettings.getFilesExcludedFromCoverage().isEmpty()) {
String excludedPaths = EscapeUtils.join(myRunSettings.getFilesExcludedFromCoverage(), ',');
parameters.put(TestRunner.ParameterKey.COVERAGE_EXCLUDED_PATHS, excludedPaths);
}
}
if (myDebug) {
parameters.put(TestRunner.ParameterKey.DEBUG, Boolean.TRUE.toString());
}
return parameters;
}
use of com.google.jstestdriver.idea.execution.settings.TestType in project intellij-plugins by JetBrains.
the class JstdSettingsUtil method collectJstdConfigs.
@NotNull
public static List<VirtualFile> collectJstdConfigs(@NotNull Project project, @NotNull JstdRunSettings runSettings) {
TestType testType = runSettings.getTestType();
List<VirtualFile> res = Collections.emptyList();
if (testType == TestType.ALL_CONFIGS_IN_DIRECTORY) {
VirtualFile virtualFile = VfsUtil.findFileByIoFile(new File(runSettings.getDirectory()), true);
if (virtualFile != null) {
res = collectJstdConfigFilesInDirectory(project, virtualFile);
}
} else {
File configFile = new File(runSettings.getConfigFile());
VirtualFile configVirtualFile = VfsUtil.findFileByIoFile(configFile, false);
if (configVirtualFile != null) {
res = Collections.singletonList(configVirtualFile);
}
}
return res;
}
use of com.google.jstestdriver.idea.execution.settings.TestType in project intellij-plugins by JetBrains.
the class JstdRunConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(JstdRunConfiguration configuration, ConfigurationContext context) {
Project project = configuration.getProject();
if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
return false;
}
JstdRunSettings patternRunSettings = buildRunSettingsContext(context.getLocation());
if (patternRunSettings == null) {
return false;
}
JstdRunSettings candidateRunSettings = configuration.getRunSettings();
TestType patternTestType = patternRunSettings.getTestType();
if (patternTestType != candidateRunSettings.getTestType()) {
return false;
}
if (patternTestType == TestType.ALL_CONFIGS_IN_DIRECTORY) {
File dir1 = new File(patternRunSettings.getDirectory());
File dir2 = new File(candidateRunSettings.getDirectory());
if (dir1.isDirectory() && dir2.isDirectory() && FileUtil.filesEqual(dir1, dir2)) {
return true;
}
} else if (patternTestType == TestType.CONFIG_FILE) {
File configFilePattern = new File(patternRunSettings.getConfigFile());
File configFileCandidate = new File(candidateRunSettings.getConfigFile());
if (configFilePattern.isFile() && configFileCandidate.isFile() && FileUtil.filesEqual(configFilePattern, configFileCandidate)) {
return true;
}
} else if (patternTestType == TestType.JS_FILE || patternTestType == TestType.TEST_CASE || patternTestType == TestType.TEST_METHOD) {
File patternJsFile = new File(patternRunSettings.getJsFilePath());
File candidateJsFile = new File(candidateRunSettings.getJsFilePath());
boolean eq = candidateJsFile.isFile() && FileUtil.filesEqual(patternJsFile, candidateJsFile);
if (patternTestType == TestType.TEST_CASE) {
eq = eq && patternRunSettings.getTestCaseName().equals(candidateRunSettings.getTestCaseName());
}
if (patternTestType == TestType.TEST_METHOD) {
eq = eq && patternRunSettings.getTestCaseName().equals(candidateRunSettings.getTestCaseName());
eq = eq && patternRunSettings.getTestMethodName().equals(candidateRunSettings.getTestMethodName());
}
if (eq) {
return true;
}
}
return false;
}
Aggregations