From ee7b48884a67d8ea8357f024166d08d78945ece9 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Sun, 31 Jan 2021 09:49:00 +0100 Subject: [PATCH] Remove caching of wdio root folder --- CONTRIBUTE.md | 5 ----- .../picimako/terra/wdio/TerraWdioFolders.java | 19 +------------------ .../terra/wdio/TerraWdioFoldersTest.java | 7 ------- .../TerraScreenshotReferenceTest.java | 6 ------ .../FindUnusedScreenshotsActionTest.java | 6 ------ 5 files changed, 1 insertion(+), 42 deletions(-) diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 118e600..6444ee5 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -77,11 +77,6 @@ Test data for inspection unit tests can be found under the `testdata` root direc Since test data files may contain additional XML elements for marking elements for expected highlighting (e.g. `` and other severity level test tags), including these elements will mark the file with an ERROR that it is invalid. You can ignore that, highlight testing will run regardless of that. -## Troubleshooting - -Since the wdio root folder value is cached in `TerraWdioFolders` it can cause unit test failures, so if you suspect that test cases might be affected by the wdio root set in other unit tests, -make sure to call `TerraWdioFolders.clearWdioRootCache()` before it/them. - ## Helper code snippets The following snippets might be helpful when generating/reorganizing data for `com.picimako.terra.documentation.TerraUIComponentDocumentationUrlService`. diff --git a/src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java b/src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java index cafbc7e..59976c3 100644 --- a/src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java +++ b/src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java @@ -27,7 +27,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; -import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; @@ -35,12 +34,8 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.search.FilenameIndex; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.CachedValue; -import com.intellij.psi.util.CachedValueProvider; -import com.intellij.psi.util.CachedValuesManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; /** * Folder and path handling for the Terra wdio related folders. @@ -64,7 +59,6 @@ public final class TerraWdioFolders { private static final String LATEST_RELATIVE_PATH = "/" + SNAPSHOTS + "/" + LATEST; private static String wdioTestRootPath; - private static CachedValue cachedWdioRoot; /** * Gets the VirtualFile representing the wdio tests root folder in the project, or null if there is no recognizable @@ -77,10 +71,7 @@ public final class TerraWdioFolders { */ @Nullable public static VirtualFile projectWdioRoot(Project project) { - if (cachedWdioRoot == null) { - cachedWdioRoot = CachedValuesManager.getManager(project).createCachedValue(() -> new CachedValueProvider.Result<>(getTestRoot(project, "wdio"), ModificationTracker.NEVER_CHANGED)); - } - return cachedWdioRoot.getValue(); + return getTestRoot(project, "wdio"); } /** @@ -345,14 +336,6 @@ public static void setWdioTestRootPath(String path) { wdioTestRootPath = path; } - /** - * Should be called only from test code. - */ - @TestOnly - public static void clearWdioRootCache() { - cachedWdioRoot = null; - } - private TerraWdioFolders() { //Utility class } diff --git a/src/test/java/com/picimako/terra/wdio/TerraWdioFoldersTest.java b/src/test/java/com/picimako/terra/wdio/TerraWdioFoldersTest.java index 07d5ce6..5b2db7b 100644 --- a/src/test/java/com/picimako/terra/wdio/TerraWdioFoldersTest.java +++ b/src/test/java/com/picimako/terra/wdio/TerraWdioFoldersTest.java @@ -44,13 +44,6 @@ protected String getTestDataPath() { return "testdata/terra/projectroot"; } - @Override - protected void setUp() throws Exception { - super.setUp(); - //This is necessary to avoid test cases interfering with each other due to the cache value - TerraWdioFolders.clearWdioRootCache(); - } - // projectWdioRoot public void testReturnVirtualFileForProjectWdioRoot() { diff --git a/src/test/java/com/picimako/terra/wdio/screenshot/reference/TerraScreenshotReferenceTest.java b/src/test/java/com/picimako/terra/wdio/screenshot/reference/TerraScreenshotReferenceTest.java index ff97486..1c24cce 100644 --- a/src/test/java/com/picimako/terra/wdio/screenshot/reference/TerraScreenshotReferenceTest.java +++ b/src/test/java/com/picimako/terra/wdio/screenshot/reference/TerraScreenshotReferenceTest.java @@ -43,12 +43,6 @@ protected String getTestDataPath() { return "testdata/terra/projectroot"; } - @Override - protected void setUp() throws Exception { - super.setUp(); - TerraWdioFolders.clearWdioRootCache(); - } - public void testReferencesForTerraDescribeViewportsAndValidatesScreenshot() { validateReferencesForSourceFile("ScreenshotResolveTerraDescribeViewportsValidatesScreenshot-spec.js"); } diff --git a/src/test/java/com/picimako/terra/wdio/toolwindow/FindUnusedScreenshotsActionTest.java b/src/test/java/com/picimako/terra/wdio/toolwindow/FindUnusedScreenshotsActionTest.java index a603a90..a9e0b6f 100644 --- a/src/test/java/com/picimako/terra/wdio/toolwindow/FindUnusedScreenshotsActionTest.java +++ b/src/test/java/com/picimako/terra/wdio/toolwindow/FindUnusedScreenshotsActionTest.java @@ -33,12 +33,6 @@ protected String getTestDataPath() { return "testdata/terra/projectroot"; } - @Override - protected void setUp() throws Exception { - super.setUp(); - TerraWdioFolders.clearWdioRootCache(); - } - public void testMarksScreenshotsUnused() { myFixture.copyFileToProject("tests/wdio/__snapshots__/reference/en/chrome_huge/some-spec/terra-_screenshot--[with-_-replaced-_-characters_-].png"); myFixture.copyFileToProject("tests/wdio/__snapshots__/reference/en/chrome_medium/some-spec/terra-_screenshot--[with-_-replaced-_-characters_-].png");