[tests] migrate from jest to vitest (#3940)

This is a big change, but I think it's a good move, as `vitest` is much
more modern than `jest`.

I'm excited about the UI watch feature (run `npm run test:ui`), for
example - it's really helpful and saves time when debugging tests. I had
to adjust a few tests because they had time related issues, but
basically we are now testing the same things - even a bit better and
less flaky (I hope).

What do you think?
This commit is contained in:
Kristjan ESPERANTO
2025-11-03 19:47:01 +01:00
committed by GitHub
parent b542f33a0a
commit 462abf7027
30 changed files with 2370 additions and 3562 deletions

View File

@@ -20,7 +20,21 @@ exports.startApplication = async (configFilename, systemDate = null, electronPar
electronParams.unshift("js/electron.js");
}
global.electronApp = await electron.launch({ args: electronParams });
// Pass environment variables to Electron process
const env = {
...process.env,
MM_CONFIG_FILE: configFilename,
TZ: timezone,
mmTestMode: "true"
};
if (systemDate) {
env.MOCK_DATE = systemDate;
}
global.electronApp = await electron.launch({
args: electronParams,
env: env
});
await global.electronApp.firstWindow();
@@ -40,13 +54,35 @@ exports.startApplication = async (configFilename, systemDate = null, electronPar
}
};
exports.stopApplication = async () => {
if (global.electronApp) {
await global.electronApp.close();
}
exports.stopApplication = async (timeout = 10000) => {
const app = global.electronApp;
global.electronApp = null;
global.page = null;
process.env.MOCK_DATE = undefined;
if (!app) {
return;
}
const killElectron = () => {
try {
const electronProcess = typeof app.process === "function" ? app.process() : null;
if (electronProcess && !electronProcess.killed) {
electronProcess.kill("SIGKILL");
}
} catch (error) {
// Ignore errors caused by Playwright already tearing down the connection
}
};
try {
await Promise.race([
app.close(),
new Promise((_, reject) => setTimeout(() => reject(new Error("Electron close timeout")), timeout))
]);
} catch (error) {
killElectron();
}
};
exports.getElement = async (selector, state = "visible") => {