roamwright 0.61.9 → 0.61.11
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.
- package/geometry/animal-ear.js +5 -12
- package/package.json +2 -1
- package/scripts/browser-scripts.mjs +4 -2
- package/scripts/build.py +404 -0
- package/tools/README.md +11 -0
- package/tools/bake-publish.cjs +212 -0
- package/tools/build-freshness.cjs +148 -0
- package/tools/look-guard.sh +61 -0
- package/tools/motion-lab.cjs +451 -0
- package/tools/motion-lab.test.cjs +43 -0
- package/tools/phone-guard.py +161 -0
- package/tools/remote-runner.sh +4 -1
- package/tools/runners.test.cjs +92 -0
- package/tools/runtime-checks.test.cjs +53 -0
- package/tools/scene-lint.cjs +301 -0
- package/tools/scene-lint.test.cjs +75 -0
- package/tools/service-worker-check.cjs +257 -0
- package/tools/set-cost.cjs +110 -0
- package/tools/speed-guard.sh +124 -0
- package/tools/travel-free.cjs +90 -0
- package/tools/viewport-check.cjs +228 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Generic viewport, live-resize, DPR cap, touch-phone, and tablet-rotation check built on a Roamwright page driver.
|
|
2
|
+
// Verifies that the WebGL drawing buffer, post-processing scene texture, camera aspect, canvas bounds, and HUD stay
|
|
3
|
+
// synchronized across quality presets, desktop display changes, phone viewports, and stale tablet CSS widths.
|
|
4
|
+
//
|
|
5
|
+
// const { runViewportCheck } = require('roamwright/tools/viewport-check.cjs');
|
|
6
|
+
// await runViewportCheck(driver, { address: 'location/harbour' });
|
|
7
|
+
'use strict';
|
|
8
|
+
const assert = require('node:assert/strict');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runs the desktop, phone, and tablet viewport synchronization checks against a built Roamwright page.
|
|
12
|
+
*
|
|
13
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
14
|
+
* @param {object} [options]
|
|
15
|
+
* @param {string} [options.address=''] Deep-link address to open (empty opens the default land).
|
|
16
|
+
* @param {string[]} [options.presets=['low', 'high']] Quality presets cycled at native 4K on desktop.
|
|
17
|
+
* @param {string} [options.desktopHudSelector='#debug-t'] Selector for the desktop perf/resolution readout.
|
|
18
|
+
* @param {string} [options.hudSelector='#hud'] Selector for the root HUD container.
|
|
19
|
+
* @param {string} [options.closeCardSelector='#card-x'] Selector for the arrival card close button.
|
|
20
|
+
* @param {string} [options.fullscreenButtonSelector='#b-full'] Selector for the fullscreen toggle button.
|
|
21
|
+
* @param {string} [options.turnedClass='turned'] Body class used for rotated phone landscape layout.
|
|
22
|
+
* @param {string} [options.touchNonPhoneSelector='body.touch:not(.phone)'] Selector patched to simulate stale tablet CSS width.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
async function runViewportCheck(
|
|
26
|
+
driver,
|
|
27
|
+
{
|
|
28
|
+
address = '',
|
|
29
|
+
presets = ['low', 'high'],
|
|
30
|
+
desktopHudSelector = '#debug-t',
|
|
31
|
+
hudSelector = '#hud',
|
|
32
|
+
closeCardSelector = '#card-x',
|
|
33
|
+
fullscreenButtonSelector = '#b-full',
|
|
34
|
+
turnedClass = 'turned',
|
|
35
|
+
touchNonPhoneSelector = 'body.touch:not(.phone)',
|
|
36
|
+
} = {},
|
|
37
|
+
) {
|
|
38
|
+
const { BASE, GPU, chromium, shell, debug, enter, applyStorage, routeUrl } = driver;
|
|
39
|
+
const pageUrl = routeUrl(address, { base: BASE, bust: false, extra: 'mute' });
|
|
40
|
+
const browser = await chromium.launch({ executablePath: shell, ...GPU });
|
|
41
|
+
try {
|
|
42
|
+
const page = await browser.newPage({
|
|
43
|
+
viewport: { width: 1920, height: 1080 },
|
|
44
|
+
deviceScaleFactor: 2,
|
|
45
|
+
screen: { width: 1920, height: 1080 },
|
|
46
|
+
});
|
|
47
|
+
page.on('pageerror', error => console.error(error.message));
|
|
48
|
+
await applyStorage(page, {
|
|
49
|
+
quality: 'medium',
|
|
50
|
+
'quality-scale': JSON.stringify({ name: 'medium', scale: 0.75 }),
|
|
51
|
+
});
|
|
52
|
+
await page.addInitScript(() => {
|
|
53
|
+
// Read the ordinary text path; the metrics worker uses the same formatter.
|
|
54
|
+
HTMLCanvasElement.prototype.transferControlToOffscreen = undefined;
|
|
55
|
+
});
|
|
56
|
+
await page.goto(pageUrl);
|
|
57
|
+
|
|
58
|
+
async function ready() {
|
|
59
|
+
await page.waitForFunction(d => window[d]?.state.mode === 'play', debug, { timeout: 180000 });
|
|
60
|
+
await page.evaluate(d => window[d].holdQuality(true), debug);
|
|
61
|
+
await page.waitForFunction(d => window[d].state.debug && window[d].state.frame > 2, debug);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function picture(w, h) {
|
|
65
|
+
await page
|
|
66
|
+
.waitForFunction(
|
|
67
|
+
([d, hudSel, width, height]) => {
|
|
68
|
+
const g = window[d];
|
|
69
|
+
const gl = g.renderer.getContext();
|
|
70
|
+
const image = g.post.final.material.uniforms.tScene.value.image;
|
|
71
|
+
return (
|
|
72
|
+
gl.drawingBufferWidth === width &&
|
|
73
|
+
gl.drawingBufferHeight === height &&
|
|
74
|
+
image.width === width &&
|
|
75
|
+
image.height === height &&
|
|
76
|
+
document.querySelector(hudSel).textContent.includes(width + ' x ' + height + ' px')
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
[debug, desktopHudSelector, w, h],
|
|
80
|
+
{ timeout: 12000 },
|
|
81
|
+
)
|
|
82
|
+
.catch(async error => {
|
|
83
|
+
console.error(
|
|
84
|
+
await page.evaluate(
|
|
85
|
+
([d, hudSel]) => {
|
|
86
|
+
const g = window[d];
|
|
87
|
+
return {
|
|
88
|
+
canvas: [g.renderer.domElement.width, g.renderer.domElement.height],
|
|
89
|
+
scene: g.post.drawn,
|
|
90
|
+
hud: document.querySelector(hudSel).textContent,
|
|
91
|
+
visible: g.state.debug,
|
|
92
|
+
scale: g.renderer.getPixelRatio(),
|
|
93
|
+
viewport: [innerWidth, innerHeight],
|
|
94
|
+
image: [g.post.sceneRT.width, g.post.sceneRT.height],
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
[debug, desktopHudSelector],
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
throw error;
|
|
101
|
+
});
|
|
102
|
+
const text = await page.locator(desktopHudSelector).textContent();
|
|
103
|
+
assert.equal(text.split('\n').filter(line => /\d+ x \d+/.test(line)).length, 1);
|
|
104
|
+
console.log(w + ' x ' + h + ' scene, output and HUD');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await ready();
|
|
108
|
+
await picture(3840, 2160);
|
|
109
|
+
for (const preset of presets) {
|
|
110
|
+
await page.evaluate(([d, name]) => window[d].chooseQuality(name), [debug, preset]);
|
|
111
|
+
await picture(3840, 2160);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const session = await page.context().newCDPSession(page);
|
|
115
|
+
const display = (width, height, screenWidth, screenHeight, deviceScaleFactor = 2) =>
|
|
116
|
+
session.send('Emulation.setDeviceMetricsOverride', {
|
|
117
|
+
width,
|
|
118
|
+
height,
|
|
119
|
+
screenWidth,
|
|
120
|
+
screenHeight,
|
|
121
|
+
deviceScaleFactor,
|
|
122
|
+
mobile: false,
|
|
123
|
+
});
|
|
124
|
+
await display(1920, 960, 1920, 1080);
|
|
125
|
+
await picture(3840, 1920);
|
|
126
|
+
await display(2560, 1080, 2560, 1440);
|
|
127
|
+
await picture(3840, 1620);
|
|
128
|
+
await display(640, 400, 1920, 1080);
|
|
129
|
+
await picture(1280, 800);
|
|
130
|
+
await display(640, 400, 1440, 900);
|
|
131
|
+
await picture(1280, 800);
|
|
132
|
+
await display(640, 400, 1920, 1080);
|
|
133
|
+
await picture(1280, 800);
|
|
134
|
+
await display(1920, 1080, 1920, 1080, 1);
|
|
135
|
+
await picture(1920, 1080);
|
|
136
|
+
await page.close();
|
|
137
|
+
|
|
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
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
[debug, width, height],
|
|
154
|
+
{ timeout: 12000 },
|
|
155
|
+
);
|
|
156
|
+
console.log(width + ' x ' + height + ' scene and output filling the touch viewport');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const phone = await browser.newPage({ viewport: { width: 430, height: 932 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true });
|
|
160
|
+
await applyStorage(phone, { quality: 'medium' });
|
|
161
|
+
await enter(phone, pageUrl, { waitUntil: 'load', direct: true });
|
|
162
|
+
await checkTouchViewport(phone, 1920, 885);
|
|
163
|
+
await phone.setViewportSize({ width: 742, height: 430 });
|
|
164
|
+
await checkTouchViewport(phone, 1863, 1080);
|
|
165
|
+
await phone.setViewportSize({ width: 600, height: 300 });
|
|
166
|
+
await checkTouchViewport(phone, 1800, 900);
|
|
167
|
+
await phone.close();
|
|
168
|
+
|
|
169
|
+
const tablet = await browser.newPage({
|
|
170
|
+
viewport: { width: 1194, height: 696 },
|
|
171
|
+
screen: { width: 834, height: 1194 },
|
|
172
|
+
deviceScaleFactor: 2,
|
|
173
|
+
hasTouch: true,
|
|
174
|
+
isMobile: true,
|
|
175
|
+
});
|
|
176
|
+
await applyStorage(tablet, { quality: 'medium' });
|
|
177
|
+
await enter(tablet, pageUrl, { waitUntil: 'load', direct: true });
|
|
178
|
+
await checkTouchViewport(tablet, 2388, 1392);
|
|
179
|
+
// Simulate stale innerWidth and stale portrait CSS width during tablet rotation.
|
|
180
|
+
await tablet.evaluate(() => {
|
|
181
|
+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 834 });
|
|
182
|
+
window.orientationLocks = [];
|
|
183
|
+
screen.orientation.lock = async orientation => {
|
|
184
|
+
window.orientationLocks.push(orientation);
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
await tablet.addStyleTag({ content: `${touchNonPhoneSelector} { width: 834px; }` });
|
|
188
|
+
for (const [width, height] of [
|
|
189
|
+
[834, 1056],
|
|
190
|
+
[1194, 696],
|
|
191
|
+
[434, 578],
|
|
192
|
+
[834, 1056],
|
|
193
|
+
]) {
|
|
194
|
+
await tablet.setViewportSize({ width, height });
|
|
195
|
+
await tablet.waitForFunction(
|
|
196
|
+
([d, hudSel, turned, w, h]) => {
|
|
197
|
+
const { renderer, post, camera } = window[d];
|
|
198
|
+
const fillsFrame = element => {
|
|
199
|
+
const box = element.getBoundingClientRect();
|
|
200
|
+
return box.x === 0 && box.y === 0 && box.width === w && box.height === h;
|
|
201
|
+
};
|
|
202
|
+
return (
|
|
203
|
+
fillsFrame(renderer.domElement) &&
|
|
204
|
+
fillsFrame(document.querySelector(hudSel)) &&
|
|
205
|
+
camera.aspect === w / h &&
|
|
206
|
+
renderer.domElement.width === w * 2 &&
|
|
207
|
+
renderer.domElement.height === h * 2 &&
|
|
208
|
+
post.sceneRT.width === w * 2 &&
|
|
209
|
+
post.sceneRT.height === h * 2 &&
|
|
210
|
+
!document.body.classList.contains(turned)
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
[debug, hudSelector, turnedClass, width, height],
|
|
214
|
+
{ timeout: 12000 },
|
|
215
|
+
);
|
|
216
|
+
console.log('Tablet camera, scene, canvas and HUD fit ' + width + ' x ' + height);
|
|
217
|
+
}
|
|
218
|
+
await tablet.locator(closeCardSelector).click();
|
|
219
|
+
await tablet.locator(fullscreenButtonSelector).click();
|
|
220
|
+
await tablet.waitForFunction(() => !!document.fullscreenElement);
|
|
221
|
+
assert.deepEqual(await tablet.evaluate(() => window.orientationLocks), []);
|
|
222
|
+
await tablet.close();
|
|
223
|
+
} finally {
|
|
224
|
+
await browser.close();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
module.exports = { runViewportCheck };
|