Search in sources :

Example 1 with TestType

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);
}
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 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";
}
Also used : TestType(com.google.jstestdriver.idea.execution.settings.TestType) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TestType

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestFileScope(com.google.jstestdriver.idea.rt.util.TestFileScope) TestType(com.google.jstestdriver.idea.execution.settings.TestType) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TestType

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestType(com.google.jstestdriver.idea.execution.settings.TestType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with TestType

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;
}
Also used : Project(com.intellij.openapi.project.Project) TestType(com.google.jstestdriver.idea.execution.settings.TestType) JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File)

Aggregations

TestType (com.google.jstestdriver.idea.execution.settings.TestType)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 ExecutionException (com.intellij.execution.ExecutionException)2 JSFile (com.intellij.lang.javascript.psi.JSFile)2 PsiFile (com.intellij.psi.PsiFile)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 JstdRunSettings (com.google.jstestdriver.idea.execution.settings.JstdRunSettings)1 TestFileScope (com.google.jstestdriver.idea.rt.util.TestFileScope)1 TestFileStructurePack (com.intellij.javascript.testFramework.TestFileStructurePack)1 Project (com.intellij.openapi.project.Project)1