Fix flaky navigation tests by refreshing file system before find

This commit is contained in:
Nikolay Krasko
2019-02-18 18:42:32 +03:00
parent e9ec8e2cee
commit c41d6c427d
2 changed files with 8 additions and 2 deletions
@@ -17,7 +17,9 @@ abstract class AbstractNavigateFromLibrarySourcesTest : LightCodeInsightFixtureT
protected fun navigationElementForReferenceInLibrarySource(filePath: String, referenceText: String): PsiElement {
val libraryOrderEntry = ModuleRootManager.getInstance(myModule!!).orderEntries.first { it is LibraryOrderEntry }
val libSourcesRoot = libraryOrderEntry.getUrls(OrderRootType.SOURCES)[0]
val vf = VirtualFileManager.getInstance().findFileByUrl(libSourcesRoot + "/$filePath")!!
val libUrl = "$libSourcesRoot/$filePath"
val vf = VirtualFileManager.getInstance().refreshAndFindFileByUrl(libUrl)
?: error("Can't find library: $libUrl")
val psiFile = psiManager.findFile(vf)!!
val indexOf = psiFile.text!!.indexOf(referenceText)
val reference = psiFile.findReferenceAt(indexOf)
@@ -41,7 +41,11 @@ fun PlatformTestCase.projectLibrary(
}
}
val File.jarRoot get() = JarFileSystem.getInstance().getRootByLocal(LocalFileSystem.getInstance().findFileByIoFile(this)!!)!!
val File.jarRoot: VirtualFile
get() {
val virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(this) ?: error("Cannot find file $this")
return JarFileSystem.getInstance().getRootByLocal(virtualFile) ?: error("Can't find root by file $virtualFile")
}
fun Module.addDependency(
library: Library,