MCPcopy Create free account
hub / github.com/adobe/react-spectrum / perform

Function perform

perf/runner.mjs:77–133  ·  view source on GitHub ↗
({page, session, size}, scenario)

Source from the content-addressed store, hash-verified

75}
76
77async function perform({page, session, size}, scenario) {
78 let {fixture, action} = driver(scenario);
79 let spec = action.spec(size);
80 // Resolve pointer coordinates before arming, so input timestamps are the
81 // measurement boundary and locator polling/layout reads cannot enter the score.
82 let box = ['pointerover', 'wheel'].includes(spec.event)
83 ? await page.locator(spec.target).boundingBox()
84 : undefined;
85 if (box === null) {
86 throw new Error(`The ${spec.event} target is not visible.`);
87 }
88 let center = box && {x: box.x + box.width / 2, y: box.y + box.height / 2};
89 await page.evaluate(spec => window.__bench.arm(spec), spec);
90 if (action.input) {
91 await action.input(page);
92 } else if (spec.event === 'wheel') {
93 // Chromium generates the wheel stream at its own frame cadence, so Node timers and
94 // protocol round trips don't shape the input. The call resolves when it finishes.
95 await session.send('Input.synthesizeScrollGesture', {
96 ...center,
97 yDistance: -spec.distance,
98 speed: spec.speed,
99 gestureSourceType: 'mouse',
100 preventFling: true
101 });
102 } else if (spec.event === 'keydown') {
103 await page.keyboard.press(spec.key);
104 } else if (spec.event === 'pointerover') {
105 await page.mouse.move(center.x, center.y);
106 } else {
107 await page.locator(spec.target).click();
108 }
109 await page.waitForFunction(() => window.__bench.done(), null, {timeout: 15000});
110 // Event Timing notifications may arrive after the semantic endpoint.
111 await pause(100);
112 let sample = await page.evaluate(() => window.__bench.read());
113 if (
114 sample.visibility !== 'visible' ||
115 !(await page.evaluate(() => document.visibilityState === 'visible'))
116 ) {
117 throw new Error(
118 'The benchmark page became hidden. Keep the browser visible during headed runs.'
119 );
120 }
121 if (spec.event === 'wheel') {
122 // Frame intervals must span the gesture, however many long frames it contained.
123 let elapsed = sample.frameIntervals.reduce((total, interval) => total + interval, 0);
124 if (sample.inputEvents < 10 || elapsed < 0.9 * (spec.distance / spec.speed) * 1000) {
125 throw new Error('Scrolling did not receive a wheel stream or span the whole gesture.');
126 }
127 }
128 let context = {page, size, action, sample};
129 await fixture.verify?.(context);
130 await action.verify?.(context);
131 await action.cleanup?.(context);
132 return sample;
133}
134

Callers 2

measureTrialsFunction · 0.70
diagnoseFunction · 0.70

Calls 3

driverFunction · 0.90
pauseFunction · 0.90
moveMethod · 0.65

Tested by

no test coverage detected