Search in sources :

Example 1 with JasmineFileStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineFileStructure in project intellij-plugins by JetBrains.

the class KarmaTestLocationProvider method findJasmineElement.

@Nullable
private static PsiElement findJasmineElement(Project project, @NotNull List<String> suiteNames, @Nullable String testName) {
    String key = JsTestFileByTestNameIndex.createJasmineKey(suiteNames);
    GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    List<VirtualFile> jsTestVirtualFiles = JsTestFileByTestNameIndex.findJsTestFilesByNameInScope(key, scope);
    JasmineFileStructureBuilder builder = JasmineFileStructureBuilder.getInstance();
    for (VirtualFile file : jsTestVirtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile instanceof JSFile) {
            JasmineFileStructure jasmineFileStructure = builder.fetchCachedTestFileStructure((JSFile) psiFile);
            PsiElement element = jasmineFileStructure.findPsiElement(suiteNames, testName);
            if (element != null && element.isValid()) {
                return element;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JasmineFileStructureBuilder(com.intellij.javascript.testFramework.jasmine.JasmineFileStructureBuilder) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JasmineFileStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineFileStructure in project intellij-plugins by JetBrains.

the class KarmaExecutionSession method findTopLevelSuiteNames.

private static List<String> findTopLevelSuiteNames(@NotNull Project project, @NotNull String testFilePath) throws ExecutionException {
    VirtualFile file = LocalFileFinder.findFile(testFilePath);
    if (file == null) {
        throw new ExecutionException("Cannot find test file by " + testFilePath);
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    JSFile jsFile = ObjectUtils.tryCast(psiFile, JSFile.class);
    if (jsFile == null) {
        LOG.info("Not a JavaScript file " + testFilePath + ", " + (psiFile == null ? "null" : psiFile.getClass()));
        throw new ExecutionException("Not a JavaScript file: " + testFilePath);
    }
    JasmineFileStructure jasmine = JasmineFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    List<String> elements = jasmine.getTopLevelElements();
    if (!elements.isEmpty()) {
        return elements;
    }
    QUnitFileStructure qunit = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    elements = qunit.getTopLevelElements();
    if (!elements.isEmpty()) {
        return elements;
    }
    throw new ExecutionException("No tests found in " + testFilePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) ExecutionException(com.intellij.execution.ExecutionException) JSFile(com.intellij.lang.javascript.psi.JSFile) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure)

Example 3 with JasmineFileStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineFileStructure in project intellij-plugins by JetBrains.

the class JstdTestLocationProvider method findJasmineTestLocation.

@Nullable
private static PsiElement findJasmineTestLocation(@NotNull Project project, @NotNull String testCaseName, @Nullable String testMethodName) {
    VirtualFile file = findJasmineTestFileSource(project, testCaseName);
    if (file == null) {
        return null;
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile instanceof JSFile) {
        JSFile jsFile = (JSFile) psiFile;
        JasmineFileStructureBuilder builder = JasmineFileStructureBuilder.getInstance();
        JasmineFileStructure jasmineFileStructure = builder.fetchCachedTestFileStructure(jsFile);
        Map<String, JasmineSuiteStructure> map = Maps.newHashMap();
        for (JasmineSuiteStructure suite : jasmineFileStructure.getSuites()) {
            visitSuite("", map, suite);
        }
        JasmineSuiteStructure suite = map.get(testCaseName);
        if (suite != null) {
            if (testMethodName == null) {
                return suite.getEnclosingCallExpression();
            }
            JasmineSpecStructure spec = suite.getInnerSpecByName(testMethodName);
            if (spec != null) {
                return spec.getEnclosingCallExpression();
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JasmineSuiteStructure(com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure) JasmineFileStructureBuilder(com.intellij.javascript.testFramework.jasmine.JasmineFileStructureBuilder) PsiFile(com.intellij.psi.PsiFile) JasmineSpecStructure(com.intellij.javascript.testFramework.jasmine.JasmineSpecStructure) JSFile(com.intellij.lang.javascript.psi.JSFile) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with JasmineFileStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineFileStructure in project intellij-plugins by JetBrains.

the class KarmaRunConfigurationProducer method setupAsSuiteOrTest.

@Nullable
private static Pair<KarmaRunSettings, PsiElement> setupAsSuiteOrTest(@NotNull JSFile file, @NotNull VirtualFile virtualFile, @NotNull PsiElement element, @NotNull KarmaRunSettings templateSettings) {
    TextRange textRange = element.getTextRange();
    if (textRange == null || !file.isTestFile()) {
        return null;
    }
    JasmineFileStructure jasmineStructure = JasmineFileStructureBuilder.getInstance().fetchCachedTestFileStructure(file);
    JsTestElementPath path = jasmineStructure.findTestElementPath(textRange);
    if (path != null) {
        templateSettings = guessConfigFileIfNeeded(templateSettings, virtualFile, element.getProject());
        KarmaRunSettings.Builder builder = templateSettings.toBuilder();
        String testName = path.getTestName();
        if (testName == null) {
            builder.setScopeKind(KarmaScopeKind.SUITE);
            builder.setTestNames(path.getSuiteNames());
        } else {
            builder.setScopeKind(KarmaScopeKind.TEST);
            builder.setTestNames(path.getAllNames());
        }
        return Pair.create(builder.build(), path.getTestElement());
    }
    return null;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) JsTestElementPath(com.intellij.javascript.testFramework.JsTestElementPath) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JasmineFileStructure (com.intellij.javascript.testFramework.jasmine.JasmineFileStructure)4 JSFile (com.intellij.lang.javascript.psi.JSFile)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)3 JasmineFileStructureBuilder (com.intellij.javascript.testFramework.jasmine.JasmineFileStructureBuilder)2 ExecutionException (com.intellij.execution.ExecutionException)1 JsTestElementPath (com.intellij.javascript.testFramework.JsTestElementPath)1 JasmineSpecStructure (com.intellij.javascript.testFramework.jasmine.JasmineSpecStructure)1 JasmineSuiteStructure (com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure)1 QUnitFileStructure (com.intellij.javascript.testFramework.qunit.QUnitFileStructure)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1