mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
in some cases the modulename.js may need to detect running in test mode (compliments pr #3630) window.name is not set web mode add a new field to the index.html window.intest and use the server_function to replace the hard coded string like we do for window.mmversion=#VERSION# then change the two test helpers to set the env variable app.js detects and sets global.intest=true server func replace with value of global.intest then module can use if(window.intest)
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
// see https://playwright.dev/docs/api/class-electronapplication
|
|
// https://github.com/microsoft/playwright/issues/6347#issuecomment-1085850728
|
|
// https://www.anycodings.com/1questions/958135/can-i-set-the-date-for-playwright-browser
|
|
const { _electron: electron } = require("playwright");
|
|
|
|
exports.startApplication = async (configFilename, systemDate = null, electronParams = ["js/electron.js"], timezone = "GMT") => {
|
|
global.electronApp = null;
|
|
global.page = null;
|
|
process.env.MM_CONFIG_FILE = configFilename;
|
|
process.env.TZ = timezone;
|
|
if (systemDate) {
|
|
process.env.MOCK_DATE = systemDate;
|
|
}
|
|
process.env.mmTestMode = "true";
|
|
|
|
global.electronApp = await electron.launch({ args: electronParams });
|
|
|
|
await global.electronApp.firstWindow();
|
|
|
|
for (const win of global.electronApp.windows()) {
|
|
const title = await win.title();
|
|
expect(["MagicMirror²", "DevTools"]).toContain(title);
|
|
if (title === "MagicMirror²") {
|
|
global.page = win;
|
|
if (systemDate) {
|
|
await global.page.evaluate((systemDate) => {
|
|
Date.now = () => {
|
|
return new Date(systemDate).valueOf();
|
|
};
|
|
}, systemDate);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.stopApplication = async () => {
|
|
if (global.electronApp) {
|
|
await global.electronApp.close();
|
|
}
|
|
global.electronApp = null;
|
|
global.page = null;
|
|
process.env.MOCK_DATE = undefined;
|
|
};
|
|
|
|
exports.getElement = async (selector) => {
|
|
expect(global.page).not.toBeNull();
|
|
let elem = global.page.locator(selector);
|
|
await elem.waitFor();
|
|
expect(elem).not.toBeNull();
|
|
return elem;
|
|
};
|