From 2c1087ba2be3581e981335e7f6540f23fc1a3b46 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 1 Dec 2024 10:14:20 +0200 Subject: [PATCH] Ignore React Router Flag warning in logs during tests --- .../delivery/export/ExportTestUtilities.java | 17 ++++++++++------- .../webserver/JSErrorRegressionTest.java | 14 +++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportTestUtilities.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportTestUtilities.java index ae2dfeb07d..626f230e84 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportTestUtilities.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportTestUtilities.java @@ -64,19 +64,22 @@ private ExportTestUtilities() { public static void assertNoLogs(List logs, String endpoint) { List 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 logs) { List 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); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java index 15334322c1..f8fd8807d9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java @@ -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. @@ -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 } @@ -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); } } @@ -190,12 +190,4 @@ private List getLinks(ChromeDriver driver, int attempt) { return getLinks(driver, attempt + 1); } } - - - private void assertNoLogs(String testName, List 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()); - } } \ No newline at end of file