mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Two causes behind most of EVERYTHING's WebKit failures so far, both in the test pages rather than in WeKan: - 94 specs switch language with setLanguage and then click at once. The client loads that language afterwards and draws everything again, which closes a popup opened before that: the board view popup of the flow and report help specs (Latin monte-carlo in WebKit; Corsican and Scottish Gaelic in earlier Firefox runs) had no entry left to click. The fixture's context now wraps Meteor.callAsync in each page so that a setLanguage call resolves once <html lang> - which client/lib/i18n.js sets in the same flush that redraws - names the language. It waits at most 10 s and then resolves anyway, so it can only make a spec patient, never fail one. A page of a context a spec makes itself uses untilLanguageShown(). - Playwright's WebKit freezes the page's main thread on PushManager.getSubscription(): after it not even a timer runs. Member Notification Settings asks it on opening, to show whether this device gets push (client/lib/webPush.js), so every WebKit spec that opened it hung in its next click - notification-activity-mute and the member scope of notification-delivery-settings, in every language. In WebKit the page now answers as a device with no subscription does. Chromium, Firefox and Safari answer the real call; no spec subscribes. WebKit: those notification specs 10 of 10, and the Latin, Corsican and Product Backlog specs 13 of 13; Chromium and Firefox 11 of 11 each with the same subset. playwrightPageInit.test.cjs runs both page scripts on a fake page: setLanguage waits for the language and keeps its result, other methods are not held, a page whose Meteor arrives later is wrapped, the wait is capped; WebKit's getSubscription answers null and Chromium's and Firefox's are left alone; the fixture installs both. Thanks to xet7 !
58 lines
2.6 KiB
JavaScript
58 lines
2.6 KiB
JavaScript
'use strict';
|
|
// Wait until the page shows the language a spec has just switched to.
|
|
//
|
|
// setLanguage saves the choice on the server; the client then loads that
|
|
// language and draws everything again - which closes a popup opened before
|
|
// that, and in WebKit keeps the page busy enough that a click waits it out.
|
|
// Specs that switched language and at once opened the board view popup, or a
|
|
// settings section, failed when the language arrived late (Latin, Corsican,
|
|
// Igbo ... in WebKit and Firefox). The client mirrors its current language into
|
|
// <html lang> (client/lib/i18n.js) in the same flush that redraws, so that
|
|
// attribute says when it has arrived.
|
|
|
|
// Runs in the page. Wraps Meteor.callAsync so that a 'setLanguage' call
|
|
// resolves only once <html lang> names the language and the redraw has run.
|
|
// It waits at most 10 s and then resolves anyway: a language the client
|
|
// resolves to another tag must not turn a wait into a failure.
|
|
function waitForLanguageOnSetLanguage() {
|
|
const tag = value => String(value || '').toLowerCase().replace(/_/g, '-');
|
|
const shown = wanted => new Promise(resolve => {
|
|
const deadline = Date.now() + 10000;
|
|
const check = () => {
|
|
if (tag(document.documentElement.lang) === tag(wanted) || Date.now() > deadline) {
|
|
requestAnimationFrame(() => requestAnimationFrame(resolve));
|
|
} else setTimeout(check, 50);
|
|
};
|
|
check();
|
|
});
|
|
const install = () => {
|
|
const meteor = window.Meteor;
|
|
if (!meteor || typeof meteor.callAsync !== 'function') return false;
|
|
if (meteor.callAsync.__waitsForLanguage) return true;
|
|
const callAsync = meteor.callAsync;
|
|
const wrapped = async function (name, ...args) {
|
|
const result = await callAsync.call(this, name, ...args);
|
|
if (name === 'setLanguage' && typeof args[0] === 'string') await shown(args[0]);
|
|
return result;
|
|
};
|
|
wrapped.__waitsForLanguage = true;
|
|
meteor.callAsync = wrapped;
|
|
return true;
|
|
};
|
|
if (!install()) {
|
|
const timer = setInterval(() => { if (install()) clearInterval(timer); }, 20);
|
|
}
|
|
}
|
|
|
|
// For a page of a context a spec makes itself, which the fixture's init script
|
|
// does not reach.
|
|
async function untilLanguageShown(page, language) {
|
|
await page.waitForFunction(wanted => {
|
|
const tag = value => String(value || '').toLowerCase().replace(/_/g, '-');
|
|
return tag(document.documentElement.lang) === tag(wanted);
|
|
}, language, { timeout: 15_000 });
|
|
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
|
}
|
|
|
|
module.exports = { waitForLanguageOnSetLanguage, untilLanguageShown };
|