mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 21:45:01 -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 !
89 lines
4.2 KiB
JavaScript
89 lines
4.2 KiB
JavaScript
'use strict';
|
|
// The scripts the Playwright fixture adds to every page of a test's context
|
|
// (tests/playwright/fixtures.js): a setLanguage call that resolves once the
|
|
// page shows the language, and WebKit not freezing on a push subscription.
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { waitForLanguageOnSetLanguage } = require('./playwright/helpers/language.cjs');
|
|
const { noPushSubscriptionInWebKit } = require('./playwright/helpers/webkit-push.cjs');
|
|
|
|
// A page: <html lang>, frames, timers, and a Meteor whose method resolves at once.
|
|
function fakePage({ lang = 'en' } = {}) {
|
|
const calls = [];
|
|
const g = {
|
|
document: { documentElement: { lang } },
|
|
requestAnimationFrame: fn => setTimeout(fn, 1),
|
|
setTimeout, setInterval, clearInterval,
|
|
Date,
|
|
Meteor: { callAsync: async (name, ...args) => { calls.push([name, ...args]); return `${name} done`; } },
|
|
};
|
|
g.window = g;
|
|
return { g, calls };
|
|
}
|
|
function run(fn, g) {
|
|
return new Function('window', 'document', 'requestAnimationFrame', 'setTimeout', 'setInterval', 'clearInterval', 'Date', 'navigator', 'PushManager',
|
|
`(${fn.toString()})()`)(g, g.document, g.requestAnimationFrame, g.setTimeout, g.setInterval, g.clearInterval, g.Date, g.navigator, g.PushManager);
|
|
}
|
|
|
|
test('setLanguage resolves only once <html lang> names the language', async () => {
|
|
const { g, calls } = fakePage();
|
|
run(waitForLanguageOnSetLanguage, g);
|
|
let done = false;
|
|
const pending = g.Meteor.callAsync('setLanguage', 'zh_SG').then(value => { done = true; return value; });
|
|
await new Promise(r => setTimeout(r, 120));
|
|
assert.equal(done, false, 'not while the page still shows the old language');
|
|
g.document.documentElement.lang = 'zh-SG';
|
|
assert.equal(await pending, 'setLanguage done', 'the method result is kept');
|
|
assert.deepEqual(calls, [['setLanguage', 'zh_SG']]);
|
|
});
|
|
|
|
test('other methods are not held, and the wrapper is installed once', async () => {
|
|
const { g } = fakePage();
|
|
run(waitForLanguageOnSetLanguage, g);
|
|
const first = g.Meteor.callAsync;
|
|
run(waitForLanguageOnSetLanguage, g);
|
|
assert.equal(g.Meteor.callAsync, first);
|
|
const started = Date.now();
|
|
assert.equal(await g.Meteor.callAsync('cards.update', 1), 'cards.update done');
|
|
assert.ok(Date.now() - started < 50);
|
|
});
|
|
|
|
test('negative: a language the page never shows does not hang the spec, it waits at most about 10 s', () => {
|
|
const source = waitForLanguageOnSetLanguage.toString();
|
|
assert.match(source, /Date\.now\(\) \+ 10000/);
|
|
assert.match(source, /\|\| Date\.now\(\) > deadline/);
|
|
});
|
|
|
|
test('a page without Meteor yet gets the wrapper when Meteor arrives', async () => {
|
|
const { g } = fakePage();
|
|
const meteor = g.Meteor; delete g.Meteor;
|
|
run(waitForLanguageOnSetLanguage, g);
|
|
g.Meteor = meteor;
|
|
await new Promise(r => setTimeout(r, 60));
|
|
assert.equal(g.Meteor.callAsync.__waitsForLanguage, true);
|
|
});
|
|
|
|
test('WebKit answers a push subscription with none; Chromium and Firefox are left alone', async () => {
|
|
const agents = {
|
|
webkit: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15',
|
|
chromium: 'Mozilla/5.0 (Macintosh) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36',
|
|
firefox: 'Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0',
|
|
};
|
|
for (const [name, userAgent] of Object.entries(agents)) {
|
|
const original = function getSubscription() { return 'real'; };
|
|
function PushManager() {}
|
|
PushManager.prototype.getSubscription = original;
|
|
const g = { navigator: { userAgent }, PushManager };
|
|
run(noPushSubscriptionInWebKit, g);
|
|
if (name === 'webkit') assert.equal(await PushManager.prototype.getSubscription(), null);
|
|
else assert.equal(PushManager.prototype.getSubscription, original, `${name} untouched`);
|
|
}
|
|
});
|
|
|
|
test('the fixture adds both scripts to the test context', () => {
|
|
const fixtures = fs.readFileSync(path.join(__dirname, 'playwright', 'fixtures.js'), 'utf8');
|
|
assert.match(fixtures, /context: async \(\{ context \}, use\) => \{[\s\S]*addInitScript\(waitForLanguageOnSetLanguage\)[\s\S]*addInitScript\(noPushSubscriptionInWebKit\)/);
|
|
});
|