vouchington-tooling 0.53.0 → 0.54.0
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/README.md +76 -12
- package/dist/agent-blackboard/index.d.mts +0 -1
- package/dist/agent-blackboard/index.mjs +0 -23
- package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
- package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
- package/dist/cli/commands/agent-blackboard.d.mts +0 -2
- package/dist/cli/commands/agent-blackboard.mjs +7 -121
- package/dist/cli/commands/story-coverage.d.mts +2 -0
- package/dist/cli/commands/story-coverage.mjs +56 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/parse-forwarded-commands.d.mts +3 -0
- package/dist/cli/parse-forwarded-commands.mjs +2 -0
- package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
- package/dist/cli/parse-story-coverage-fields.mjs +69 -0
- package/dist/cli/parse-story-coverage.d.mts +8 -0
- package/dist/cli/parse-story-coverage.mjs +34 -0
- package/dist/cli/parse.d.mts +5 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +8 -7
- package/dist/host-storage/check.d.mts +38 -0
- package/dist/host-storage/check.mjs +109 -0
- package/dist/host-storage/cli.d.mts +7 -0
- package/dist/host-storage/cli.mjs +102 -0
- package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
- package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
- package/dist/host-storage/index.d.mts +3 -0
- package/dist/host-storage/index.mjs +3 -0
- package/dist/host-storage/preflight.d.mts +22 -0
- package/dist/host-storage/preflight.mjs +105 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/playwright/assertions.d.mts +1 -0
- package/dist/playwright/assertions.mjs +5 -0
- package/dist/playwright/blocked-external-network.d.mts +15 -0
- package/dist/playwright/blocked-external-network.mjs +73 -0
- package/dist/playwright/browser-dialog-issues.d.mts +12 -0
- package/dist/playwright/browser-dialog-issues.mjs +29 -0
- package/dist/playwright/browser-errors.d.mts +22 -0
- package/dist/playwright/browser-errors.mjs +130 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
- package/dist/playwright/browser-issue-records.d.mts +42 -0
- package/dist/playwright/browser-issue-records.mjs +148 -0
- package/dist/playwright/browser-test.d.mts +21 -0
- package/dist/playwright/browser-test.mjs +68 -0
- package/dist/playwright/expect-no-broken-images.d.mts +17 -0
- package/dist/playwright/expect-no-broken-images.mjs +39 -0
- package/dist/playwright/index.d.mts +30 -0
- package/dist/playwright/index.mjs +22 -0
- package/dist/playwright/mobile-assertions.d.mts +14 -0
- package/dist/playwright/mobile-assertions.mjs +43 -0
- package/dist/playwright/navigate-to.d.mts +27 -0
- package/dist/playwright/navigate-to.mjs +39 -0
- package/dist/playwright/radix-select.d.mts +18 -0
- package/dist/playwright/radix-select.mjs +19 -0
- package/dist/playwright/random-id.d.mts +34 -0
- package/dist/playwright/random-id.mjs +37 -0
- package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
- package/dist/playwright/retry-on-connection-lost.mjs +107 -0
- package/dist/playwright/scroll-to-load-more.d.mts +37 -0
- package/dist/playwright/scroll-to-load-more.mjs +158 -0
- package/dist/playwright/storybook.d.mts +2 -0
- package/dist/playwright/storybook.mjs +13 -0
- package/dist/playwright/test-fixtures.d.mts +1 -0
- package/dist/playwright/test-fixtures.mjs +2 -0
- package/dist/playwright/test-lifecycle-reporter.d.mts +11 -0
- package/dist/playwright/test-lifecycle-reporter.mjs +35 -0
- package/dist/playwright/totp.d.mts +6 -0
- package/dist/playwright/totp.mjs +37 -0
- package/dist/playwright/turnstile-stub.d.mts +8 -0
- package/dist/playwright/turnstile-stub.mjs +61 -0
- package/dist/playwright/viewport-constants.d.mts +30 -0
- package/dist/playwright/viewport-constants.mjs +9 -0
- package/dist/playwright/virtual-authenticator.d.mts +5 -0
- package/dist/playwright/virtual-authenticator.mjs +15 -0
- package/dist/playwright/wait-for-hydration.d.mts +29 -0
- package/dist/playwright/wait-for-hydration.mjs +81 -0
- package/dist/shell-parse/ansi-c-string.d.mts +12 -0
- package/dist/shell-parse/ansi-c-string.mjs +80 -0
- package/dist/shell-parse/index.d.mts +20 -0
- package/dist/shell-parse/index.mjs +15 -0
- package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
- package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
- package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
- package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
- package/dist/shell-parse/shell-commands.d.mts +24 -0
- package/dist/shell-parse/shell-commands.mjs +155 -0
- package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
- package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
- package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
- package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
- package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
- package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
- package/dist/shell-parse/shell-heredoc.d.mts +10 -0
- package/dist/shell-parse/shell-heredoc.mjs +90 -0
- package/dist/shell-parse/shell-redirections.d.mts +5 -0
- package/dist/shell-parse/shell-redirections.mjs +34 -0
- package/dist/shell-parse/shell-script-operand.d.mts +13 -0
- package/dist/shell-parse/shell-script-operand.mjs +103 -0
- package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
- package/dist/shell-parse/shell-stdin-script.mjs +61 -0
- package/dist/shell-parse/shell-token-utils.d.mts +9 -0
- package/dist/shell-parse/shell-token-utils.mjs +33 -0
- package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
- package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
- package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
- package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
- package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
- package/dist/shell-parse/shell-tokenizer.mjs +104 -0
- package/dist/story-coverage/analyze.d.mts +8 -0
- package/dist/story-coverage/analyze.mjs +24 -0
- package/dist/story-coverage/check.d.mts +11 -0
- package/dist/story-coverage/check.mjs +42 -0
- package/dist/story-coverage/components.d.mts +10 -0
- package/dist/story-coverage/components.mjs +40 -0
- package/dist/story-coverage/coverage.d.mts +10 -0
- package/dist/story-coverage/coverage.mjs +43 -0
- package/dist/story-coverage/index.d.mts +13 -0
- package/dist/story-coverage/index.mjs +7 -0
- package/dist/story-coverage/messages.d.mts +10 -0
- package/dist/story-coverage/messages.mjs +42 -0
- package/dist/story-coverage/options.d.mts +27 -0
- package/dist/story-coverage/options.mjs +51 -0
- package/dist/story-coverage/workspace.d.mts +2 -0
- package/dist/story-coverage/workspace.mjs +27 -0
- package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
- package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
- package/dist/vitest-diagnostics/index.d.mts +9 -1
- package/dist/vitest-diagnostics/index.mjs +5 -1
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +10 -1
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +43 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +50 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +69 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
- package/dist/vitest-diagnostics/vitest-process-resources.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-process-resources.mjs +51 -0
- package/dist/vitest-effective-timeout/cap.d.mts +9 -0
- package/dist/vitest-effective-timeout/cap.mjs +28 -0
- package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
- package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
- package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
- package/dist/vitest-effective-timeout/config-file.mjs +23 -0
- package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
- package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
- package/dist/vitest-effective-timeout/index.d.mts +7 -0
- package/dist/vitest-effective-timeout/index.mjs +4 -0
- package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
- package/dist/vitest-effective-timeout/profiles.mjs +33 -0
- package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
- package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
- package/docs/mcp-server.md +2 -13
- package/package.json +32 -2
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/chromium-launch-probe.d.mts +7 -0
- package/scripts/chromium-launch-probe.mjs +101 -0
- package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
- package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
- package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
- package/scripts/run-bounded.py +199 -0
- package/scripts/run_bounded_process.py +129 -0
- package/scripts/worktree/git-index-lock.sh +16 -0
- package/scripts/worktree/git-worktrees.sh +23 -20
- package/scripts/worktree/reset-worktree-run.sh +199 -0
- package/scripts/worktree/reset-worktree.sh +122 -0
- package/skills/blackboard/SKILL.md +4 -64
- package/skills/stacked-prs/SKILL.md +1 -1
- package/skills/stacked-prs/references/drain.md +2 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers response and requestfailed listeners on `page` to record any image
|
|
3
|
+
* requests that fail at the network level or return a non-2xx HTTP status.
|
|
4
|
+
*
|
|
5
|
+
* Call once at the top of a test, then call `assertNoImageFailures()` after the
|
|
6
|
+
* interaction under test completes. This is the network-level gate — it catches
|
|
7
|
+
* off-screen and lazy-loaded images that a visible-element poll cannot see.
|
|
8
|
+
*
|
|
9
|
+
* Any image failure during the test surfaces here. Ignore a known-flaky host in
|
|
10
|
+
* the caller's network policy instead of suppressing the error here.
|
|
11
|
+
*/
|
|
12
|
+
export function installImageResponseGuard(page) {
|
|
13
|
+
const failures = [];
|
|
14
|
+
// Treat 2xx (success) and 3xx (304 Not Modified, redirect hops) as healthy — Playwright
|
|
15
|
+
// emits a response event for each hop, and the terminal response is what matters.
|
|
16
|
+
page.on('response', (response) => {
|
|
17
|
+
const status = response.status();
|
|
18
|
+
if (status >= 200 && status < 400)
|
|
19
|
+
return;
|
|
20
|
+
if (response.request().resourceType() === 'image') {
|
|
21
|
+
failures.push({ url: response.url(), status });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
page.on('requestfailed', (request) => {
|
|
25
|
+
if (request.resourceType() === 'image') {
|
|
26
|
+
failures.push({ url: request.url(), status: null });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
assertNoImageFailures() {
|
|
31
|
+
if (failures.length === 0)
|
|
32
|
+
return;
|
|
33
|
+
const details = failures
|
|
34
|
+
.map((failure) => ` ${failure.status ?? 'failed'} ${failure.url}`)
|
|
35
|
+
.join('\n');
|
|
36
|
+
throw new Error(`${failures.length} image(s) failed to load:\n${details}`);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import TestLifecycleReporter from './test-lifecycle-reporter.mts';
|
|
2
|
+
export { BrowserIssueMonitor } from './browser-errors.mts';
|
|
3
|
+
export type { BrowserIssueAllowlistEntry } from './browser-issue-records.mts';
|
|
4
|
+
export { createDialogIssue, formatBrowserDialogIssue, getBrowserDialogIssueSearchableValues, getPageUrl, } from './browser-dialog-issues.mts';
|
|
5
|
+
export type { BrowserDialogIssue } from './browser-dialog-issues.mts';
|
|
6
|
+
export { createConsoleErrorIssue, createPageCrashIssue, createRequestFailedIssue, createWebErrorIssue, formatBrowserIssue, isBrowserSynthesizedResourceLoadError, isExpectedBrowserCancellation, isRetryableLocalConnectionLoss, matchesAllowlist, validateAllowlist, } from './browser-issue-records.mts';
|
|
7
|
+
export type { BrowserIssue } from './browser-issue-records.mts';
|
|
8
|
+
export { BLOCKED_EXTERNAL_NETWORK_RULES, blockedExternalRequestFailureAllowlist, installBlockedExternalNetwork, isBlockedExternalNetworkUrl, } from './blocked-external-network.mts';
|
|
9
|
+
export type { BlockedExternalNetworkRule } from './blocked-external-network.mts';
|
|
10
|
+
export { createBrowserErrorsFixture, createBrowserTest, expect, test, withMonitoredPage, } from './browser-test.mts';
|
|
11
|
+
export type { BrowserTestOptions } from './browser-test.mts';
|
|
12
|
+
export type { Browser, BrowserContext, Locator, Page, Request, TestInfo } from '@playwright/test';
|
|
13
|
+
export { navigateTo } from './navigate-to.mts';
|
|
14
|
+
export { retryOnConnectionLost } from './retry-on-connection-lost.mts';
|
|
15
|
+
export { forceMainScrollableBeforeHydration, scrollToLoadMore } from './scroll-to-load-more.mts';
|
|
16
|
+
export { DEFAULT_TURNSTILE_STUB_ATTRIBUTE, DEFAULT_TURNSTILE_STUB_TOKEN, installTurnstileStub, } from './turnstile-stub.mts';
|
|
17
|
+
export type { TurnstileStubOptions } from './turnstile-stub.mts';
|
|
18
|
+
export { waitForBelowFoldHydration } from './wait-for-hydration.mts';
|
|
19
|
+
export { requireTestValue } from './assertions.mts';
|
|
20
|
+
export { installImageResponseGuard } from './expect-no-broken-images.mts';
|
|
21
|
+
export { assertNoHorizontalScroll, getHorizontalOverflowState } from './mobile-assertions.mts';
|
|
22
|
+
export type { HorizontalOverflowState } from './mobile-assertions.mts';
|
|
23
|
+
export { openRadixDropdown } from './radix-select.mts';
|
|
24
|
+
export { randomSuffix } from './random-id.mts';
|
|
25
|
+
export { storybookBundleHasStory } from './storybook.mts';
|
|
26
|
+
export { TEST_PNG } from './test-fixtures.mts';
|
|
27
|
+
export { TestLifecycleReporter };
|
|
28
|
+
export { generateTotpCode } from './totp.mts';
|
|
29
|
+
export { DESKTOP_VIEWPORT, MOBILE_VIEWPORTS } from './viewport-constants.mts';
|
|
30
|
+
export { setupVirtualAuthenticator } from './virtual-authenticator.mts';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import TestLifecycleReporter from "./test-lifecycle-reporter.mjs";
|
|
2
|
+
export { BrowserIssueMonitor } from "./browser-errors.mjs";
|
|
3
|
+
export { createDialogIssue, formatBrowserDialogIssue, getBrowserDialogIssueSearchableValues, getPageUrl, } from "./browser-dialog-issues.mjs";
|
|
4
|
+
export { createConsoleErrorIssue, createPageCrashIssue, createRequestFailedIssue, createWebErrorIssue, formatBrowserIssue, isBrowserSynthesizedResourceLoadError, isExpectedBrowserCancellation, isRetryableLocalConnectionLoss, matchesAllowlist, validateAllowlist, } from "./browser-issue-records.mjs";
|
|
5
|
+
export { BLOCKED_EXTERNAL_NETWORK_RULES, blockedExternalRequestFailureAllowlist, installBlockedExternalNetwork, isBlockedExternalNetworkUrl, } from "./blocked-external-network.mjs";
|
|
6
|
+
export { createBrowserErrorsFixture, createBrowserTest, expect, test, withMonitoredPage, } from "./browser-test.mjs";
|
|
7
|
+
export { navigateTo } from "./navigate-to.mjs";
|
|
8
|
+
export { retryOnConnectionLost } from "./retry-on-connection-lost.mjs";
|
|
9
|
+
export { forceMainScrollableBeforeHydration, scrollToLoadMore } from "./scroll-to-load-more.mjs";
|
|
10
|
+
export { DEFAULT_TURNSTILE_STUB_ATTRIBUTE, DEFAULT_TURNSTILE_STUB_TOKEN, installTurnstileStub, } from "./turnstile-stub.mjs";
|
|
11
|
+
export { waitForBelowFoldHydration } from "./wait-for-hydration.mjs";
|
|
12
|
+
export { requireTestValue } from "./assertions.mjs";
|
|
13
|
+
export { installImageResponseGuard } from "./expect-no-broken-images.mjs";
|
|
14
|
+
export { assertNoHorizontalScroll, getHorizontalOverflowState } from "./mobile-assertions.mjs";
|
|
15
|
+
export { openRadixDropdown } from "./radix-select.mjs";
|
|
16
|
+
export { randomSuffix } from "./random-id.mjs";
|
|
17
|
+
export { storybookBundleHasStory } from "./storybook.mjs";
|
|
18
|
+
export { TEST_PNG } from "./test-fixtures.mjs";
|
|
19
|
+
export { TestLifecycleReporter };
|
|
20
|
+
export { generateTotpCode } from "./totp.mjs";
|
|
21
|
+
export { DESKTOP_VIEWPORT, MOBILE_VIEWPORTS } from "./viewport-constants.mjs";
|
|
22
|
+
export { setupVirtualAuthenticator } from "./virtual-authenticator.mjs";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Page } from '@playwright/test';
|
|
2
|
+
export interface HorizontalOverflowState {
|
|
3
|
+
overflow: boolean;
|
|
4
|
+
scrollWidth: number;
|
|
5
|
+
clientWidth: number;
|
|
6
|
+
offenders: Array<{
|
|
7
|
+
tag: string;
|
|
8
|
+
id: string;
|
|
9
|
+
cls: string;
|
|
10
|
+
right: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export declare function getHorizontalOverflowState(): HorizontalOverflowState;
|
|
14
|
+
export declare function assertNoHorizontalScroll(page: Page): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { expect } from '@playwright/test';
|
|
2
|
+
export function getHorizontalOverflowState() {
|
|
3
|
+
const root = globalThis.document;
|
|
4
|
+
const scrollWidth = root.documentElement.scrollWidth;
|
|
5
|
+
const clientWidth = root.documentElement.clientWidth;
|
|
6
|
+
if (scrollWidth <= clientWidth) {
|
|
7
|
+
return { overflow: false, scrollWidth, clientWidth, offenders: [] };
|
|
8
|
+
}
|
|
9
|
+
const offenders = [];
|
|
10
|
+
for (const element of root.querySelectorAll('*')) {
|
|
11
|
+
const rect = element.getBoundingClientRect();
|
|
12
|
+
if (rect.right > clientWidth + 1) {
|
|
13
|
+
offenders.push({
|
|
14
|
+
tag: element.tagName,
|
|
15
|
+
id: element.id,
|
|
16
|
+
cls: (element.getAttribute('class') ?? '').slice(0, 60),
|
|
17
|
+
right: Math.round(rect.right),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return { overflow: true, scrollWidth, clientWidth, offenders: offenders.slice(0, 10) };
|
|
22
|
+
}
|
|
23
|
+
export async function assertNoHorizontalScroll(page) {
|
|
24
|
+
// Poll until layout settles — CSS transitions like
|
|
25
|
+
// sidebar collapse may briefly cause scrollWidth > clientWidth.
|
|
26
|
+
const state = { lastResult: null };
|
|
27
|
+
try {
|
|
28
|
+
await expect
|
|
29
|
+
.poll(async () => {
|
|
30
|
+
state.lastResult = await page.evaluate(getHorizontalOverflowState);
|
|
31
|
+
return state.lastResult.overflow;
|
|
32
|
+
}, { timeout: 5000, intervals: [50, 100] })
|
|
33
|
+
.toBe(false);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
// Log only once after all retries are exhausted
|
|
37
|
+
const { lastResult } = state;
|
|
38
|
+
if (lastResult?.overflow) {
|
|
39
|
+
console.error(`Horizontal overflow detected: scrollWidth=${lastResult.scrollWidth} clientWidth=${lastResult.clientWidth}\nOffending elements:`, JSON.stringify(lastResult.offenders, null, 2));
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
import { retryOnConnectionLost } from './retry-on-connection-lost.mts';
|
|
3
|
+
import { installTurnstileStub } from './turnstile-stub.mts';
|
|
4
|
+
/**
|
|
5
|
+
* Navigate to a URL and wait for network idle (or a custom wait state).
|
|
6
|
+
* Always use this instead of raw page.goto() to avoid flaky tests
|
|
7
|
+
* caused by interacting with pages before they've fully loaded.
|
|
8
|
+
*
|
|
9
|
+
* Installs the Turnstile stub once per page (see turnstile-stub.mts) so the
|
|
10
|
+
* widget script does not keep third-party traffic alive past the navigation
|
|
11
|
+
* timeout. Pass `dependencies.installTurnstileStub` to replace that install.
|
|
12
|
+
*
|
|
13
|
+
* Retries transient connection errors (ERR_CONNECTION_REFUSED / RESET) using
|
|
14
|
+
* bounded retries and 5s backoff to absorb cold starts.
|
|
15
|
+
*
|
|
16
|
+
* Pass `waitUntil: 'load'` for pages with a connection that stays open and
|
|
17
|
+
* never reaches networkidle.
|
|
18
|
+
*
|
|
19
|
+
* Safe for URLs that redirect on the client — the readiness wait restarts against
|
|
20
|
+
* whichever document the redirect lands on (see wait-for-hydration.mts).
|
|
21
|
+
*/
|
|
22
|
+
export declare function navigateTo(page: Page, url: string, { waitUntil }?: {
|
|
23
|
+
waitUntil?: "load" | "networkidle" | undefined;
|
|
24
|
+
}, dependencies?: Partial<{
|
|
25
|
+
installTurnstileStub: typeof installTurnstileStub;
|
|
26
|
+
retryOnConnectionLost: typeof retryOnConnectionLost;
|
|
27
|
+
}>): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { retryOnConnectionLost } from "./retry-on-connection-lost.mjs";
|
|
2
|
+
import { installTurnstileStub } from "./turnstile-stub.mjs";
|
|
3
|
+
import { waitForBelowFoldHydration } from "./wait-for-hydration.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Navigate to a URL and wait for network idle (or a custom wait state).
|
|
6
|
+
* Always use this instead of raw page.goto() to avoid flaky tests
|
|
7
|
+
* caused by interacting with pages before they've fully loaded.
|
|
8
|
+
*
|
|
9
|
+
* Installs the Turnstile stub once per page (see turnstile-stub.mts) so the
|
|
10
|
+
* widget script does not keep third-party traffic alive past the navigation
|
|
11
|
+
* timeout. Pass `dependencies.installTurnstileStub` to replace that install.
|
|
12
|
+
*
|
|
13
|
+
* Retries transient connection errors (ERR_CONNECTION_REFUSED / RESET) using
|
|
14
|
+
* bounded retries and 5s backoff to absorb cold starts.
|
|
15
|
+
*
|
|
16
|
+
* Pass `waitUntil: 'load'` for pages with a connection that stays open and
|
|
17
|
+
* never reaches networkidle.
|
|
18
|
+
*
|
|
19
|
+
* Safe for URLs that redirect on the client — the readiness wait restarts against
|
|
20
|
+
* whichever document the redirect lands on (see wait-for-hydration.mts).
|
|
21
|
+
*/
|
|
22
|
+
export async function navigateTo(page, url, { waitUntil = 'networkidle' } = {}, dependencies) {
|
|
23
|
+
const installStub = dependencies?.installTurnstileStub ?? installTurnstileStub;
|
|
24
|
+
const retry = dependencies?.retryOnConnectionLost ?? retryOnConnectionLost;
|
|
25
|
+
await installStub(page);
|
|
26
|
+
await retry(async () => {
|
|
27
|
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
28
|
+
await page.waitForLoadState(waitUntil);
|
|
29
|
+
// React 19 + React Compiler can attach above-fold handlers after networkidle on
|
|
30
|
+
// slower machines. This bounded idle probe reduces that race but cannot prove
|
|
31
|
+
// every handler is wired; a control that rejects early interaction owns a
|
|
32
|
+
// disabled-until-hydrated boundary, and tests assert that boundary is enabled.
|
|
33
|
+
//
|
|
34
|
+
// A route that redirects on the client can reach `waitUntil` before the
|
|
35
|
+
// redirect fires, so pass it through: if the redirect lands mid-wait, the
|
|
36
|
+
// replacement document is settled to the same state this call asked for.
|
|
37
|
+
await waitForBelowFoldHydration(page, { waitUntil });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Locator } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Opens a Radix UI Select or DropdownMenu by pressing Space on the trigger.
|
|
4
|
+
*
|
|
5
|
+
* Radix portals the dropdown content outside the trigger's DOM subtree, so the
|
|
6
|
+
* trigger must be focused first; Space is the reliable keyboard activation path
|
|
7
|
+
* (ArrowDown also works for DropdownMenu but Space is universal for both).
|
|
8
|
+
*
|
|
9
|
+
* After calling this, wait for the option you want with `toBeAttached()` before
|
|
10
|
+
* clicking — not `toBeVisible()`. Radix items are attached to the DOM immediately
|
|
11
|
+
* but may not pass the visibility check until the CSS animation settles.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* await openRadixDropdown(page.getByTestId('sort-trigger'))
|
|
15
|
+
* await expect(page.getByTestId('sort-option-new')).toBeAttached()
|
|
16
|
+
* await page.getByTestId('sort-option-new').click()
|
|
17
|
+
*/
|
|
18
|
+
export declare function openRadixDropdown(trigger: Locator): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens a Radix UI Select or DropdownMenu by pressing Space on the trigger.
|
|
3
|
+
*
|
|
4
|
+
* Radix portals the dropdown content outside the trigger's DOM subtree, so the
|
|
5
|
+
* trigger must be focused first; Space is the reliable keyboard activation path
|
|
6
|
+
* (ArrowDown also works for DropdownMenu but Space is universal for both).
|
|
7
|
+
*
|
|
8
|
+
* After calling this, wait for the option you want with `toBeAttached()` before
|
|
9
|
+
* clicking — not `toBeVisible()`. Radix items are attached to the DOM immediately
|
|
10
|
+
* but may not pass the visibility check until the CSS animation settles.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* await openRadixDropdown(page.getByTestId('sort-trigger'))
|
|
14
|
+
* await expect(page.getByTestId('sort-option-new')).toBeAttached()
|
|
15
|
+
* await page.getByTestId('sort-option-new').click()
|
|
16
|
+
*/
|
|
17
|
+
export async function openRadixDropdown(trigger) {
|
|
18
|
+
await trigger.press(' ');
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a short random suffix for unique-ID-style usage in Playwright tests.
|
|
3
|
+
* Use this instead of `Date.now()`, which can collide between parallel workers
|
|
4
|
+
* and which returns different values when called twice in the same test.
|
|
5
|
+
*
|
|
6
|
+
* The suffix is 12 lowercase hex characters (about 48 bits of entropy), which
|
|
7
|
+
* is plenty for slug/title/hostname uniqueness while remaining short and
|
|
8
|
+
* readable in CI logs and screenshots.
|
|
9
|
+
*
|
|
10
|
+
* Compute the suffix once per test and reuse it everywhere a related ID is
|
|
11
|
+
* needed (slug, name, hostname, etc.) so all values stay consistent:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const suffix = randomSuffix()
|
|
15
|
+
* await insertRecord(`Example ${suffix}`, `example-${suffix}`)
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* If a `beforeAll` hook seeds data shared by a `describe` block (or a whole
|
|
19
|
+
* file), call `randomSuffix()` *inside* that hook, not at module/describe
|
|
20
|
+
* scope. Playwright's `fullyParallel` scheduler can hand a worker a second
|
|
21
|
+
* test from the same file, re-running `beforeAll` with module scope intact —
|
|
22
|
+
* a suffix hoisted outside the hook stays the same across that re-entry and
|
|
23
|
+
* produces the same slug/name twice, which throws on any unique column.
|
|
24
|
+
* Assign it as the first statement of the hook so every entry mints a fresh value:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* let suffix = ''
|
|
28
|
+
* test.beforeAll(async () => {
|
|
29
|
+
* suffix = randomSuffix()
|
|
30
|
+
* await insertRecord(`Example ${suffix}`, `example-${suffix}`)
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function randomSuffix(): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a short random suffix for unique-ID-style usage in Playwright tests.
|
|
4
|
+
* Use this instead of `Date.now()`, which can collide between parallel workers
|
|
5
|
+
* and which returns different values when called twice in the same test.
|
|
6
|
+
*
|
|
7
|
+
* The suffix is 12 lowercase hex characters (about 48 bits of entropy), which
|
|
8
|
+
* is plenty for slug/title/hostname uniqueness while remaining short and
|
|
9
|
+
* readable in CI logs and screenshots.
|
|
10
|
+
*
|
|
11
|
+
* Compute the suffix once per test and reuse it everywhere a related ID is
|
|
12
|
+
* needed (slug, name, hostname, etc.) so all values stay consistent:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const suffix = randomSuffix()
|
|
16
|
+
* await insertRecord(`Example ${suffix}`, `example-${suffix}`)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* If a `beforeAll` hook seeds data shared by a `describe` block (or a whole
|
|
20
|
+
* file), call `randomSuffix()` *inside* that hook, not at module/describe
|
|
21
|
+
* scope. Playwright's `fullyParallel` scheduler can hand a worker a second
|
|
22
|
+
* test from the same file, re-running `beforeAll` with module scope intact —
|
|
23
|
+
* a suffix hoisted outside the hook stays the same across that re-entry and
|
|
24
|
+
* produces the same slug/name twice, which throws on any unique column.
|
|
25
|
+
* Assign it as the first statement of the hook so every entry mints a fresh value:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* let suffix = ''
|
|
29
|
+
* test.beforeAll(async () => {
|
|
30
|
+
* suffix = randomSuffix()
|
|
31
|
+
* await insertRecord(`Example ${suffix}`, `example-${suffix}`)
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function randomSuffix() {
|
|
36
|
+
return randomUUID().replaceAll('-', '').slice(0, 12);
|
|
37
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const CONNECTION_RETRY_DEFAULT_BACKOFF_MS = 5000;
|
|
2
|
+
const CONNECTION_RETRY_DEFAULT_DURATION_MS = 55_000;
|
|
3
|
+
const CONNECTION_RETRY_MINIMUM_BACKOFF_MS = 50;
|
|
4
|
+
const CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE = 'connection retry budget exceeded';
|
|
5
|
+
function validateRetryInputs(backoffMs, maxDurationMs, maxRetries) {
|
|
6
|
+
if (!Number.isFinite(backoffMs) || backoffMs <= 0) {
|
|
7
|
+
throw new Error('connection retry backoffMs must be a finite number greater than 0');
|
|
8
|
+
}
|
|
9
|
+
if (!Number.isFinite(maxDurationMs) || maxDurationMs <= 0) {
|
|
10
|
+
throw new Error('connection retry maxDurationMs must be a finite number greater than 0');
|
|
11
|
+
}
|
|
12
|
+
if (maxRetries !== undefined &&
|
|
13
|
+
(!Number.isFinite(maxRetries) || maxRetries < 0 || !Number.isInteger(maxRetries))) {
|
|
14
|
+
throw new Error('connection retry maxRetries must be a finite non-negative integer');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function getDefaultMaxRetries(backoffMs, maxDurationMs) {
|
|
18
|
+
return Math.max(1, Math.ceil(maxDurationMs / backoffMs));
|
|
19
|
+
}
|
|
20
|
+
const CONNECTION_LOST_PATTERN = /\bERR_(CONNECTION_REFUSED|CONNECTION_RESET|CONNECTION_CLOSED|SOCKET_NOT_CONNECTED|NETWORK_CHANGED|EMPTY_RESPONSE|ABORTED|INCOMPLETE_CHUNKED_ENCODING)\b/i;
|
|
21
|
+
const NAVIGATION_TIMEOUT_PATTERN = /\bpage\.goto: Timeout \d+ms exceeded\b/;
|
|
22
|
+
function isLocalUrl(value) {
|
|
23
|
+
try {
|
|
24
|
+
const { hostname } = new URL(value);
|
|
25
|
+
const normalizedHostname = hostname.replace(/^\[(.*)]$/, '$1');
|
|
26
|
+
return ['', 'localhost', '127.0.0.1', '::1'].includes(normalizedHostname);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function isLocalNavigationTimeout(message) {
|
|
33
|
+
if (!NAVIGATION_TIMEOUT_PATTERN.test(message))
|
|
34
|
+
return false;
|
|
35
|
+
const navigatingMatch = message.match(/navigating to "([^"]+)"/);
|
|
36
|
+
const target = navigatingMatch?.[1];
|
|
37
|
+
return target !== undefined && isLocalUrl(target);
|
|
38
|
+
}
|
|
39
|
+
function isConnectionLostError(err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
return CONNECTION_LOST_PATTERN.test(message) || isLocalNavigationTimeout(message);
|
|
42
|
+
}
|
|
43
|
+
async function runWithDeadline(fn, deadlineMs) {
|
|
44
|
+
if (deadlineMs <= 0) {
|
|
45
|
+
throw new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE);
|
|
46
|
+
}
|
|
47
|
+
let timedOut = false;
|
|
48
|
+
let timerId;
|
|
49
|
+
const timeout = new Promise((_, reject) => {
|
|
50
|
+
timerId = setTimeout(() => {
|
|
51
|
+
timedOut = true;
|
|
52
|
+
reject(new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE));
|
|
53
|
+
}, deadlineMs);
|
|
54
|
+
});
|
|
55
|
+
let attempt;
|
|
56
|
+
try {
|
|
57
|
+
attempt = Promise.resolve().then(fn);
|
|
58
|
+
const result = await Promise.race([attempt, timeout]);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (timedOut && attempt) {
|
|
63
|
+
attempt.catch(() => undefined);
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
clearTimeout(timerId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Retries fn on transient network/worker errors matched by CONNECTION_LOST_PATTERN
|
|
72
|
+
// for a bounded recovery window, using configurable backoff sleeps and a total
|
|
73
|
+
// elapsed-time budget to absorb process restart windows, OS-level
|
|
74
|
+
// network changes (ERR_NETWORK_CHANGED), and related cold-start races.
|
|
75
|
+
export function retryOnConnectionLost(fn, options = {}) {
|
|
76
|
+
const backoffMs = options.backoffMs ?? CONNECTION_RETRY_DEFAULT_BACKOFF_MS;
|
|
77
|
+
const maxDurationMs = options.maxDurationMs ?? CONNECTION_RETRY_DEFAULT_DURATION_MS;
|
|
78
|
+
validateRetryInputs(backoffMs, maxDurationMs, options.maxRetries);
|
|
79
|
+
const effectiveBackoffMs = Math.max(CONNECTION_RETRY_MINIMUM_BACKOFF_MS, backoffMs);
|
|
80
|
+
const maxRetries = options.maxRetries ?? getDefaultMaxRetries(effectiveBackoffMs, maxDurationMs);
|
|
81
|
+
const deadline = Date.now() + maxDurationMs;
|
|
82
|
+
const retry = async (remainingRetries) => {
|
|
83
|
+
try {
|
|
84
|
+
return await runWithDeadline(fn, deadline - Date.now());
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (!isConnectionLostError(err) || remainingRetries <= 0)
|
|
88
|
+
throw err;
|
|
89
|
+
const remainingMs = Math.max(0, deadline - Date.now());
|
|
90
|
+
if (remainingMs <= 0)
|
|
91
|
+
throw err;
|
|
92
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(effectiveBackoffMs, remainingMs)));
|
|
93
|
+
if (Date.now() >= deadline) {
|
|
94
|
+
throw new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE, { cause: err });
|
|
95
|
+
}
|
|
96
|
+
return retry(remainingRetries - 1);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return retry(maxRetries).catch((err) => {
|
|
100
|
+
if (err instanceof Error && err.message === CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE) {
|
|
101
|
+
throw new Error(`retryOnConnectionLost: ${CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE}`, {
|
|
102
|
+
cause: err,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Trigger pagination with a real scroll gesture.
|
|
4
|
+
*
|
|
5
|
+
* The pagination control gates `onLoadMore` behind a one-shot window `scroll`
|
|
6
|
+
* listener plus IntersectionObserver, so this wheels a viewport at a time
|
|
7
|
+
* until the sentinel is on screen. Do not use `scrollIntoViewIfNeeded()`:
|
|
8
|
+
* it is a no-op on an already-visible element and emits no `scroll` event
|
|
9
|
+
* (`playwright-no-scroll-into-view-sentinel`).
|
|
10
|
+
*
|
|
11
|
+
* After the sentinel is in view, wait for below-fold hydration and issue a
|
|
12
|
+
* net-zero extra scroll so a deferred listener still sees a live event.
|
|
13
|
+
*
|
|
14
|
+
* Probe `count()` before `boundingBox()` and bound `boundingBox()` to
|
|
15
|
+
* {@link BOUNDING_BOX_TIMEOUT_MS} so a detached sentinel cannot consume the
|
|
16
|
+
* action timeout. The loop is also bounded by
|
|
17
|
+
* {@link SCROLL_LOOP_BUDGET_MS}; a detached attempt waits up to
|
|
18
|
+
* {@link DETACHED_REMOUNT_WAIT_MS} for remount.
|
|
19
|
+
*
|
|
20
|
+
* The pagination control unmounts the sentinel when `hasNextPage` becomes false.
|
|
21
|
+
* If this helper already saw the sentinel attached (typically below the fold)
|
|
22
|
+
* and it stays gone after that remount wait, pagination already loaded the
|
|
23
|
+
* last page. Treating that as failure flakes the scroll-gated specs.
|
|
24
|
+
*/
|
|
25
|
+
export declare function scrollToLoadMore(page: Page, { sentinelTestId }?: {
|
|
26
|
+
sentinelTestId?: string;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Force `main` to exceed the viewport height before hydration, so
|
|
30
|
+
* the pagination control's short-page escape hatch (which auto-loads when
|
|
31
|
+
* `document.documentElement.scrollHeight <= window.innerHeight`) cannot open
|
|
32
|
+
* the pagination gate on its own. Use this alongside `scrollToLoadMore(page)`
|
|
33
|
+
* so a scroll-triggered pagination test exercises the scroll-gated path
|
|
34
|
+
* deterministically rather than depending on whichever seeded content happens
|
|
35
|
+
* to render.
|
|
36
|
+
*/
|
|
37
|
+
export declare function forceMainScrollableBeforeHydration(page: Page): Promise<void>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { waitForBelowFoldHydration } from "./wait-for-hydration.mjs";
|
|
2
|
+
const SENTINEL_TEST_ID = 'infinite-scroll-sentinel';
|
|
3
|
+
const MAX_SCROLL_ATTEMPTS = 30;
|
|
4
|
+
const POST_HYDRATION_SCROLL_RETRIES = 3;
|
|
5
|
+
const BOUNDING_BOX_TIMEOUT_MS = 2_000;
|
|
6
|
+
const SCROLL_LOOP_BUDGET_MS = 10_000;
|
|
7
|
+
const DETACHED_REMOUNT_WAIT_MS = 1_000;
|
|
8
|
+
function readScrollTop(page) {
|
|
9
|
+
return page.evaluate(() => globalThis.document.scrollingElement?.scrollTop ?? 0);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Trigger pagination with a real scroll gesture.
|
|
13
|
+
*
|
|
14
|
+
* The pagination control gates `onLoadMore` behind a one-shot window `scroll`
|
|
15
|
+
* listener plus IntersectionObserver, so this wheels a viewport at a time
|
|
16
|
+
* until the sentinel is on screen. Do not use `scrollIntoViewIfNeeded()`:
|
|
17
|
+
* it is a no-op on an already-visible element and emits no `scroll` event
|
|
18
|
+
* (`playwright-no-scroll-into-view-sentinel`).
|
|
19
|
+
*
|
|
20
|
+
* After the sentinel is in view, wait for below-fold hydration and issue a
|
|
21
|
+
* net-zero extra scroll so a deferred listener still sees a live event.
|
|
22
|
+
*
|
|
23
|
+
* Probe `count()` before `boundingBox()` and bound `boundingBox()` to
|
|
24
|
+
* {@link BOUNDING_BOX_TIMEOUT_MS} so a detached sentinel cannot consume the
|
|
25
|
+
* action timeout. The loop is also bounded by
|
|
26
|
+
* {@link SCROLL_LOOP_BUDGET_MS}; a detached attempt waits up to
|
|
27
|
+
* {@link DETACHED_REMOUNT_WAIT_MS} for remount.
|
|
28
|
+
*
|
|
29
|
+
* The pagination control unmounts the sentinel when `hasNextPage` becomes false.
|
|
30
|
+
* If this helper already saw the sentinel attached (typically below the fold)
|
|
31
|
+
* and it stays gone after that remount wait, pagination already loaded the
|
|
32
|
+
* last page. Treating that as failure flakes the scroll-gated specs.
|
|
33
|
+
*/
|
|
34
|
+
export async function scrollToLoadMore(page, { sentinelTestId = SENTINEL_TEST_ID } = {}) {
|
|
35
|
+
const sentinel = page.getByTestId(sentinelTestId);
|
|
36
|
+
const viewport = page.viewportSize();
|
|
37
|
+
const centerX = (viewport?.width ?? 0) / 2;
|
|
38
|
+
const viewportHeight = viewport?.height ?? 0;
|
|
39
|
+
await page.mouse.move(centerX, viewportHeight / 2);
|
|
40
|
+
let sentinelInView = false;
|
|
41
|
+
let lastPageConsumedSentinel = false;
|
|
42
|
+
let sawSentinelAttached = false;
|
|
43
|
+
let lastCount = 0;
|
|
44
|
+
let lastBox = null;
|
|
45
|
+
const initialScrollTop = await readScrollTop(page);
|
|
46
|
+
const scrollTops = [initialScrollTop];
|
|
47
|
+
const attemptStates = [];
|
|
48
|
+
const loopDeadline = Date.now() + SCROLL_LOOP_BUDGET_MS;
|
|
49
|
+
for (let attempt = 0; attempt < MAX_SCROLL_ATTEMPTS && Date.now() < loopDeadline; attempt++) {
|
|
50
|
+
// oxlint-disable-next-line no-await-in-loop -- count() must resolve before deciding whether to probe further
|
|
51
|
+
lastCount = await sentinel.count();
|
|
52
|
+
if (lastCount > 0) {
|
|
53
|
+
sawSentinelAttached = true;
|
|
54
|
+
let boundingBoxTimedOut = false;
|
|
55
|
+
// oxlint-disable-next-line no-await-in-loop -- bounded so a count()/boundingBox() detach race can't consume the full action timeout
|
|
56
|
+
lastBox = await sentinel.boundingBox({ timeout: BOUNDING_BOX_TIMEOUT_MS }).catch(() => {
|
|
57
|
+
boundingBoxTimedOut = true;
|
|
58
|
+
return null;
|
|
59
|
+
});
|
|
60
|
+
if (lastBox && lastBox.y < viewportHeight) {
|
|
61
|
+
sentinelInView = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
attemptStates.push(lastBox ? 'below-fold' : boundingBoxTimedOut ? 'race-detach' : 'no-box');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
lastBox = null;
|
|
68
|
+
attemptStates.push('detached');
|
|
69
|
+
// oxlint-disable-next-line no-await-in-loop -- bounded wait gives a transient detach real time to remount
|
|
70
|
+
await sentinel
|
|
71
|
+
.waitFor({ state: 'attached', timeout: DETACHED_REMOUNT_WAIT_MS })
|
|
72
|
+
.catch(() => undefined);
|
|
73
|
+
// oxlint-disable-next-line no-await-in-loop -- remount vs last-page unmount must be distinguished before wheeling
|
|
74
|
+
lastCount = await sentinel.count();
|
|
75
|
+
if (lastCount > 0)
|
|
76
|
+
continue;
|
|
77
|
+
if (sawSentinelAttached) {
|
|
78
|
+
lastPageConsumedSentinel = true;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// oxlint-disable-next-line no-await-in-loop -- scrolling all at once would overshoot the sentinel
|
|
83
|
+
await page.mouse.wheel(0, viewportHeight);
|
|
84
|
+
// oxlint-disable-next-line no-await-in-loop -- records this attempt's post-wheel position for diagnosis
|
|
85
|
+
scrollTops.push(await readScrollTop(page));
|
|
86
|
+
}
|
|
87
|
+
if (!sentinelInView && !lastPageConsumedSentinel) {
|
|
88
|
+
const documentState = await page.evaluate(() => ({
|
|
89
|
+
scrollHeight: globalThis.document.documentElement.scrollHeight,
|
|
90
|
+
innerHeight: globalThis.window
|
|
91
|
+
.innerHeight,
|
|
92
|
+
}));
|
|
93
|
+
const documentScrolled = scrollTops.at(-1) > initialScrollTop;
|
|
94
|
+
const tally = {
|
|
95
|
+
detached: 0,
|
|
96
|
+
'race-detach': 0,
|
|
97
|
+
'no-box': 0,
|
|
98
|
+
'below-fold': 0,
|
|
99
|
+
};
|
|
100
|
+
for (const s of attemptStates)
|
|
101
|
+
tally[s] += 1;
|
|
102
|
+
const state = !documentScrolled
|
|
103
|
+
? `the document never scrolled despite ${attemptStates.length} wheel events ` +
|
|
104
|
+
`(scrollTop stayed at ${initialScrollTop}) — the wheel target may have landed on a ` +
|
|
105
|
+
`nested scroll container instead of the document`
|
|
106
|
+
: tally.detached === attemptStates.length
|
|
107
|
+
? `sentinel was detached from the DOM on every attempt (count()=0 all ` +
|
|
108
|
+
`${attemptStates.length} times) — it never (re)mounted during the scroll loop`
|
|
109
|
+
: `sentinel state varied across ${attemptStates.length} attempts: ` +
|
|
110
|
+
`${tally.detached} detached, ${tally['race-detach']} attached-but-boundingBox-timed-out, ` +
|
|
111
|
+
`${tally['no-box']} attached-but-invisible, ${tally['below-fold']} below-fold`;
|
|
112
|
+
throw new Error(`scrollToLoadMore: sentinel [data-testid="${sentinelTestId}"] did not enter the ` +
|
|
113
|
+
`viewport after ${attemptStates.length} scroll attempts: ${state}. ` +
|
|
114
|
+
`lastCount()=${lastCount}, lastBox=${JSON.stringify(lastBox)}, ` +
|
|
115
|
+
`scrollTop=${scrollTops[0]}->${scrollTops.at(-1)}, ` +
|
|
116
|
+
`documentScrollHeight=${documentState.scrollHeight}, windowInnerHeight=${documentState.innerHeight}`);
|
|
117
|
+
}
|
|
118
|
+
if (!sentinelInView)
|
|
119
|
+
return;
|
|
120
|
+
for (let retry = 0; retry < POST_HYDRATION_SCROLL_RETRIES; retry++) {
|
|
121
|
+
// oxlint-disable-next-line no-await-in-loop -- each retry must wait for hydration to catch up first
|
|
122
|
+
await waitForBelowFoldHydration(page);
|
|
123
|
+
// oxlint-disable-next-line no-await-in-loop -- must complete before the wheel-forward below
|
|
124
|
+
await page.mouse.wheel(0, -50);
|
|
125
|
+
// oxlint-disable-next-line no-await-in-loop -- closes the net-zero scroll pair for this retry
|
|
126
|
+
await page.mouse.wheel(0, 50);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Force `main` to exceed the viewport height before hydration, so
|
|
131
|
+
* the pagination control's short-page escape hatch (which auto-loads when
|
|
132
|
+
* `document.documentElement.scrollHeight <= window.innerHeight`) cannot open
|
|
133
|
+
* the pagination gate on its own. Use this alongside `scrollToLoadMore(page)`
|
|
134
|
+
* so a scroll-triggered pagination test exercises the scroll-gated path
|
|
135
|
+
* deterministically rather than depending on whichever seeded content happens
|
|
136
|
+
* to render.
|
|
137
|
+
*/
|
|
138
|
+
export async function forceMainScrollableBeforeHydration(page) {
|
|
139
|
+
await page.addInitScript(() => {
|
|
140
|
+
const styleId = 'pw-force-scrollable-main';
|
|
141
|
+
const document = globalThis.document;
|
|
142
|
+
const installStyle = () => {
|
|
143
|
+
if (document.getElementById(styleId))
|
|
144
|
+
return;
|
|
145
|
+
const styleRoot = document.head ?? document.documentElement;
|
|
146
|
+
if (!styleRoot)
|
|
147
|
+
return;
|
|
148
|
+
const style = document.createElement('style');
|
|
149
|
+
style.id = styleId;
|
|
150
|
+
style.textContent = 'main { min-height: 180vh !important; }';
|
|
151
|
+
styleRoot.append(style);
|
|
152
|
+
};
|
|
153
|
+
if (document.readyState === 'loading') {
|
|
154
|
+
document.addEventListener('DOMContentLoaded', installStyle, { once: true });
|
|
155
|
+
}
|
|
156
|
+
installStyle();
|
|
157
|
+
});
|
|
158
|
+
}
|