Skip to content

Commit

Permalink
[Proposal] Remove webdriverio deprecation notice the ugly way
Browse files Browse the repository at this point in the history
Our tests run with the test framework `vitest`, which is for now
using the `webdriverio` dependency to run it on real browser
environments.

However, it seems that `vitest` is using a deprecated API for each tests
resulting in `webdriverio` outputing a warning log after each of them.

Considering that we have thousands of tests, it makes the outputs of
integration tests unreadable, output which is particularly important
when running test scripts.

This could be considered as a `vitest` issue, and they have been made
aware of it through their #6804 issue (I'm not linking it in any way
here as GitHub as the annoying tendency to spam messages to the original
issue when linked that way, but it's the one named
"`switchToFrame` deprecated in WebdriverIO v9").

But in the meantime it has been several month and it's hard to write and
run integration tests with that mess. So here I'm proposing to just
uglily patch console functions in `vitest`'s "globalSetup" script.
  • Loading branch information
peaBerberian committed Jan 7, 2025
1 parent 3dee043 commit 303a16f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 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);
};
}
1 change: 1 addition & 0 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default defineConfig({
"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 303a16f

Please sign in to comment.