use of com.intellij.javascript.testFramework.TestFileStructurePack 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.intellij.javascript.testFramework.TestFileStructurePack in project intellij-plugins by JetBrains.
the class JstdRunConfigurationVerifier method verifyTestCase.
@Nullable
private static TestFileStructurePack verifyTestCase(@NotNull Project project, @NotNull JstdRunSettings runSettings) throws RuntimeConfigurationException {
verifyJSFileType(runSettings);
if (runSettings.getTestCaseName().isEmpty()) {
throw new RuntimeConfigurationError("Test case name is empty.");
}
VirtualFile jsTestVirtualFile = VfsUtil.findFileByIoFile(new File(runSettings.getJsFilePath()), false);
if (jsTestVirtualFile == null) {
throw new RuntimeConfigurationWarning("Can't find JavaScript test file.");
}
JSFile jsFile = ObjectUtils.tryCast(PsiManager.getInstance(project).findFile(jsTestVirtualFile), JSFile.class);
if (jsFile == null) {
throw new RuntimeConfigurationWarning("Wrong JavaScript test file.");
}
TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsFile);
if (pack != null) {
boolean found = pack.contains(runSettings.getTestCaseName(), null, JstdTestMethodNameRefiner.INSTANCE);
if (!found) {
throw new RuntimeConfigurationWarning("Can't find test case with name '" + runSettings.getTestCaseName() + "'.");
}
return pack;
}
return null;
}
use of com.intellij.javascript.testFramework.TestFileStructurePack in project intellij-plugins by JetBrains.
the class TestMethodRunSettingsSection method updateTestMethodVariants.
private void updateTestMethodVariants(@NotNull Project project, @NotNull String jsTestFilePath, @NotNull String testCaseName) {
myTestMethodNameComboBox.removeAllItems();
VirtualFile jsTestVirtualFile = VfsUtil.findFileByIoFile(new File(jsTestFilePath), false);
if (jsTestVirtualFile == null) {
return;
}
JSFile jsFile = ObjectUtils.tryCast(PsiManager.getInstance(project).findFile(jsTestVirtualFile), JSFile.class);
if (jsFile == null) {
return;
}
TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsFile);
if (pack != null) {
List<String> testMethodNames = pack.getChildrenOf(testCaseName);
for (String testMethodName : testMethodNames) {
myTestMethodNameComboBox.addItem(testMethodName);
}
}
}
use of com.intellij.javascript.testFramework.TestFileStructurePack in project intellij-plugins by JetBrains.
the class NavUtils method findPsiLocation.
@Nullable
public static PsiElement findPsiLocation(@NotNull Project project, @NotNull VirtualFile jsTestVirtualFile, @NotNull String testCaseName, @Nullable String testMethodName, @Nullable TestMethodNameRefiner testMethodNameRefiner) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(jsTestVirtualFile);
if (!(psiFile instanceof JSFile)) {
return null;
}
JSFile jsFile = (JSFile) psiFile;
TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsFile);
if (pack != null) {
return pack.findPsiElement(testCaseName, testMethodName, testMethodNameRefiner);
}
return null;
}
use of com.intellij.javascript.testFramework.TestFileStructurePack in project intellij-plugins by JetBrains.
the class TestCaseRunSettingsSection method updateTestCaseVariants.
private void updateTestCaseVariants(@NotNull Project project, @NotNull String jsTestFilePath) {
myTestCaseNameComboBox.removeAllItems();
VirtualFile jsTestVirtualFile = VfsUtil.findFileByIoFile(new File(jsTestFilePath), false);
if (jsTestVirtualFile == null) {
return;
}
JSFile jsFile = ObjectUtils.tryCast(PsiManager.getInstance(project).findFile(jsTestVirtualFile), JSFile.class);
if (jsFile == null) {
return;
}
TestFileStructurePack pack = TestFileStructureManager.fetchTestFileStructurePackByJsFile(jsFile);
if (pack != null) {
for (Object topLevel : pack.getTopLevelElements()) {
myTestCaseNameComboBox.addItem(topLevel);
}
}
}
Aggregations