Skip to content

Commit

Permalink
Remove caching of wdio root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
picimako committed Jan 31, 2021
1 parent 3e9d2b5 commit ee7b488
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 42 deletions.
5 changes: 0 additions & 5 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<error descr=""></error>` 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`.
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@

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;
import com.intellij.psi.PsiElement;
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.
Expand All @@ -64,7 +59,6 @@ public final class TerraWdioFolders {
private static final String LATEST_RELATIVE_PATH = "/" + SNAPSHOTS + "/" + LATEST;

private static String wdioTestRootPath;
private static CachedValue<VirtualFile> cachedWdioRoot;

/**
* Gets the VirtualFile representing the wdio tests root folder in the project, or null if there is no recognizable
Expand All @@ -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");
}

/**
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit ee7b488

Please sign in to comment.