Skip to content

Commit

Permalink
Ignore React Router Flag warning in logs during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 committed Dec 1, 2024
1 parent d341c5b commit 2c1087b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@ private ExportTestUtilities() {
public static void assertNoLogs(List<LogEntry> logs, String endpoint) {
List<String> loggedLines = logs.stream()
.map(log -> "\n" + log.getLevel().getName() + " " + log.getMessage())
.filter(log -> !StringUtils.containsAny(log,
"fonts.gstatic.com", "fonts.googleapis.com", "cdn.jsdelivr.net"
)).toList();
.filter(ExportTestUtilities::ignoredLogLines).toList();
assertTrue(loggedLines.isEmpty(), () -> "Loading " + endpoint + ", Browser console included " + loggedLines.size() + " logs: " + loggedLines);
}

private static boolean ignoredLogLines(String log) {
return !StringUtils.containsAny(log,
"fonts.gstatic.com", "fonts.googleapis.com", "cdn.jsdelivr.net", "manifest.json",
"React Router Future Flag Warning" // TODO remove after update to react-router-dom v7
);
}

public static void assertNoLogsExceptFaviconError(List<LogEntry> logs) {
List<String> loggedLines = logs.stream()
.map(log -> "\n" + log.getLevel().getName() + " " + log.getMessage())
.filter(log -> !log.contains("favicon.ico")
&& !log.contains("manifest.json")
&& !log.contains("fonts.gstatic.com")
&& !log.contains("fonts.googleapis.com"))
.filter(ExportTestUtilities::ignoredLogLines)
.filter(log -> !log.contains("favicon.ico"))
.toList();
assertTrue(loggedLines.isEmpty(), () -> "Browser console included " + loggedLines.size() + " logs: " + loggedLines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static com.djrapitops.plan.delivery.export.ExportTestUtilities.assertNoLogs;

/**
* This test class is for catching any JavaScript errors.
Expand Down Expand Up @@ -140,7 +140,7 @@ private DynamicTest testAddress(String address, ChromeDriver driver) {
logs.addAll(driver.manage().logs().get(LogType.CLIENT).getAll());
logs.addAll(driver.manage().logs().get(LogType.BROWSER).getAll());

assertNoLogs("'" + address + "',", logs);
assertNoLogs(logs, address);
} finally {
locale.clear(); // Reset locale after test
}
Expand Down Expand Up @@ -170,7 +170,7 @@ void linkFunctionRegressionTest(String address, ChromeDriver driver) {
logs.addAll(driver.manage().logs().get(LogType.CLIENT).getAll());
logs.addAll(driver.manage().logs().get(LogType.BROWSER).getAll());

assertNoLogs("Page link '" + address + "'->'" + href + "' issue: ", logs);
assertNoLogs(logs, "Page link '" + address + "'->'" + href + "'");
System.out.println("'" + address + "' has link to " + href);
}
}
Expand All @@ -190,12 +190,4 @@ private List<String> getLinks(ChromeDriver driver, int attempt) {
return getLinks(driver, attempt + 1);
}
}


private void assertNoLogs(String testName, List<LogEntry> logs) {
assertTrue(logs.isEmpty(), () -> testName + "Browser console included " + logs.size() + " logs: " + logs.stream()
.map(log -> "\n" + log.getLevel().getName() + " " + log.getMessage())
.filter(log -> !log.contains("fonts.gstatic.com") && !log.contains("fonts.googleapis.com"))
.toList());
}
}

0 comments on commit 2c1087b

Please sign in to comment.