ccqa 0.4.0 → 0.5.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/dist/package.json
CHANGED
|
@@ -4,9 +4,9 @@ declare function ab(...args: string[]): void;
|
|
|
4
4
|
declare function abWait(selector: string, timeoutMs?: number): void;
|
|
5
5
|
/** Assert stable text is visible on page (via wait --text). */
|
|
6
6
|
declare function abAssertTextVisible(text: string, timeoutMs?: number): void;
|
|
7
|
-
/** Assert element is visible (
|
|
7
|
+
/** Assert element is visible (polls `get count`; never uses the blocking `wait <selector>`). */
|
|
8
8
|
declare function abAssertVisible(selector: string, timeoutMs?: number): void;
|
|
9
|
-
/** Assert element is NOT visible (
|
|
9
|
+
/** Assert element is NOT visible (polls `get count` for absence; --fn for text). */
|
|
10
10
|
declare function abAssertNotVisible(selector: string, timeoutMs?: number): void;
|
|
11
11
|
/** Assert URL contains a pattern (via get url). */
|
|
12
12
|
declare function abAssertUrl(pattern: string): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as spawnAB, t as sleepSync } from "../spawn-ab-
|
|
1
|
+
import { n as spawnAB, t as sleepSync } from "../spawn-ab-DjRh1-4T.mjs";
|
|
2
2
|
//#region src/runtime/test-helpers.ts
|
|
3
3
|
const POST_OPEN_SETTLE_MS = 600;
|
|
4
4
|
function logStep(action, args) {
|
|
@@ -18,22 +18,50 @@ function ab(...args) {
|
|
|
18
18
|
if (result.status !== 0) fail(`agent-browser ${command} failed (exit ${result.status})`, result);
|
|
19
19
|
if (command === "open") sleepSync(POST_OPEN_SETTLE_MS);
|
|
20
20
|
}
|
|
21
|
+
const SELECTOR_POLL_INTERVAL_MS = 500;
|
|
22
|
+
function selectorCount(selector) {
|
|
23
|
+
const r = spawnAB([
|
|
24
|
+
"get",
|
|
25
|
+
"count",
|
|
26
|
+
selector
|
|
27
|
+
]);
|
|
28
|
+
if (r.status !== 0) return 0;
|
|
29
|
+
const n = Number.parseInt(r.stdout.trim(), 10);
|
|
30
|
+
return Number.isNaN(n) ? 0 : n;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Poll until `get count <selector>` reaches the desired presence state or the
|
|
34
|
+
* timeout elapses. `want: "present"` waits for >=1 match; `"absent"` waits for
|
|
35
|
+
* 0 matches. Returns true on success, false on timeout.
|
|
36
|
+
*/
|
|
37
|
+
function pollSelector(selector, want, timeoutMs) {
|
|
38
|
+
const deadline = Date.now() + timeoutMs;
|
|
39
|
+
for (;;) {
|
|
40
|
+
const count = selectorCount(selector);
|
|
41
|
+
if (want === "present" ? count > 0 : count === 0) return true;
|
|
42
|
+
if (Date.now() >= deadline) return false;
|
|
43
|
+
sleepSync(SELECTOR_POLL_INTERVAL_MS);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
21
46
|
/** Wait for element/text with an explicit timeout so long-running async ops don't hang. */
|
|
22
|
-
function abWait(selector, timeoutMs =
|
|
47
|
+
function abWait(selector, timeoutMs = 3e4) {
|
|
23
48
|
logStep("wait", [selector]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
selector
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
if (selector.startsWith("text=")) {
|
|
50
|
+
const result = spawnAB([
|
|
51
|
+
"wait",
|
|
52
|
+
"--text",
|
|
53
|
+
selector.slice(5),
|
|
54
|
+
"--timeout",
|
|
55
|
+
String(timeoutMs)
|
|
56
|
+
]);
|
|
57
|
+
if (result.status !== 0) fail(`wait failed: ${selector}`, result);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!pollSelector(selector, "present", timeoutMs)) fail(`wait failed: ${selector} not present within ${timeoutMs}ms`, {
|
|
61
|
+
status: 1,
|
|
62
|
+
stdout: "",
|
|
63
|
+
stderr: ""
|
|
64
|
+
});
|
|
37
65
|
}
|
|
38
66
|
/** Assert stable text is visible on page (via wait --text). */
|
|
39
67
|
function abAssertTextVisible(text, timeoutMs = 3e4) {
|
|
@@ -47,35 +75,45 @@ function abAssertTextVisible(text, timeoutMs = 3e4) {
|
|
|
47
75
|
]);
|
|
48
76
|
if (result.status !== 0) fail(`Assertion failed: text ${JSON.stringify(text)} not found within ${timeoutMs}ms`, result);
|
|
49
77
|
}
|
|
50
|
-
/** Assert element is visible (
|
|
78
|
+
/** Assert element is visible (polls `get count`; never uses the blocking `wait <selector>`). */
|
|
51
79
|
function abAssertVisible(selector, timeoutMs = 3e4) {
|
|
52
80
|
logStep("assert.visible", [selector]);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
if (selector.startsWith("text=")) {
|
|
82
|
+
const result = spawnAB([
|
|
83
|
+
"wait",
|
|
84
|
+
"--text",
|
|
85
|
+
selector.slice(5),
|
|
86
|
+
"--timeout",
|
|
87
|
+
String(timeoutMs)
|
|
88
|
+
]);
|
|
89
|
+
if (result.status !== 0) fail(`Assertion failed: ${JSON.stringify(selector)} not visible within ${timeoutMs}ms`, result);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!pollSelector(selector, "present", timeoutMs)) fail(`Assertion failed: ${JSON.stringify(selector)} not visible within ${timeoutMs}ms`, {
|
|
93
|
+
status: 1,
|
|
94
|
+
stdout: "",
|
|
95
|
+
stderr: ""
|
|
96
|
+
});
|
|
60
97
|
}
|
|
61
|
-
/** Assert element is NOT visible (
|
|
98
|
+
/** Assert element is NOT visible (polls `get count` for absence; --fn for text). */
|
|
62
99
|
function abAssertNotVisible(selector, timeoutMs = 3e4) {
|
|
63
100
|
logStep("assert.hidden", [selector]);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
selector
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
if (selector.startsWith("text=")) {
|
|
102
|
+
const result = spawnAB([
|
|
103
|
+
"wait",
|
|
104
|
+
"--fn",
|
|
105
|
+
`!document.body.innerText.includes(${JSON.stringify(selector.slice(5))})`,
|
|
106
|
+
"--timeout",
|
|
107
|
+
String(timeoutMs)
|
|
108
|
+
]);
|
|
109
|
+
if (result.status !== 0) fail(`Assertion failed: ${JSON.stringify(selector)} still visible after ${timeoutMs}ms`, result);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!pollSelector(selector, "absent", timeoutMs)) fail(`Assertion failed: ${JSON.stringify(selector)} still visible after ${timeoutMs}ms`, {
|
|
113
|
+
status: 1,
|
|
114
|
+
stdout: "",
|
|
115
|
+
stderr: ""
|
|
116
|
+
});
|
|
79
117
|
}
|
|
80
118
|
/** Assert URL contains a pattern (via get url). */
|
|
81
119
|
function abAssertUrl(pattern) {
|