Skip to content

Commit

Permalink
Merge pull request #1618 from canalplus/misc/remove-webdriverio-depre…
Browse files Browse the repository at this point in the history
…cation-notices

[Proposal] Remove webdriverio deprecation notice the ugly way
  • Loading branch information
peaBerberian authored Jan 7, 2025
2 parents 3dee043 + 709ad29 commit f47e6c7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
9 changes: 1 addition & 8 deletions tests/contents/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
};
43 changes: 43 additions & 0 deletions tests/globalSetup.mjs
Original file line number Diff line number Diff line change
@@ -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);
};
}
2 changes: 1 addition & 1 deletion vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
});

0 comments on commit f47e6c7

Please sign in to comment.