roamwright 0.61.15 → 0.61.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,11 @@ const assert = require('node:assert/strict');
20
20
  * @param {string} [options.fullscreenButtonSelector='#b-full'] Selector for the fullscreen toggle button.
21
21
  * @param {string} [options.turnedClass='turned'] Body class used for rotated phone landscape layout.
22
22
  * @param {string} [options.touchNonPhoneSelector='body.touch:not(.phone)'] Selector patched to simulate stale tablet CSS width.
23
+ * @param {{ output?: number, scene?: number }} [options.phoneScale={ output: 1, scene: 1 }] The share of each side the
24
+ * phone's Medium preset draws at: the output of its render limit, and the scene texture of the output (each within a
25
+ * pixel of rounding).
26
+ * @param {{ width: number, height: number }} [options.phoneLimit={ width: 1920, height: 1080 }] The most pixels the phone's
27
+ * output is drawn at, before `phoneScale`; a device with more is fitted into it.
23
28
  * @returns {Promise<void>}
24
29
  */
25
30
  async function runViewportCheck(
@@ -33,6 +38,8 @@ async function runViewportCheck(
33
38
  fullscreenButtonSelector = '#b-full',
34
39
  turnedClass = 'turned',
35
40
  touchNonPhoneSelector = 'body.touch:not(.phone)',
41
+ phoneScale = {},
42
+ phoneLimit = { width: 1920, height: 1080 },
36
43
  } = {},
37
44
  ) {
38
45
  const { BASE, GPU, chromium, shell, debug, enter, applyStorage, routeUrl } = driver;
@@ -135,35 +142,63 @@ async function runViewportCheck(
135
142
  await picture(1920, 1080);
136
143
  await page.close();
137
144
 
138
- async function checkTouchViewport(tab, width, height) {
139
- await tab.waitForFunction(
140
- ([d, w, h]) => {
141
- const { renderer, post } = window[d];
142
- const gl = renderer.getContext();
143
- const bounds = renderer.domElement.getBoundingClientRect();
144
- return (
145
- gl.drawingBufferWidth === w &&
146
- gl.drawingBufferHeight === h &&
147
- post.sceneRT.width === w &&
148
- post.sceneRT.height === h &&
149
- Math.abs(bounds.width - innerWidth) < 1 &&
150
- Math.abs(bounds.height - innerHeight) < 1
145
+ // Checks the output is `width` x `height` (or, given a `scale` `{ output, scene }`, the device's pixels of that size fitted
146
+ // into the phone's limit drawn at `scale.output` of each side) and the scene texture `scale.scene` of the output.
147
+ async function checkTouchViewport(tab, width, height, scale = null) {
148
+ const fit = scale
149
+ ? Math.min(1, (phoneLimit.width * (scale.output ?? 1)) / width, (phoneLimit.height * (scale.output ?? 1)) / height)
150
+ : 1;
151
+ const outW = Math.floor(width * fit);
152
+ const outH = Math.floor(height * fit);
153
+ const sceneW = Math.round(outW * (scale?.scene ?? 1));
154
+ const sceneH = Math.round(outH * (scale?.scene ?? 1));
155
+ await tab
156
+ .waitForFunction(
157
+ ([d, w, h, sw, sh]) => {
158
+ const { renderer, post } = window[d];
159
+ const gl = renderer.getContext();
160
+ const bounds = renderer.domElement.getBoundingClientRect();
161
+ const near = (a, b) => Math.abs(a - b) <= 1;
162
+ return (
163
+ near(gl.drawingBufferWidth, w) &&
164
+ near(gl.drawingBufferHeight, h) &&
165
+ near(post.sceneRT.width, sw) &&
166
+ near(post.sceneRT.height, sh) &&
167
+ Math.abs(bounds.width - innerWidth) < 1 &&
168
+ Math.abs(bounds.height - innerHeight) < 1
169
+ );
170
+ },
171
+ [debug, outW, outH, sceneW, sceneH],
172
+ { timeout: 12000 },
173
+ )
174
+ .catch(async error => {
175
+ console.error(
176
+ await tab.evaluate(d => {
177
+ const { renderer, post } = window[d];
178
+ const gl = renderer.getContext();
179
+ const bounds = renderer.domElement.getBoundingClientRect();
180
+ return {
181
+ buffer: [gl.drawingBufferWidth, gl.drawingBufferHeight],
182
+ scene: [post.sceneRT.width, post.sceneRT.height],
183
+ bounds: [bounds.width, bounds.height],
184
+ viewport: [innerWidth, innerHeight],
185
+ ratio: renderer.getPixelRatio(),
186
+ };
187
+ }, debug),
151
188
  );
152
- },
153
- [debug, width, height],
154
- { timeout: 12000 },
155
- );
156
- console.log(width + ' x ' + height + ' scene and output filling the touch viewport');
189
+ throw error;
190
+ });
191
+ console.log(`${outW} x ${outH} output and ${sceneW} x ${sceneH} scene filling the touch viewport`);
157
192
  }
158
193
 
159
194
  const phone = await browser.newPage({ viewport: { width: 430, height: 932 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true });
160
195
  await applyStorage(phone, { quality: 'medium' });
161
196
  await enter(phone, pageUrl, { waitUntil: 'load', direct: true });
162
- await checkTouchViewport(phone, 1920, 885);
197
+ await checkTouchViewport(phone, 2796, 1290, phoneScale); // 932 x 430 at 3x, turned
163
198
  await phone.setViewportSize({ width: 742, height: 430 });
164
- await checkTouchViewport(phone, 1863, 1080);
199
+ await checkTouchViewport(phone, 2226, 1290, phoneScale);
165
200
  await phone.setViewportSize({ width: 600, height: 300 });
166
- await checkTouchViewport(phone, 1800, 900);
201
+ await checkTouchViewport(phone, 1800, 900, phoneScale);
167
202
  await phone.close();
168
203
 
169
204
  const tablet = await browser.newPage({