@specific.dev/spectest 0.35.0 → 0.35.1
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/index.d.ts +37 -10
- package/dist/index.js +37 -10
- package/dist/inspect.d.ts +8 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1390,16 +1390,43 @@ export declare function expect(actual: Locator, message?: string): LocatorAssert
|
|
|
1390
1390
|
export declare function expect(actual: Browser, message?: string): BrowserAssertion;
|
|
1391
1391
|
export declare function expect(actual: Provenanced, message?: string): Expectation;
|
|
1392
1392
|
/**
|
|
1393
|
-
* Assert on a value with **no provenance** — a computed number, a
|
|
1394
|
-
* WebSocket
|
|
1395
|
-
* required (it's the second argument) and reads as
|
|
1396
|
-
* "assert …" (e.g.
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1393
|
+
* Assert on a value with **no provenance** — a computed number, a frame read
|
|
1394
|
+
* off a raw `WebSocket` you opened yourself, anything that never flowed from a
|
|
1395
|
+
* recorded op. `message` is required (it's the second argument) and reads as
|
|
1396
|
+
* the natural follow-on to "assert …" (e.g.
|
|
1397
|
+
* `expectRaw(id, "id matches the generated value")`); it renders as the
|
|
1398
|
+
* assertion's label in the CLI/dashboard ("ASSERT <message>") since a raw
|
|
1399
|
+
* assertion has no op to nest under. (`expect`'s own `message` is optional;
|
|
1400
|
+
* here it is mandatory, since the label is the only human-meaningful summary a
|
|
1401
|
+
* raw assertion has.)
|
|
1402
|
+
*
|
|
1403
|
+
* **This is an escape hatch, and reaching for it is almost always a mistake.**
|
|
1404
|
+
* A raw assertion is *deliberately* unlinked: it renders as a disconnected
|
|
1405
|
+
* top-level row with no op above it, so whoever reads the failure can't see the
|
|
1406
|
+
* request, query, or command the value came from. Using it to get past
|
|
1407
|
+
* `expect`'s compile-time provenance gate is an anti-pattern — the gate rejects
|
|
1408
|
+
* a value precisely because its provenance was destroyed on the way in, and
|
|
1409
|
+
* this doesn't restore it, it just accepts the loss.
|
|
1410
|
+
*
|
|
1411
|
+
* Nearly every real use is a *wrapped* value that got flattened by `.unwrap()`,
|
|
1412
|
+
* `String(x)`, `JSON.parse(x)`, `x.length`, or a home-grown coercion helper.
|
|
1413
|
+
* Keep it wrapped instead:
|
|
1414
|
+
*
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* // ✗ flattened, then asserted raw — the link to the op is gone
|
|
1417
|
+
* expectRaw(JSON.parse(res.body.unwrap()).tier, "tier is pro").toBe("pro");
|
|
1418
|
+
* expectRaw(rows.length, "one row").toBe(1);
|
|
1419
|
+
*
|
|
1420
|
+
* // ✓ same checks, still nested under the http / db step
|
|
1421
|
+
* expect(res.body.transform<{ tier: string }>("json", (s) => JSON.parse(s)).tier).toBe("pro");
|
|
1422
|
+
* expect(rows).toHaveLength(1);
|
|
1423
|
+
* ```
|
|
1424
|
+
*
|
|
1425
|
+
* `.transform(label, fn)` carries the source op's tag through a decode,
|
|
1426
|
+
* `toHaveLength` reads a length without severing it, and a nullish leaf read
|
|
1427
|
+
* inline in `expect(...)` (or via `field`) recovers its own tag. If the value
|
|
1428
|
+
* came from a `fetch`/db/exec/browser/fake/kube op at any point, there is a
|
|
1429
|
+
* wrapped way to assert on it — see the `/tests` docs page.
|
|
1403
1430
|
*/
|
|
1404
1431
|
export declare function expectRaw(actual: unknown, message: string): Expectation;
|
|
1405
1432
|
/** `node:assert/strict` re-exported for users who prefer Node's built-in API. */
|
package/dist/index.js
CHANGED
|
@@ -657,16 +657,43 @@ function buildBrowserMatchers(session, negated, message) {
|
|
|
657
657
|
};
|
|
658
658
|
}
|
|
659
659
|
/**
|
|
660
|
-
* Assert on a value with **no provenance** — a computed number, a
|
|
661
|
-
* WebSocket
|
|
662
|
-
* required (it's the second argument) and reads as
|
|
663
|
-
* "assert …" (e.g.
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
660
|
+
* Assert on a value with **no provenance** — a computed number, a frame read
|
|
661
|
+
* off a raw `WebSocket` you opened yourself, anything that never flowed from a
|
|
662
|
+
* recorded op. `message` is required (it's the second argument) and reads as
|
|
663
|
+
* the natural follow-on to "assert …" (e.g.
|
|
664
|
+
* `expectRaw(id, "id matches the generated value")`); it renders as the
|
|
665
|
+
* assertion's label in the CLI/dashboard ("ASSERT <message>") since a raw
|
|
666
|
+
* assertion has no op to nest under. (`expect`'s own `message` is optional;
|
|
667
|
+
* here it is mandatory, since the label is the only human-meaningful summary a
|
|
668
|
+
* raw assertion has.)
|
|
669
|
+
*
|
|
670
|
+
* **This is an escape hatch, and reaching for it is almost always a mistake.**
|
|
671
|
+
* A raw assertion is *deliberately* unlinked: it renders as a disconnected
|
|
672
|
+
* top-level row with no op above it, so whoever reads the failure can't see the
|
|
673
|
+
* request, query, or command the value came from. Using it to get past
|
|
674
|
+
* `expect`'s compile-time provenance gate is an anti-pattern — the gate rejects
|
|
675
|
+
* a value precisely because its provenance was destroyed on the way in, and
|
|
676
|
+
* this doesn't restore it, it just accepts the loss.
|
|
677
|
+
*
|
|
678
|
+
* Nearly every real use is a *wrapped* value that got flattened by `.unwrap()`,
|
|
679
|
+
* `String(x)`, `JSON.parse(x)`, `x.length`, or a home-grown coercion helper.
|
|
680
|
+
* Keep it wrapped instead:
|
|
681
|
+
*
|
|
682
|
+
* ```ts
|
|
683
|
+
* // ✗ flattened, then asserted raw — the link to the op is gone
|
|
684
|
+
* expectRaw(JSON.parse(res.body.unwrap()).tier, "tier is pro").toBe("pro");
|
|
685
|
+
* expectRaw(rows.length, "one row").toBe(1);
|
|
686
|
+
*
|
|
687
|
+
* // ✓ same checks, still nested under the http / db step
|
|
688
|
+
* expect(res.body.transform<{ tier: string }>("json", (s) => JSON.parse(s)).tier).toBe("pro");
|
|
689
|
+
* expect(rows).toHaveLength(1);
|
|
690
|
+
* ```
|
|
691
|
+
*
|
|
692
|
+
* `.transform(label, fn)` carries the source op's tag through a decode,
|
|
693
|
+
* `toHaveLength` reads a length without severing it, and a nullish leaf read
|
|
694
|
+
* inline in `expect(...)` (or via `field`) recovers its own tag. If the value
|
|
695
|
+
* came from a `fetch`/db/exec/browser/fake/kube op at any point, there is a
|
|
696
|
+
* wrapped way to assert on it — see the `/tests` docs page.
|
|
670
697
|
*/
|
|
671
698
|
export function expectRaw(actual, message) {
|
|
672
699
|
// Force the raw form so no stray tag is read even if a wrapped value is
|
package/dist/inspect.d.ts
CHANGED
|
@@ -106,8 +106,14 @@ export interface Carrier<T> {
|
|
|
106
106
|
* `null`/`undefined` are also admitted: a nullish leaf can't carry the symbol
|
|
107
107
|
* tag, but `adoptNullishTag` recovers its provenance at runtime, so
|
|
108
108
|
* `expect(rows[0]?.text)` and `expect(dep.status.readyReplicas)` stay on
|
|
109
|
-
* `expect`.
|
|
110
|
-
*
|
|
109
|
+
* `expect`.
|
|
110
|
+
*
|
|
111
|
+
* When this gate rejects a value, the fix is usually to stop flattening it —
|
|
112
|
+
* `.transform(label, fn)` instead of a decode-then-`.unwrap()`, `toHaveLength`
|
|
113
|
+
* instead of `.length` — not to switch to `expectRaw`, which accepts anything
|
|
114
|
+
* but renders the assertion unlinked. Reach for `expectRaw(value, message)`
|
|
115
|
+
* only when the value never flowed from a recorded op at all (a computed
|
|
116
|
+
* number, a frame off a raw WebSocket); see its own doc comment.
|
|
111
117
|
*/
|
|
112
118
|
export type Provenanced = {
|
|
113
119
|
unwrap(): unknown;
|