nativeproof 0.8.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to NativeProof are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/) and the project adheres to
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## 0.9.0
8
+
9
+ Regex frame matching — `expect(mock)` matches traffic by pattern.
10
+
11
+ **Added**
12
+
13
+ - **`toHaveSent` / `toHaveReceived` (and `FrameMatch`) accept a `RegExp`** for `path`, `type`, and any
14
+ payload field — `expect(mock).toHaveSent({ path: /\/users/, type: "request" })` matches a
15
+ query-suffixed or otherwise variable path, mirroring regex selectors on the locator side. A string
16
+ stays an exact match (deep equality for payload objects); a RegExp tests the actual string value.
17
+
7
18
  ## 0.8.0
8
19
 
9
20
  Relative locators — `Locator.near` scopes to the match nearest an anchor.
package/README.md CHANGED
@@ -555,7 +555,8 @@ test.describe("chat room", "member", () => {
555
555
  - `mock.route(path).reject({ code })` — fail it (HTTP status, or WebSocket close code 3000–4999).
556
556
  - `mock.route(path).abort()` — drop the connect/request entirely.
557
557
  - `expect(mock).toHaveSent(match)` / `toHaveReceived(match)` — `match` is a partial frame:
558
- `path` / `type` plus any payload fields.
558
+ `path` / `type` plus any payload fields. Each field is a string (exact / deep-equal) **or a `RegExp`**
559
+ (`toHaveSent({ path: /\/users/, type: "request" })`) to match a query-suffixed or variable path.
559
560
 
560
561
  **Frame types** — real protocol messages keep their own `type` (a WS JSON message's `type`); the
561
562
  server also synthesises types for primitives so you can assert on them:
package/dist/mock.d.ts CHANGED
@@ -18,8 +18,8 @@ export interface MockFrame {
18
18
  }
19
19
  /** A partial frame to match against: `path` / `type` plus any payload fields. */
20
20
  export interface FrameMatch {
21
- path?: string;
22
- type?: string;
21
+ path?: string | RegExp;
22
+ type?: string | RegExp;
23
23
  [key: string]: unknown;
24
24
  }
25
25
  /** Controls how an intercepted path replies — the Playwright `Route` equivalent. */
package/dist/mock.js CHANGED
@@ -1,23 +1,33 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
+ /**
3
+ * Match one field of an observed frame against an expected value: a `RegExp` tests the
4
+ * actual string (so paths with query/suffix match — `toHaveSent({ path: /\/users/ })`),
5
+ * anything else is deep structural equality.
6
+ */
7
+ function fieldMatches(actual, expected) {
8
+ if (expected instanceof RegExp)
9
+ return typeof actual === "string" && expected.test(actual);
10
+ return isDeepStrictEqual(actual, expected);
11
+ }
2
12
  /**
3
13
  * True if `frame` satisfies every field of `match`: `path` / `type` at the top level,
4
14
  * every other key against the frame's payload.
5
15
  */
6
16
  export function matchesFrame(frame, match) {
7
- if (match.path !== undefined && frame.path !== match.path)
17
+ if (match.path !== undefined && !fieldMatches(frame.path, match.path))
8
18
  return false;
9
- if (match.type !== undefined && frame.type !== match.type)
19
+ if (match.type !== undefined && !fieldMatches(frame.type, match.type))
10
20
  return false;
11
21
  for (const [key, value] of Object.entries(match)) {
12
22
  if (key === "path" || key === "type")
13
23
  continue;
14
- if (!isDeepStrictEqual(frame.payload?.[key], value))
24
+ if (!fieldMatches(frame.payload?.[key], value))
15
25
  return false;
16
26
  }
17
27
  return true;
18
28
  }
19
29
  export function describeMatch(match) {
20
- return JSON.stringify(match);
30
+ return JSON.stringify(match, (_key, value) => (value instanceof RegExp ? String(value) : value));
21
31
  }
22
32
  /** Single-shot check: does any observed frame match `match` in `direction`? */
23
33
  export async function frameExists(source, direction, match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nativeproof",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Native Mobile E2E test framework inspired by Playwright (fixtures, locators, expect, route-style mocking) on Appium/WebdriverIO.",