@symbiote-native/test-utils 0.1.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/LICENSE +21 -0
- package/README.md +82 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 A. Prokopenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# @symbiote-native/test-utils
|
|
2
|
+
|
|
3
|
+
The **shared fake-Fabric test harness** of [SymbioteNative](../../README.md) (ADR 0025) — one
|
|
4
|
+
`installFabric()` that puts a fresh, faithful fake `nativeFabricUIManager` on `globalThis` and
|
|
5
|
+
returns a handle to inspect what a renderer committed. It replaces the per-file fake slot every
|
|
6
|
+
headless test used to copy-paste (×65 across the repo) with one implementation, shared by the
|
|
7
|
+
engine, every adapter, and the example apps' own colocated `vitest` suites.
|
|
8
|
+
|
|
9
|
+
> New to SymbioteNative? The [root README](../../README.md) has the architecture and the
|
|
10
|
+
> [Testing](../../README.md#testing) section this package's harness is the foundation of.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
Nearly every consumer gets this as a `devDependency`, alongside `vitest`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -D @symbiote-native/test-utils
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Use it
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { installFabric } from '@symbiote-native/test-utils';
|
|
28
|
+
|
|
29
|
+
test('tap increments the counter', () => {
|
|
30
|
+
const fabric = installFabric();
|
|
31
|
+
mount(1, createElement(App));
|
|
32
|
+
|
|
33
|
+
const button = fabric.find((n) => n.viewName === 'RCTView' && n.props.testID === 'tap-target');
|
|
34
|
+
fabric.fireEvent(button!.instanceHandle, 'topClick', {});
|
|
35
|
+
|
|
36
|
+
expect(fabric.serialize(fabric.committed)).toContain('Taps: 1');
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each test calls `installFabric()` fresh (or `.reset()` an existing handle between assertions in the
|
|
41
|
+
same test) — the fake slot is a `globalThis` singleton, so a stale handle from a previous test would
|
|
42
|
+
otherwise leak state into the next one.
|
|
43
|
+
|
|
44
|
+
## What `installFabric()` gives you
|
|
45
|
+
|
|
46
|
+
- **`committed`** — the child set from the most recent `completeRoot`, and **`appRoot()`** — unwraps
|
|
47
|
+
RN's synthetic `box-none` AppContainer root (ADR 0015) so a test doesn't re-check that invariant by
|
|
48
|
+
hand.
|
|
49
|
+
- **`created`** and **`find(predicate)`** — every node ever `createNode`'d this run (clones
|
|
50
|
+
excluded), and a lookup by predicate (e.g. "the app's own `View` with this `testID`").
|
|
51
|
+
- **`fireEvent(handle, topLevelType, nativeEvent?)`** — delivers a native event to whatever handler
|
|
52
|
+
the renderer registered, the same `instanceHandle` round-trip real Fabric does.
|
|
53
|
+
- **`commands`** and **`counts`** — every imperative command dispatched at a committed node, and
|
|
54
|
+
call counters (`createNode` / `completeRoot`) for tests asserting "exactly N native nodes".
|
|
55
|
+
- **`serialize(nodes)`** — a committed tree as `RCTView(RCTText(RCTRawText "text"))` shorthand, for
|
|
56
|
+
a one-line snapshot instead of walking `IFakeNode` by hand.
|
|
57
|
+
- **`reset()`** — zeroes the counters and clears `committed`/`created` (the registered event handler
|
|
58
|
+
survives), for reusing one `installFabric()` call across several assertions in one test.
|
|
59
|
+
|
|
60
|
+
The fake's persistence semantics are **faithful to real Fabric**, not simplified: every clone gets a
|
|
61
|
+
new identity, `clone*WithNewProps` **merges** the diff onto the previous props exactly like native
|
|
62
|
+
Fabric does with the engine's minimal-diff payload (a removed key arrives as literal `null` and
|
|
63
|
+
stays `null`, so a test can tell "explicitly reset" apart from "never set"), and `appendChild`
|
|
64
|
+
throws on an illegal family reparent. A persistence bug in the fake is fixed once, here, for every
|
|
65
|
+
test that depends on it.
|
|
66
|
+
|
|
67
|
+
## What it does NOT do
|
|
68
|
+
|
|
69
|
+
- It is not a mocking framework — there's nothing to configure beyond calling `installFabric()`;
|
|
70
|
+
the fake always behaves like real Fabric's clone-on-write contract.
|
|
71
|
+
- It does not stand in for on-device verification — see [Testing](../../README.md#testing) for how
|
|
72
|
+
this headless layer and the on-device `Detox` layer divide the work.
|
|
73
|
+
|
|
74
|
+
## Related packages
|
|
75
|
+
|
|
76
|
+
- [`@symbiote-native/engine`](../engine) — the package whose commit path this fake stands in for;
|
|
77
|
+
every adapter's headless test drives the real engine against this fake slot instead of real Fabric.
|
|
78
|
+
|
|
79
|
+
## Test it
|
|
80
|
+
|
|
81
|
+
This package has no tests of its own — it *is* the test double every other package's `vitest` suite
|
|
82
|
+
imports.
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbiote-native/test-utils",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Shared, framework-agnostic fake-Fabric test harness for SymbioteNative — the fake nativeFabricUIManager recorder used by the co-located test suites across the engine, every adapter, and the example apps.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/OneEyed1366/symbiote-native.git",
|
|
8
|
+
"directory": "core/test-utils"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/OneEyed1366/symbiote-native/tree/master/core/test-utils#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/OneEyed1366/symbiote-native/issues"
|
|
13
|
+
},
|
|
14
|
+
"author": "Andrey Prokopenko <psevdoproger@gmail.com>",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./build/index.js",
|
|
17
|
+
"module": "./build/index.js",
|
|
18
|
+
"types": "./build/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./build/index.d.ts",
|
|
22
|
+
"default": "./build/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"build"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"typecheck": "tsc --build",
|
|
33
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
34
|
+
}
|
|
35
|
+
}
|