diff --git a/tests/contents/server.mjs b/tests/contents/server.mjs index b14ce29945..4334ed363e 100644 --- a/tests/contents/server.mjs +++ b/tests/contents/server.mjs @@ -19,7 +19,7 @@ const DEFAULT_CONTENT_SERVER_PORT = 3000; * @param {number} port * @returns {Object} */ -export function createContentServer(port = DEFAULT_CONTENT_SERVER_PORT) { +export default function createContentServer(port = DEFAULT_CONTENT_SERVER_PORT) { const server = createServer(function (req, res) { if (routeObj[req.url] == null) { res.setHeader("Content-Type", "text/plain"); @@ -143,10 +143,3 @@ function parseRangeHeader(rangeHeader, dataLength) { } return [rangesNb[0], rangesNb[1]]; } -/** Default export that returns a teardown function that is executed by - * Vitest on test run - * @see https://vitest.dev/config/#globalsetup - * */ -export default () => { - createContentServer(); -}; diff --git a/tests/globalSetup.mjs b/tests/globalSetup.mjs new file mode 100644 index 0000000000..f608e25a8d --- /dev/null +++ b/tests/globalSetup.mjs @@ -0,0 +1,43 @@ +import createContentServer from "./contents/server.mjs"; + +const realConsoleWarn = console.warn; +let contentServer; + +/** + * Peform actions we want to setup before tests. + */ +export function setup() { + removeAnnoyingDeprecationNotice(); + contentServer = createContentServer(); +} + +/** + * Peform actions to clean-up after tests. + */ +export function teardown() { + contentServer?.close(); +} + +/** + * Webdriverio just spams a deprecation notice with the current version of + * vitest (one per test, though as we have thousands of tests, it just fills the + * output into something unreadable). + * + * This is so annoying that I just chose to mute it by monkey-patching the + * console function here. + * + * This should hopefully be very temporary. + */ +function removeAnnoyingDeprecationNotice() { + console.warn = function (...args) { + if ( + typeof args[0] === "string" && + args[0].startsWith( + '⚠️ [WEBDRIVERIO DEPRECATION NOTICE] The "switchToFrame" command is deprecated and we encourage everyone to use `switchFrame` instead for switching into frames.', + ) + ) { + return; + } + return realConsoleWarn.apply(console, args); + }; +} diff --git a/vitest.config.mjs b/vitest.config.mjs index 080b826fb4..9f924e2105 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -97,7 +97,7 @@ export default defineConfig({ // memory tests "tests/memory/**/*.[jt]s?(x)", ], - globalSetup: "tests/contents/server.mjs", + globalSetup: "tests/globalSetup.mjs", browser: getBrowserConfig(process.env.BROWSER_CONFIG ?? "chrome"), }, });