Search in sources :

Example 1 with TestFileStructurePack

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) ImmutableSet(com.google.common.collect.ImmutableSet) PsiFile(com.intellij.psi.PsiFile) TestType(com.google.jstestdriver.idea.execution.settings.TestType) JSFile(com.intellij.lang.javascript.psi.JSFile) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TestFileStructurePack

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) JSFile(com.intellij.lang.javascript.psi.JSFile) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JSFile(com.intellij.lang.javascript.psi.JSFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TestFileStructurePack

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) JSFile(com.intellij.lang.javascript.psi.JSFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JSFile(com.intellij.lang.javascript.psi.JSFile)

Example 4 with TestFileStructurePack

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;
}
Also used : TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with TestFileStructurePack

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileStructurePack(com.intellij.javascript.testFramework.TestFileStructurePack) JSFile(com.intellij.lang.javascript.psi.JSFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JSFile(com.intellij.lang.javascript.psi.JSFile)

Aggregations

TestFileStructurePack (com.intellij.javascript.testFramework.TestFileStructurePack)5 JSFile (com.intellij.lang.javascript.psi.JSFile)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 PsiFile (com.intellij.psi.PsiFile)2 Nullable (org.jetbrains.annotations.Nullable)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 TestType (com.google.jstestdriver.idea.execution.settings.TestType)1 ExecutionException (com.intellij.execution.ExecutionException)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 RuntimeConfigurationWarning (com.intellij.execution.configurations.RuntimeConfigurationWarning)1 NotNull (org.jetbrains.annotations.NotNull)1