@solidrt/test 0.0.72 → 0.0.73
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/AGENTS.md +7 -0
- package/package.json +3 -3
- package/src/index.ts +34 -1
package/AGENTS.md
CHANGED
|
@@ -59,6 +59,13 @@ agents/testing.md.
|
|
|
59
59
|
app registered with `registerDebug` and returns its value: the way to
|
|
60
60
|
put a loaded app into a state its UI reaches slowly. A `gamepad` event
|
|
61
61
|
in `app.input` seats and drives a synthetic pad, as `send_input` does.
|
|
62
|
+
- `await app.camera({ width, height, pixels })` makes an RGBA8 image (a
|
|
63
|
+
`decodeImage` result, or pixels the test builds) what the camera sees:
|
|
64
|
+
every camera the app opens shows it, with no device and no prompt, and
|
|
65
|
+
an open one shows it from the next frame. Call it before the app opens
|
|
66
|
+
its camera; call it again to show another image. A QR code in it is
|
|
67
|
+
decoded as from a real camera, so `settle()` after the open and read
|
|
68
|
+
the app's barcode state.
|
|
62
69
|
- Past a node's record: `locator.outline()` is the subtree as an outline
|
|
63
70
|
(kind, label, text, box per line, no ids) to pin a layout or print it;
|
|
64
71
|
`locator.pixel(x, y)` is `[r, g, b, a]` at a point of the node and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidrt/test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"funding": "https://github.com/sponsors/wellawaretech",
|
|
6
6
|
"author": "Antoine van Wel",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"AGENTS.md"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@solidrt/flux-types": "0.0.
|
|
17
|
+
"@solidrt/flux-types": "0.0.73"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@solidrt/core": "0.0.
|
|
20
|
+
"@solidrt/core": "0.0.73"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { test as register, expect } from "flux:test"
|
|
18
18
|
import * as gui from "flux:test/gui"
|
|
19
|
-
import { capture, debug, frame as stepFrame, frameRate, inputPlan, inputStep, link, painted as paintFrame, setFrameRate, settle, time, windowReady } from "sol:test"
|
|
19
|
+
import { camera as installCamera, capture, debug, frame as stepFrame, frameRate, inputPlan, inputStep, link, painted as paintFrame, setFrameRate, settle, time, windowReady } from "sol:test"
|
|
20
20
|
import { createElement, insert, render } from "@solidrt/core"
|
|
21
21
|
|
|
22
22
|
export { expect }
|
|
@@ -158,6 +158,13 @@ export interface PointerOptions {
|
|
|
158
158
|
meta?: boolean
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/** An RGBA8 image, tightly packed rows top to bottom: what `decodeImage` returns. */
|
|
162
|
+
export interface CameraImage {
|
|
163
|
+
width: number
|
|
164
|
+
height: number
|
|
165
|
+
pixels: Uint8Array
|
|
166
|
+
}
|
|
167
|
+
|
|
161
168
|
/** The app under test, as a test's function receives it. */
|
|
162
169
|
export interface TestApp {
|
|
163
170
|
/**
|
|
@@ -191,6 +198,23 @@ export interface TestApp {
|
|
|
191
198
|
* `settle()` after it.
|
|
192
199
|
*/
|
|
193
200
|
link(link: string): Promise<void>
|
|
201
|
+
/**
|
|
202
|
+
* Makes `image` what the camera sees: every camera the app opens from
|
|
203
|
+
* now on shows it (a `createCamera` or `open` resolves at once, no device
|
|
204
|
+
* and no permission prompt), and a camera already open shows it from the
|
|
205
|
+
* next frame. Call it before `mount` or `load` so the app's own open finds
|
|
206
|
+
* it; call it again to show the app another image. A QR code in the
|
|
207
|
+
* image is decoded like one in front of a real camera: `settle()` after
|
|
208
|
+
* the open and the app's barcode handler has run. Pass a `decodeImage`
|
|
209
|
+
* result, or pixels the test builds.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* await app.camera(decodeImage(png))
|
|
213
|
+
* let cam = createCamera({ scan: ["qr"] })
|
|
214
|
+
* await app.settle()
|
|
215
|
+
* expect(cam.barcode()?.data).toBe("solidrt")
|
|
216
|
+
*/
|
|
217
|
+
camera(image: CameraImage): Promise<void>
|
|
194
218
|
/**
|
|
195
219
|
* Calls a debug command the app registered (`registerDebug` of
|
|
196
220
|
* `sol:dev`), runs a frame, and returns what the command returned. The
|
|
@@ -497,6 +521,15 @@ let app: TestApp = {
|
|
|
497
521
|
if (!link(target)) throw new Error(`link: the app does not listen for links (no onLink handler), so ${JSON.stringify(target)} went nowhere`)
|
|
498
522
|
await app.frame()
|
|
499
523
|
},
|
|
524
|
+
async camera(image) {
|
|
525
|
+
let ok = image !== null && typeof image === "object" && image.pixels instanceof Uint8Array
|
|
526
|
+
if (!ok) throw new TypeError("camera: pass { width, height, pixels }, with the pixels a Uint8Array of RGBA8")
|
|
527
|
+
let { width, height, pixels } = image
|
|
528
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) throw new TypeError(`camera: the size must be positive integers, got ${width} x ${height}`)
|
|
529
|
+
if (pixels.length !== width * height * RGBA) throw new TypeError(`camera: ${width} x ${height} RGBA8 is ${width * height * RGBA} bytes, got ${pixels.length}`)
|
|
530
|
+
installCamera(width, height, pixels)
|
|
531
|
+
await app.frame()
|
|
532
|
+
},
|
|
500
533
|
async debug(name, args) {
|
|
501
534
|
let result = debug(name, args === undefined ? null : JSON.stringify(args))
|
|
502
535
|
await app.frame()
|