Search in sources :

Example 1 with QUnitFileStructure

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructure 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 2 with QUnitFileStructure

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructure in project intellij-plugins by JetBrains.

the class JstdAssertionFrameworkLineMarkerProvider method getQUnitLineMarkerInfo.

@Nullable
private static LineMarkerInfo getQUnitLineMarkerInfo(@NotNull JSFile jsFile, @NotNull PsiElement element) {
    QUnitFileStructure qunitFileStructure = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    if (element instanceof JSCallExpression) {
        JSCallExpression callExpression = (JSCallExpression) element;
        String testElementName = qunitFileStructure.getNameByPsiElement(callExpression);
        if (testElementName == null) {
            return null;
        }
        return createLineMarkerFromElement(element, testElementName);
    }
    return null;
}
Also used : JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with QUnitFileStructure

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructure in project intellij-plugins by JetBrains.

the class QUnitAdapterSupportInspection method isSuitableElement.

@Override
protected boolean isSuitableElement(@NotNull JSFile jsFile, @NotNull JSCallExpression callExpression) {
    QUnitFileStructure structure = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    String name = structure.getNameByPsiElement(callExpression);
    return name != null;
}
Also used : QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure)

Example 4 with QUnitFileStructure

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructure in project intellij-plugins by JetBrains.

the class JstdTestLocationProvider method findTestFromQUnitDefaultModule.

@Nullable
private static PsiElement findTestFromQUnitDefaultModule(@NotNull Project project, @NotNull String testMethodName) {
    GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    testMethodName = StringUtil.trimStart(testMethodName, "test ");
    String key = JsTestFileByTestNameIndex.createQUnitKeyForTestFromDefaultModule(testMethodName);
    List<VirtualFile> jsTestVirtualFiles = JsTestFileByTestNameIndex.findJsTestFilesByNameInScope(key, scope);
    List<VirtualFile> validJsTestVirtualFiles = filterVirtualFiles(jsTestVirtualFiles);
    for (VirtualFile jsTestVirtualFile : validJsTestVirtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(jsTestVirtualFile);
        if (psiFile instanceof JSFile) {
            JSFile jsFile = (JSFile) psiFile;
            QUnitFileStructureBuilder builder = QUnitFileStructureBuilder.getInstance();
            QUnitFileStructure qunitFileStructure = builder.fetchCachedTestFileStructure(jsFile);
            PsiElement element = qunitFileStructure.findPsiElement(DefaultQUnitModuleStructure.NAME, testMethodName);
            if (element != null && element.isValid()) {
                return element;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure) PsiElement(com.intellij.psi.PsiElement) QUnitFileStructureBuilder(com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with QUnitFileStructure

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructure in project intellij-plugins by JetBrains.

the class KarmaTestLocationProvider method findQUnitElement.

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

Aggregations

QUnitFileStructure (com.intellij.javascript.testFramework.qunit.QUnitFileStructure)5 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 QUnitFileStructureBuilder (com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder)2 PsiElement (com.intellij.psi.PsiElement)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ExecutionException (com.intellij.execution.ExecutionException)1 JasmineFileStructure (com.intellij.javascript.testFramework.jasmine.JasmineFileStructure)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1