@unotest/web 0.54.0 → 0.55.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.
@@ -639,7 +639,10 @@ assertTrue(probe.code == 0, 'app.log should contain "ready"');
639
639
  Deep equality, the way JSON sees the two values: key order does not
640
640
  count, and a missing key differs from a key set to `null`. The failure
641
641
  names the first path that differs and both values, then a line diff of
642
- the two sides, every line of them — nothing is folded away:
642
+ the two sides, every line of them — nothing is folded away. A value
643
+ nested deeper than 1000 levels is refused by name (the test is
644
+ errored: `assertEqual: value nested deeper than 1000 levels`), as by
645
+ every DSL function:
643
646
 
644
647
  ```js
645
648
  const body = parseJson(getAttribute(locator('#state'), 'data-json'));
@@ -751,7 +754,9 @@ Semantics:
751
754
  CLI session), `vertex` uses ADC via
752
755
  `GOOGLE_CLOUD_PROJECT`/`GOOGLE_CLOUD_LOCATION`, the rest take the
753
756
  vendor-standard key vars (`GEMINI_API_KEY`, `OPENAI_API_KEY`,
754
- `ANTHROPIC_API_KEY`) — see the `@unotest/judge` README. Unconfigured
757
+ `ANTHROPIC_API_KEY`) — see the `@unotest/judge` README. In `local`
758
+ mode the key goes in `unotest/.secrets` (or `.secrets.<env>`); an
759
+ exported variable wins over the file. Unconfigured
755
760
  (`off`) → the step fails with the setup message; a judge assert is
756
761
  never silently skipped.
757
762
  - The judged text is the element's **rendered** text (`innerText`): line
@@ -1871,7 +1876,18 @@ Semantics:
1871
1876
  - **Env**: the child inherits the runner's `process.env` (which includes
1872
1877
  `unotest/.env` layers). Secrets from `.secrets*` are **not** inherited;
1873
1878
  export them explicitly via the `sandbox.exportSecrets` allowlist
1874
- (values stay masked in logs).
1879
+ (values stay masked in logs). The runner's own credentials
1880
+ (`UNOTEST_CLOUD_TOKEN`, the judge's and the grounder's keys) are
1881
+ dropped from the child's env as well.
1882
+ - **Rights**: the child runs with the rights of the account that runs
1883
+ the suite. Exported keys and key files are visible to it. Dropping
1884
+ names from its env keeps them out of an accidental `printenv` and out
1885
+ of logs; it is not a wall — the same command can read your files
1886
+ (`unotest/.secrets`, the cloud sign-in in `~/.config/unotest/`) and the
1887
+ environment your shell exported (for example through the parent
1888
+ process). Do not run a suite you do not trust from a shell that
1889
+ exports a key; on a box a run's container holds none of the box's
1890
+ tokens.
1875
1891
 
1876
1892
  ```js
1877
1893
  const out = shell('pnpm', 'db:create-user', 'alice'); // non-zero exit → step fails
@@ -2559,6 +2575,59 @@ assertTrue(req.postDataJson.text == 'hello', 'sent: ' + req.postData);
2559
2575
  - `{timeoutMs}` — default 20 000.
2560
2576
  - A `ws://` or `wss://` mask is refused: a WebSocket is no request.
2561
2577
 
2578
+ ### `waitForResponse(glob, options?)` → `{url, method, status, ok, headers, json, text}`
2579
+
2580
+ Waits for the answer to a request matching `glob` and returns it. Use it
2581
+ when what the test checks comes only with the answer — an element drawn
2582
+ from it, or one that must not be.
2583
+
2584
+ ```js
2585
+ click(getByRole('button', { name: 'Load' }));
2586
+ const res = waitForResponse('**/api/items', { status: 200 });
2587
+ assertEqual(res.json.items.length, 0);
2588
+ assertHidden(getByTestId('item'));
2589
+ ```
2590
+
2591
+ - **Which request.** Those sent from the start of the last call that
2592
+ acted on the page: `click`, `fill`, `press`, `check`, `hover`,
2593
+ `selectOption`, `goto`, `reload`, `evaluate`, `clockTick` and the
2594
+ like. A `log`, a `note`, an assertion or another wait in between moves
2595
+ nothing. The same GET the page made as it loaded is not taken after a
2596
+ later click.
2597
+ - **An answer that came before the call is found**: the page's requests
2598
+ are recorded all along, there is no race with a fast server.
2599
+ - Of those, the one sent first that no earlier `waitForResponse`
2600
+ returned: two waits on one mask take two answers.
2601
+ - `{status}` — only that status; others are passed over and named in
2602
+ the timeout. `{method}` — only that method, any case.
2603
+ - A request that failed (refused, aborted by `mockRoute`) is no answer.
2604
+ A `mockRoute` answer is one, with `mocked: true`; `{continue: true}`
2605
+ gives the network's.
2606
+ - `{since}` — epoch ms from `nowMs()`: requests sent from then on, in
2607
+ place of the last page action. Needed when another action came
2608
+ between the one that sent the request and the wait:
2609
+
2610
+ ```js
2611
+ const before = nowMs();
2612
+ click(getByRole('button', { name: 'Load' }));
2613
+ hover(getByRole('menu'));
2614
+ waitForResponse('**/api/items', { since: before });
2615
+ ```
2616
+
2617
+ Without `{since}` that wait looks from the `hover` on and times out;
2618
+ the timeout says so.
2619
+ - `headers` — the response's, names in lower case. `json` — the body
2620
+ read as JSON, `null` when it is not JSON, was not read or was cut.
2621
+ `text` — the body of a text or JSON content type, `null` otherwise.
2622
+ Bodies are read for `fetch` and `xhr`, at most 64 KB; a longer one has
2623
+ `truncated: true`. Documents and images have status and headers only.
2624
+ - `{timeoutMs}` — default 20 000. A timeout fails the test and quotes the
2625
+ answers on the mask it passed over and why.
2626
+ - The answer is in, not yet drawn: the page renders after it. To show an
2627
+ element never appears, follow with
2628
+ `assertNeverAppears(locator, { withinMs })`.
2629
+ - A `ws://` or `wss://` mask is refused: use `waitForWebSocket`.
2630
+
2562
2631
  ### `waitForWebSocket(glob, options?)` → `{url}`
2563
2632
 
2564
2633
  Waits until the active page has opened a WebSocket whose URL matches
@@ -3454,12 +3523,12 @@ assertTrue(consoleEntries({ level: ['warn', 'error'], since: before }).length ==
3454
3523
  `console.json` holds the lines of every browser context, each with its
3455
3524
  `contextIndex`, the last 500 by time.
3456
3525
 
3457
- ### `networkEntries(options?)` → `[{ url, method, status, ok, requestJson, responseJson, responseText, at }]`
3526
+ ### `networkEntries(options?)` → `[{ url, method, status, ok, headers, requestJson, responseJson, responseText, at }]`
3458
3527
 
3459
3528
  What the active page requested and was answered, oldest first. Like the
3460
3529
  console, it is recorded from the moment the page opened, so the usual
3461
3530
  order works: act, then ask. A response is entered when it finishes, so
3462
- wait for it.
3531
+ wait for it — `waitForResponse` waits for one.
3463
3532
 
3464
3533
  ```js
3465
3534
  click(getByRole('button', { name: 'Verify' }));
@@ -3472,6 +3541,8 @@ assertEqual(answer.responseJson.kind, 'mobile');
3472
3541
  - `status` / `ok` — the response; a request that failed before any
3473
3542
  response (refused, aborted) has `status` 0, `ok` false and
3474
3543
  `failureText`.
3544
+ - `headers` — the response's, names in lower case; empty for a request
3545
+ that failed.
3475
3546
  - `mocked` — `true` when a `mockRoute` answered or aborted it.
3476
3547
  - Bodies are read for `fetch` and `xhr` requests with a text or JSON
3477
3548
  content type, at most 64 KB each; a longer one is cut, `truncated` is
@@ -3531,7 +3602,10 @@ Writes one line to the runner's output (the terminal, the live System
3531
3602
  pane in the viewer) **and** to the run journal (`steps.jsonl`, as a
3532
3603
  `log` event under the current step), so a finished run still shows it
3533
3604
  under the step that wrote it and in the System pane. Non-string args
3534
- are `JSON.stringify`'d.
3605
+ are `JSON.stringify`'d. An arg nested deeper than 1000 levels is
3606
+ refused by name, as by every DSL function: `log: value nested deeper
3607
+ than 1000 levels`, and the test is errored. The Vars view shows such a
3608
+ value cut at that depth, marked `…`.
3535
3609
 
3536
3610
  ```js
3537
3611
  log('user id:', userId);
@@ -3763,6 +3837,7 @@ per option; an older spelling it still takes is named after the line.
3763
3837
  - `mockRoute(glob: string, response: any): void`
3764
3838
  - `unmockRoute(glob?: string): void`
3765
3839
  - `waitForRequest(glob: string, options?: { timeoutMs?: number }): any`
3840
+ - `waitForResponse(glob: string, options?: { status?: number; method?: string; since?: number; timeoutMs?: number }): any`
3766
3841
  - `waitForWebSocket(glob: string, options?: { timeoutMs?: number }): any`
3767
3842
  - `networkEntries(options?: { since?: number; glob?: any }): any`
3768
3843
  - `assertNoRequest(glob: string, options?: { since?: number }): void`
package/llms.txt CHANGED
@@ -180,8 +180,9 @@ Full reference: https://docs.unotest.com/reference/dsl/
180
180
  - `mockRoute(glob, response)` · since 0.45.0 — From now on, requests matching `glob` (a Playwright URL glob: `**/api/items*`) get a fixed answer: `{status?, body?, headers?, contentType?}` (an object body goes as JSON), `{abort: true, record?}` or `{continue: true}` (to the network).
181
181
  - `unmockRoute(glob?)` · since 0.45.0 — Take off the mock at `glob`, or every mock when called without one.
182
182
  - `waitForRequest(glob, { timeoutMs? }) → { url, method, headers, postData, postDataJson }` · options `{timeoutMs?}` · since 0.45.0 — Wait for a request matching `glob` and return it; `postDataJson` is the body read as JSON (null when it is not).
183
+ - `waitForResponse(glob, { status?, method?, since?, timeoutMs? }) → { url, method, status, ok, headers, json, text, truncated?, mocked? }` · options `{status?, method?, since?, timeoutMs?}` · since 0.55.0 — Wait for the answer to a request matching `glob` and return it: `headers` of the response (names in lower case), `json` (null when the body is not JSON, was not read or was cut), `text` (text or JSON bodies of `fetch` / `xhr`, at most 64 KB, then `truncated`).
183
184
  - `waitForWebSocket(glob, { timeoutMs? }) → { url }` · options `{timeoutMs?}` · since 0.51.0 — Wait until the active page has opened a WebSocket whose URL matches `glob` (a Playwright URL glob: `**/ws`, `ws://localhost:*/live`) and return its URL.
184
- - `networkEntries({ since?, glob? }) → [{ url, method, status, ok, failureText?, mocked?, requestJson, responseJson, responseText, truncated?, at }]` · options `{since?, glob?}` · since 0.53.0 — What the active page requested and was answered, oldest first: the status and, for `fetch` / `xhr` with a text or JSON content type, the bodies (`requestJson` as `postDataJson` of `waitForRequest`; `responseJson` is null when the body is not JSON; at most 64 KB each, then `truncated`).
185
+ - `networkEntries({ since?, glob? }) → [{ url, method, status, ok, headers, failureText?, mocked?, requestJson, responseJson, responseText, truncated?, at }]` · options `{since?, glob?}` · since 0.53.0 — What the active page requested and was answered, oldest first: the status and, for `fetch` / `xhr` with a text or JSON content type, the bodies (`requestJson` as `postDataJson` of `waitForRequest`; `responseJson` is null when the body is not JSON; at most 64 KB each, then `truncated`).
185
186
  - `assertNoRequest(glob, { since? })` · options `{since?}` · since 0.45.0 — FAIL if the recording abort at `glob` — mockRoute(glob, {abort: true, record: true}) — stopped any request; with `since` (epoch ms, from nowMs()) only from then on.
186
187
  - `openTerminal(app?, { host?, leaveOpen?, env?, cwd?, shell?, cols?, rows?, term?, locale?, cleanProfile? }) → number` · options `{host?, leaveOpen?, env?, cwd?, shell?, cols?, rows?, term?, locale?, cleanProfile?}` · since 0.51.0 — Open a terminal and make it the one the terminal steps act on; returns its index for setTerminal.
187
188
  - `setTerminal(index)` · since 0.51.0 — Make the terminal `index` (from openTerminal) the one the terminal steps act on.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unotest/web",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "AI-native E2E testing for web applications. MCP server (run_test / step / resume / inspect_runtime / agent_fix) + CLI runner + JavaScript DSL scenarios on a sandboxed AST engine + semantic DOM snapshots.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -88,11 +88,11 @@
88
88
  "tsx": "^4.19.2",
89
89
  "yaml": "^2.6.0",
90
90
  "zod": "^3.23.8",
91
- "@unotest/core": "^0.54.0",
92
- "@unotest/dsl": "^0.54.0",
93
- "@unotest/protocol": "^0.54.0",
94
- "@unotest/viewer": "^0.54.0",
95
- "@unotest/grounder-client": "^0.54.0"
91
+ "@unotest/grounder-client": "^0.55.0",
92
+ "@unotest/core": "^0.55.0",
93
+ "@unotest/protocol": "^0.55.0",
94
+ "@unotest/viewer": "^0.55.0",
95
+ "@unotest/dsl": "^0.55.0"
96
96
  },
97
97
  "optionalDependencies": {
98
98
  "node-pty": "1.2.0-beta.15"
@@ -102,8 +102,8 @@
102
102
  "javascript-obfuscator": "^4.1.1",
103
103
  "tsup": "^8.5.1",
104
104
  "typescript": "^5.7.2",
105
- "@unotest/judge": "^0.54.0",
106
- "@unotest/grounder": "^0.54.0"
105
+ "@unotest/grounder": "^0.55.0",
106
+ "@unotest/judge": "^0.55.0"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "typescript": ">=5.0.0 <7"
@@ -1106,6 +1106,13 @@ declare function unmockRoute(glob?: string): void;
1106
1106
  */
1107
1107
  declare function waitForRequest(glob: string, options?: { timeoutMs?: number }): any;
1108
1108
 
1109
+ /**
1110
+ * waitForResponse(glob, { status?, method?, since?, timeoutMs? }) → { url, method, status, ok, headers, json, text, truncated?, mocked? }
1111
+ *
1112
+ * Wait for the answer to a request matching `glob` and return it: `headers` of the response (names in lower case), `json` (null when the body is not JSON, was not read or was cut), `text` (text or JSON bodies of `fetch` / `xhr`, at most 64 KB, then `truncated`). It looks at requests sent from the start of the last call that acted on the page (a click, fill, press, goto, evaluate…); a log, a note or an assertion in between moves nothing, and an answer that came before the call is found. Of those, the one sent first that no earlier waitForResponse returned. `{status}` skips other statuses, `{method}` other methods; a request that failed is no answer. `{since}` (epoch ms from nowMs()) sets the start instead — needed when another action came between the one that sent the request and the wait. A timeout fails the test and names the answers it passed over. The answer is in, not drawn: for "never appears" follow with assertNeverAppears. Default timeout 20 s.
1113
+ */
1114
+ declare function waitForResponse(glob: string, options?: { status?: number; method?: string; since?: number; timeoutMs?: number }): any;
1115
+
1109
1116
  /**
1110
1117
  * waitForWebSocket(glob, { timeoutMs? }) → { url }
1111
1118
  *
@@ -1114,9 +1121,9 @@ declare function waitForRequest(glob: string, options?: { timeoutMs?: number }):
1114
1121
  declare function waitForWebSocket(glob: string, options?: { timeoutMs?: number }): any;
1115
1122
 
1116
1123
  /**
1117
- * networkEntries({ since?, glob? }) → [{ url, method, status, ok, failureText?, mocked?, requestJson, responseJson, responseText, truncated?, at }]
1124
+ * networkEntries({ since?, glob? }) → [{ url, method, status, ok, headers, failureText?, mocked?, requestJson, responseJson, responseText, truncated?, at }]
1118
1125
  *
1119
- * What the active page requested and was answered, oldest first: the status and, for `fetch` / `xhr` with a text or JSON content type, the bodies (`requestJson` as `postDataJson` of `waitForRequest`; `responseJson` is null when the body is not JSON; at most 64 KB each, then `truncated`). Other resources have a status only; a request that failed has status 0 and `failureText`. Recorded from the moment the page opened, but a response is entered when it finishes, so wait for it. options: {since} (epoch ms of sending, from nowMs()), {glob} (a mask; one starting with `/` is read on the site's origin).
1126
+ * What the active page requested and was answered, oldest first: the status and, for `fetch` / `xhr` with a text or JSON content type, the bodies (`requestJson` as `postDataJson` of `waitForRequest`; `responseJson` is null when the body is not JSON; at most 64 KB each, then `truncated`). Other resources have a status only; `headers` are the response's (names in lower case, empty for a request that failed); a request that failed has status 0 and `failureText`. Recorded from the moment the page opened, but a response is entered when it finishes, so wait for it. options: {since} (epoch ms of sending, from nowMs()), {glob} (a mask; one starting with `/` is read on the site's origin).
1120
1127
  */
1121
1128
  declare function networkEntries(options?: { since?: number; glob?: any }): any;
1122
1129