nativeproof 0.10.1 → 0.10.3

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,45 @@ 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.10.3
8
+
9
+ Out-of-the-box setup: scaffolding, minimal config, a route-optional mock contract, and typed
10
+ contexts across the `createHarness` export boundary.
11
+
12
+ **Added**
13
+
14
+ - `nativeproof init` scaffolds a starter `nativeproof.config.ts` (app + harness + android/ios
15
+ projects) and a sample spec, so a new project is runnable in one command. Idempotent — it
16
+ never overwrites an existing file.
17
+ - `defineApp` now accepts any mock that exposes `frames()` + `stop()` (the new `SessionMock`);
18
+ `route()` is no longer required, since a session never routes (only a spec does). An app whose
19
+ mock only observes traffic can use `defineApp` / `createHarness` / `nativeproof.config` directly.
20
+ - `buildWdioConfig` fills in `platformName` and `appium:automationName` per platform (Android →
21
+ UiAutomator2, iOS → XCUITest), so a project needs only `name` + `platform`. A project's own
22
+ capabilities still win, and `DeviceProject.capabilities` is now optional.
23
+
24
+ **Fixed**
25
+
26
+ - `export const { test } = createHarness(app)` consumed from a spec in another file now keeps a
27
+ fully-typed fixture context. The harness/app/config are parameterised by the *resolved* context
28
+ rather than the screens type `S` (which TS widened to its constraint — screens → `unknown` — when
29
+ computing the exported type), so behaviours get typed `mock` and screens across the import
30
+ boundary. `App<S, M>` is now `App<Ctx>`; `NativeProofConfig` / `defineConfig` follow.
31
+
32
+ ## 0.10.2
33
+
34
+ Generic mock typing and built-in evidence-on-failure.
35
+
36
+ **Added**
37
+
38
+ - `defineApp` (and `createHarness` / `defineConfig`) are now generic over the mock type. An app
39
+ whose mock extends the base contract gets that concrete type through screens, login/join,
40
+ teardown, `onFailure` and the session context — no casts. Existing single-type-arg uses are
41
+ unchanged (the mock type defaults to `MockBackend`).
42
+ - The synthesised runner config captures evidence on a failed behaviour out of the box — a
43
+ screenshot + redacted page source named after the spec — so apps need no hand-written
44
+ `afterTest`. Best-effort: a capture error never masks the real failure.
45
+
7
46
  ## 0.10.1
8
47
 
9
48
  Cross-platform locator resolution fixes.
package/dist/app.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Driver } from "./driver.js";
2
2
  import type { FailureInfo, ScenarioFixture } from "./fixtures.js";
3
- import type { MockBackend } from "./mock.js";
3
+ import type { SessionMock } from "./mock.js";
4
4
  /**
5
5
  * `defineApp` — the single seam script.
6
6
  *
@@ -10,53 +10,84 @@ import type { MockBackend } from "./mock.js";
10
10
  * framework core imports nothing from the app; the app describes itself here once.
11
11
  * `app.session(role)` turns that into a {@link ScenarioFixture} the `test` facade runs.
12
12
  */
13
- /** The device handles every session provides before app screens are layered on. */
14
- export interface DeviceContext {
13
+ /**
14
+ * The device handles every session provides before app screens are layered on.
15
+ * Generic over the mock type `M` (default {@link SessionMock}) so an app with a richer
16
+ * mock — extra socket/presence controls beyond the base contract — gets `mock` typed as
17
+ * that richer type throughout, with no casts. The constraint is `SessionMock` (frames + stop),
18
+ * not the full `MockBackend`, so a mock that doesn't implement `route()` still works.
19
+ */
20
+ export interface DeviceContext<M extends SessionMock = SessionMock> {
15
21
  driver: Driver;
16
- mock: MockBackend;
22
+ mock: M;
17
23
  }
18
24
  /** A screen-object factory: given the device context, build that screen's locators/actions. */
19
- export type ScreenFactory<S> = (context: DeviceContext) => S;
20
- export type ScreenFactories = Record<string, ScreenFactory<unknown>>;
25
+ export type ScreenFactory<S, M extends SessionMock = SessionMock> = (context: DeviceContext<M>) => S;
26
+ export type ScreenFactories<M extends SessionMock = SessionMock> = Record<string, ScreenFactory<unknown, M>>;
21
27
  /** Context passed to the login/join flows. */
22
- export type FlowContext = DeviceContext & {
28
+ export type FlowContext<M extends SessionMock = SessionMock> = DeviceContext<M> & {
23
29
  role: string;
24
30
  };
25
- export interface AppDefinition<S extends ScreenFactories> {
31
+ export interface AppDefinition<S extends ScreenFactories<M>, M extends SessionMock = SessionMock> {
26
32
  /** Acquire the device/driver (e.g. wdioDriver()). */
27
33
  driver: () => Driver | Promise<Driver>;
28
- /** Start the app's mock backend. */
29
- mock: () => MockBackend | Promise<MockBackend>;
34
+ /** Start the app's mock backend (its concrete type `M` flows through the whole session). */
35
+ mock: () => M | Promise<M>;
30
36
  /** App-specific secret patterns to keep out of evidence (injected, never baked into the core). */
31
37
  secrets?: readonly RegExp[];
32
38
  /** App-specific evidence-redaction patterns. */
33
39
  redact?: readonly RegExp[];
34
40
  /** Reach a logged-in state for the role. */
35
- login?: (context: FlowContext) => Promise<void>;
41
+ login?: (context: NoInfer<FlowContext<M>>) => Promise<void>;
36
42
  /** Enter the role's main surface. */
37
- join?: (context: FlowContext) => Promise<void>;
38
- /** Screen-object factories, bound to the device context. */
43
+ join?: (context: NoInfer<FlowContext<M>>) => Promise<void>;
44
+ /** Screen-object factories, bound to the device context. `S` (and so the whole context) is
45
+ * inferred from here. */
39
46
  screens: S;
40
47
  /**
41
48
  * Release app-level resources acquired across the session, run on teardown BEFORE the
42
49
  * mock stops and before the runner deletes the device session — e.g. force-stop the app
43
50
  * so its background sockets are gone before `deleteSession`. The mock is still stopped
44
51
  * even if this throws.
52
+ *
53
+ * The context is wrapped in `NoInfer` so passing a `teardown` does NOT drive `S` inference —
54
+ * otherwise this S-dependent parameter co-infers with `screens` and collapses `S` to its
55
+ * `ScreenFactories<M>` constraint (screens → `unknown`) in the exported context type.
45
56
  */
46
- teardown?: (context: SessionContext<S>) => Promise<void> | void;
57
+ teardown?: (context: NoInfer<SessionContext<S, M>>) => Promise<void> | void;
47
58
  /**
48
59
  * Invoked when a behaviour throws, before the failure propagates — wire on-failure
49
60
  * evidence here (e.g. `captureState(...)`) so capture lives in one place, not in every
50
- * behaviour. Its own errors are swallowed so they never mask the real failure.
61
+ * behaviour. Its own errors are swallowed so they never mask the real failure. `NoInfer` for the
62
+ * same reason as `teardown` — this parameter must not participate in inferring `S`.
51
63
  */
52
- onFailure?: (context: SessionContext<S>, info: FailureInfo) => Promise<void> | void;
64
+ onFailure?: (context: NoInfer<SessionContext<S, M>>, info: FailureInfo) => Promise<void> | void;
53
65
  }
54
- /** The fixture context a session injects: the device handles plus each app screen. */
55
- export type SessionContext<S extends ScreenFactories> = DeviceContext & {
66
+ /** Eagerly flatten an intersection into one object type, so the resolved context ports cleanly. */
67
+ type Prettify<T> = {
68
+ [K in keyof T]: T[K];
69
+ } & {};
70
+ /**
71
+ * The fixture context a session injects: the device handles plus each app screen's value. Flattened
72
+ * with {@link Prettify} so it is a single object type rather than a lazy intersection — that lets
73
+ * `export const { test } = createHarness(app)` carry fully-typed screens into specs in other files.
74
+ * (Portability still needs the mock type `M` to be nameable — a single exported interface, not an
75
+ * anonymous intersection — so a consumer's mock should be one named type.)
76
+ */
77
+ export type SessionContext<S extends ScreenFactories<M>, M extends SessionMock = SessionMock> = Prettify<DeviceContext<M> & {
56
78
  [K in keyof S]: ReturnType<S[K]>;
57
- };
58
- export interface App<S extends ScreenFactories> {
79
+ }>;
80
+ /**
81
+ * Parameterised by the *resolved* session context `Ctx` (`{ driver; mock; …screens }`), not by
82
+ * the screens type `S`. `S` is only ever used inside the mapped `SessionContext<S, M>`, a
83
+ * non-inferable position — so a consumer's `export const { test } = createHarness(app)` would
84
+ * lose the concrete screen return types across the import boundary (TS falls back to the
85
+ * `ScreenFactories<M>` constraint, whose screens are `unknown`). `defineApp` resolves the context
86
+ * here, where `S` is still concrete, so `Ctx` is a plain object type that ports cleanly into specs.
87
+ */
88
+ export interface App<Ctx> {
59
89
  /** A scenario fixture that provisions a logged-in, joined session for `role`. */
60
- session(role?: string): ScenarioFixture<SessionContext<S>>;
90
+ session(role?: string): ScenarioFixture<Ctx>;
61
91
  }
62
- export declare function defineApp<S extends ScreenFactories>(definition: AppDefinition<S>): App<S>;
92
+ export declare function defineApp<S extends ScreenFactories<M>, M extends SessionMock = SessionMock>(definition: AppDefinition<S, M>): App<SessionContext<S, M>>;
93
+ export {};
package/dist/app.js CHANGED
@@ -12,7 +12,8 @@ export function defineApp(definition) {
12
12
  if (definition.join)
13
13
  await definition.join({ ...device, role });
14
14
  const screens = {};
15
- for (const [name, factory] of Object.entries(definition.screens)) {
15
+ const factories = Object.entries(definition.screens);
16
+ for (const [name, factory] of factories) {
16
17
  screens[name] = factory(device);
17
18
  }
18
19
  // Dynamic assembly: the screen factories' precise return types are
package/dist/cli.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * the environment (the mobile analogue of needing a display) and is left to the host.
10
10
  */
11
11
  export interface CliArgs {
12
- command: "test" | "help" | "version";
12
+ command: "test" | "init" | "help" | "version";
13
13
  config: string | undefined;
14
14
  platform: "android" | "ios" | undefined;
15
15
  project: string | undefined;
@@ -22,6 +22,23 @@ export interface CliArgs {
22
22
  export declare function parseArgs(argv: readonly string[]): CliArgs;
23
23
  export declare function version(): string;
24
24
  export declare function helpText(): string;
25
+ export interface ScaffoldFile {
26
+ path: string;
27
+ contents: string;
28
+ }
29
+ /** The starter files \`nativeproof init\` writes — pure, so they can be asserted in a test. */
30
+ export declare function scaffoldFiles(): ScaffoldFile[];
31
+ /** Minimal filesystem seam so \`scaffold\` is testable without touching disk. */
32
+ export interface ScaffoldIo {
33
+ exists(file: string): boolean;
34
+ write(file: string, contents: string): void;
35
+ }
36
+ /** Write the starter files under \`cwd\`, never overwriting an existing one. */
37
+ export declare function scaffold(cwd: string, io?: ScaffoldIo): {
38
+ created: string[];
39
+ skipped: string[];
40
+ };
41
+ export declare function init(cwd?: string): number;
25
42
  interface ResolvedRunner {
26
43
  wdioConfig: string;
27
44
  extraEnv: NodeJS.ProcessEnv;
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn } from "node:child_process";
3
- import { existsSync, readFileSync, realpathSync } from "node:fs";
3
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { findConfigFile } from "./config.js";
@@ -27,6 +27,10 @@ export function parseArgs(argv) {
27
27
  const arg = argv[i];
28
28
  if (arg === "test")
29
29
  continue;
30
+ if (arg === "init") {
31
+ args.command = "init";
32
+ continue;
33
+ }
30
34
  if (arg === "-h" || arg === "--help")
31
35
  return { ...args, command: "help" };
32
36
  if (arg === "-v" || arg === "--version")
@@ -92,7 +96,8 @@ export function helpText() {
92
96
  "nativeproof — Native Mobile E2E test framework inspired by Playwright",
93
97
  "",
94
98
  "Usage:",
95
- " nativeproof [test] [options]",
99
+ " nativeproof [test] [options] run the suite (default)",
100
+ " nativeproof init scaffold nativeproof.config.ts + a sample spec",
96
101
  "",
97
102
  "Config is auto-discovered: nativeproof.config.ts (preferred), else wdio.conf.ts.",
98
103
  "",
@@ -109,6 +114,88 @@ export function helpText() {
109
114
  " -v, --version print the version",
110
115
  ].join("\n");
111
116
  }
117
+ const CONFIG_TEMPLATE = `import { createHarness, defineApp, defineConfig, page, startMockServer, wdioDriver } from "nativeproof";
118
+
119
+ /**
120
+ * One file declares your app, your devices, and where your specs live — the
121
+ * \`nativeproof\` CLI discovers it and runs the suite. Replace the TODOs with your app.
122
+ */
123
+ const app = defineApp({
124
+ // Acquire the device/driver (Appium/WebdriverIO under the hood).
125
+ driver: () => wdioDriver(),
126
+ // Start a mock backend; swap startMockServer() for your own if you have one.
127
+ mock: () => startMockServer(),
128
+ // Screen objects: build locators/actions from the device context. Replace these.
129
+ screens: {
130
+ home: ({ driver }) => ({
131
+ heading: page(driver).getByText("Welcome"),
132
+ }),
133
+ },
134
+ });
135
+
136
+ // Specs import these: \`import { test, expect } from "../nativeproof.config";\`
137
+ export const { test, expect } = createHarness(app);
138
+
139
+ export default defineConfig({
140
+ app,
141
+ testDir: "tests",
142
+ // platformName + automationName are filled in from \`platform\`; set \`appium:app\` to your build.
143
+ projects: [
144
+ { name: "android", platform: "android", capabilities: { /* "appium:app": "/path/to/app.apk" */ } },
145
+ { name: "ios", platform: "ios", capabilities: { /* "appium:app": "/path/to/app.app" */ } },
146
+ ],
147
+ });
148
+ `;
149
+ const SPEC_TEMPLATE = `import { expect, test } from "../nativeproof.config";
150
+
151
+ test.describe("example", () => {
152
+ test("the home screen shows its heading", async ({ home }) => {
153
+ await expect(home.heading).toBeVisible();
154
+ });
155
+ });
156
+ `;
157
+ /** The starter files \`nativeproof init\` writes — pure, so they can be asserted in a test. */
158
+ export function scaffoldFiles() {
159
+ return [
160
+ { path: "nativeproof.config.ts", contents: CONFIG_TEMPLATE },
161
+ { path: "tests/example.spec.ts", contents: SPEC_TEMPLATE },
162
+ ];
163
+ }
164
+ const diskIo = {
165
+ exists: existsSync,
166
+ write(file, contents) {
167
+ mkdirSync(path.dirname(file), { recursive: true });
168
+ writeFileSync(file, contents);
169
+ },
170
+ };
171
+ /** Write the starter files under \`cwd\`, never overwriting an existing one. */
172
+ export function scaffold(cwd, io = diskIo) {
173
+ const created = [];
174
+ const skipped = [];
175
+ for (const file of scaffoldFiles()) {
176
+ if (io.exists(path.join(cwd, file.path))) {
177
+ skipped.push(file.path);
178
+ continue;
179
+ }
180
+ io.write(path.join(cwd, file.path), file.contents);
181
+ created.push(file.path);
182
+ }
183
+ return { created, skipped };
184
+ }
185
+ export function init(cwd = process.cwd()) {
186
+ const { created, skipped } = scaffold(cwd);
187
+ for (const file of created)
188
+ console.log(`nativeproof: created ${file}`);
189
+ for (const file of skipped)
190
+ console.log(`nativeproof: ${file} already exists — skipped`);
191
+ if (created.length === 0) {
192
+ console.log("nativeproof: nothing to scaffold (all files already exist)");
193
+ }
194
+ else {
195
+ console.log("\nNext: set capabilities + screens in nativeproof.config.ts, then run `nativeproof`.");
196
+ }
197
+ return 0;
198
+ }
112
199
  function localBin(name) {
113
200
  const bin = path.join(process.cwd(), "node_modules", ".bin", name);
114
201
  return existsSync(bin) ? bin : name;
@@ -208,6 +295,9 @@ export async function main(argv) {
208
295
  console.log(version());
209
296
  return 0;
210
297
  }
298
+ if (args.command === "init") {
299
+ return init();
300
+ }
211
301
  return runTests(args);
212
302
  }
213
303
  /** True when this file is the process entry — robust to the symlink npm creates for bins. */
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { App, ScreenFactories } from "./app.js";
1
+ import type { App } from "./app.js";
2
2
  /**
3
3
  * The Playwright-style config: one `nativeproof.config.ts` declares the app, the device
4
4
  * projects, and where the tests live. The `nativeproof` CLI auto-discovers it and
@@ -29,9 +29,20 @@ export interface DeviceProject {
29
29
  /** A name to select with `nativeproof --project <name>`. */
30
30
  name: string;
31
31
  platform: "android" | "ios";
32
- /** Appium capabilities for this device (e.g. `appium:app`, `appium:deviceName`). */
33
- capabilities: Record<string, unknown>;
32
+ /**
33
+ * Appium capabilities for this device (e.g. `appium:app`, `appium:deviceName`). Optional:
34
+ * `platformName` and `appium:automationName` are filled in from `platform` (see
35
+ * {@link defaultCapabilities}), so a project usually needs only `appium:app` — or nothing
36
+ * for a smoke run against whatever is already installed. Anything you set here wins.
37
+ */
38
+ capabilities?: Record<string, unknown>;
34
39
  }
40
+ /**
41
+ * The standard capabilities for a platform, so a consumer doesn't restate the same
42
+ * `platformName` / `automationName` in every project. Android → UiAutomator2, iOS → XCUITest
43
+ * (the canonical Appium drivers). A project's own `capabilities` override these.
44
+ */
45
+ export declare function defaultCapabilities(platform: "android" | "ios"): Record<string, unknown>;
35
46
  /** The device/run config the CLI turns into a WebdriverIO run. */
36
47
  export interface RunnerConfig {
37
48
  /** Directory holding the specs (default "tests"). */
@@ -43,12 +54,12 @@ export interface RunnerConfig {
43
54
  /** Per-test timeout in ms (default 240000). */
44
55
  mochaTimeout?: number;
45
56
  }
46
- export interface NativeProofConfig<S extends ScreenFactories = ScreenFactories> extends RunnerConfig {
57
+ export interface NativeProofConfig<Ctx = unknown> extends RunnerConfig {
47
58
  /** The app under test (from `defineApp`). */
48
- app: App<S>;
59
+ app: App<Ctx>;
49
60
  }
50
61
  /** Identity helper for typed config + editor autocomplete (mirrors Playwright's `defineConfig`). */
51
- export declare function defineConfig<S extends ScreenFactories>(config: NativeProofConfig<S>): NativeProofConfig<S>;
62
+ export declare function defineConfig<Ctx>(config: NativeProofConfig<Ctx>): NativeProofConfig<Ctx>;
52
63
  /** Selection inputs (from the CLI / env) used to resolve the active project + connection. */
53
64
  export interface RunnerEnv {
54
65
  platform?: string;
package/dist/config.js CHANGED
@@ -1,5 +1,16 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
+ import { captureState, failureEvidenceName } from "./evidence.js";
4
+ /**
5
+ * The standard capabilities for a platform, so a consumer doesn't restate the same
6
+ * `platformName` / `automationName` in every project. Android → UiAutomator2, iOS → XCUITest
7
+ * (the canonical Appium drivers). A project's own `capabilities` override these.
8
+ */
9
+ export function defaultCapabilities(platform) {
10
+ return platform === "android"
11
+ ? { platformName: "Android", "appium:automationName": "UiAutomator2" }
12
+ : { platformName: "iOS", "appium:automationName": "XCUITest" };
13
+ }
3
14
  /** Identity helper for typed config + editor autocomplete (mirrors Playwright's `defineConfig`). */
4
15
  export function defineConfig(config) {
5
16
  return config;
@@ -39,10 +50,19 @@ export function buildWdioConfig(config, env = {}, cwd = process.cwd()) {
39
50
  path: env.appiumPath ?? config.appium?.path ?? "/wd/hub",
40
51
  specs,
41
52
  maxInstances: 1,
42
- capabilities: [project.capabilities],
53
+ capabilities: [{ ...defaultCapabilities(project.platform), ...project.capabilities }],
43
54
  framework: "mocha",
44
55
  reporters: ["spec"],
45
56
  mochaOpts: { ui: "bdd", timeout: config.mochaTimeout ?? 240_000 },
57
+ // Evidence on failure, out of the box: on a failed behaviour, snapshot a screenshot +
58
+ // redacted page source into the artifact dir, named after the spec. Best-effort — a
59
+ // capture error never masks the real failure — and consumers get it without writing
60
+ // their own afterTest hook.
61
+ afterTest: async (test, _context, result) => {
62
+ if (result.passed)
63
+ return;
64
+ await captureState(failureEvidenceName(test)).catch(() => { });
65
+ },
46
66
  };
47
67
  }
48
68
  const CONFIG_NAMES = [
@@ -3,3 +3,13 @@ export declare function captureText(filename: string, contents: string): Promise
3
3
  export declare function captureScreenshot(filename: string): Promise<string>;
4
4
  /** Capture a screenshot + redacted source pair under one prefix; returns the source. */
5
5
  export declare function captureState(prefix: string): Promise<string>;
6
+ /**
7
+ * A filesystem-safe evidence prefix for a failed behaviour — `failure-<describe>-<test>`
8
+ * with runs of non-word characters collapsed to `_` and capped at 120 chars. Used by the
9
+ * runner's built-in on-failure capture so a failing spec leaves a screenshot + source pair
10
+ * named after it, with no per-spec wiring.
11
+ */
12
+ export declare function failureEvidenceName(test: {
13
+ parent: string;
14
+ title: string;
15
+ }): string;
package/dist/evidence.js CHANGED
@@ -42,3 +42,12 @@ export async function captureState(prefix) {
42
42
  await captureText(`${prefix}.xml`, source);
43
43
  return source;
44
44
  }
45
+ /**
46
+ * A filesystem-safe evidence prefix for a failed behaviour — `failure-<describe>-<test>`
47
+ * with runs of non-word characters collapsed to `_` and capped at 120 chars. Used by the
48
+ * runner's built-in on-failure capture so a failing spec leaves a screenshot + source pair
49
+ * named after it, with no per-spec wiring.
50
+ */
51
+ export function failureEvidenceName(test) {
52
+ return `failure-${test.parent}-${test.title}`.replace(/[^\w.-]+/g, "_").slice(0, 120);
53
+ }
package/dist/harness.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { App, ScreenFactories, SessionContext } from "./app.js";
1
+ import type { App } from "./app.js";
2
2
  import { expect } from "./expect.js";
3
3
  /**
4
4
  * `createHarness(app)` — the Playwright `@playwright/test` pattern.
@@ -18,19 +18,28 @@ import { expect } from "./expect.js";
18
18
  * });
19
19
  * ```
20
20
  */
21
- export interface HarnessTest<S extends ScreenFactories> {
22
- (name: string, body: (context: SessionContext<S>) => void | Promise<void>): void;
21
+ /**
22
+ * Parameterised by the *resolved* session context `Ctx`, not by the screens type `S`. When a
23
+ * project does `export const { test } = createHarness(app)` and a spec in another file imports
24
+ * `test`, TS computes the portable exported type — and if the harness were parameterised by
25
+ * `S extends ScreenFactories<M>`, it would write the **constraint** (`ScreenFactories<M>`, whose
26
+ * screens return `unknown`) instead of the concrete `S`, so every imported behaviour's context
27
+ * would be `unknown`. `Ctx` is already the concrete object (`{ driver; mock; …screens }`), so the
28
+ * screen return types survive the boundary and behaviours stay fully typed.
29
+ */
30
+ export interface HarnessTest<Ctx> {
31
+ (name: string, body: (context: Ctx) => void | Promise<void>): void;
23
32
  /** Open a scenario block for the default role. */
24
33
  describe(title: string, body: () => void): void;
25
34
  /** Open a scenario block for a specific role (e.g. "member" / "guest"). */
26
35
  describe(title: string, role: string, body: () => void): void;
27
36
  /** Run before each behaviour in the open scenario, with the session context injected. */
28
- beforeEach(body: (context: SessionContext<S>) => void | Promise<void>): void;
37
+ beforeEach(body: (context: Ctx) => void | Promise<void>): void;
29
38
  /** Run after each behaviour in the open scenario, with the session context injected. */
30
- afterEach(body: (context: SessionContext<S>) => void | Promise<void>): void;
39
+ afterEach(body: (context: Ctx) => void | Promise<void>): void;
31
40
  }
32
- export interface Harness<S extends ScreenFactories> {
33
- test: HarnessTest<S>;
41
+ export interface Harness<Ctx> {
42
+ test: HarnessTest<Ctx>;
34
43
  expect: typeof expect;
35
44
  }
36
- export declare function createHarness<S extends ScreenFactories>(app: App<S>): Harness<S>;
45
+ export declare function createHarness<Ctx>(app: App<Ctx>): Harness<Ctx>;
package/dist/mock.d.ts CHANGED
@@ -43,12 +43,20 @@ export interface FrameLog {
43
43
  /** Every frame observed so far, in order, both directions. */
44
44
  frames(): Promise<readonly MockFrame[]>;
45
45
  }
46
- export interface MockBackend extends FrameLog {
47
- /** Intercept a path and control its reply. */
48
- route(path: string): MockRoute;
46
+ /**
47
+ * The minimum a mock must provide to drive a {@link defineApp} session: observable frames plus a
48
+ * `stop()` the session calls on teardown. `route()` is intentionally NOT required — a session never
49
+ * routes (only a spec does) — so an app whose mock only observes frames and stops can use
50
+ * `defineApp` without implementing `route`. {@link MockBackend} is the full contract (adds `route`).
51
+ */
52
+ export interface SessionMock extends FrameLog {
49
53
  /** Release the backend (stop the server, close sockets). */
50
54
  stop(): Promise<void>;
51
55
  }
56
+ export interface MockBackend extends SessionMock {
57
+ /** Intercept a path and control its reply. */
58
+ route(path: string): MockRoute;
59
+ }
52
60
  /**
53
61
  * True if `frame` satisfies every field of `match`: `path` / `type` at the top level,
54
62
  * every other key against the frame's payload.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nativeproof",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
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.",