Ignore React Router Flag warning in logs during tests

This commit is contained in:
Aurora Lahtela 2024-12-01 10:14:20 +02:00
parent d341c5b04a
commit 2c1087ba2b
2 changed files with 13 additions and 18 deletions

View File

@ -64,19 +64,22 @@ public class 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);
}

View File

@ -51,7 +51,7 @@ import java.nio.file.Path;
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.
@ -140,7 +140,7 @@ class JSErrorRegressionTest {
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
}
@ -170,7 +170,7 @@ class JSErrorRegressionTest {
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);
}
}
@ -190,12 +190,4 @@ class JSErrorRegressionTest {
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());
}
}