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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations