Files
orca/config/scripts/build-plugin-declarative-runtime.test.mjs
T
Neil 531658f1d1 Plugin test kit: orca/testing, orca plugin test and orca plugin check (#36969)
* feat(plugins): orca/testing kit, `orca plugin test` and `orca plugin check`

- `orca/testing` mounts a components panel in plain Node (node:test, vitest, bun) with the real
  runtime and Orca's own tree validator: find by text/role/label/testId, press/type/submit/toggle/
  select that resolve once the panel settles, tree() snapshots, errors (with stacks) and warnings,
  persisted state (with stored() for migrations), emit/setVisible/rerender, and unmount running
  setup cleanup. It re-exports node:test and strict assert so tests type-check without @types/node.
- mockHost refuses what Orca refuses with the same codes (surface, capability from the manifest,
  params, a gesture method without a press), checks configured results against the host API, and
  records calls.
- `orca plugin test [dir]` discovers *.test.ts(x) and runs them with node:test through Node module
  hooks that resolve `orca` like the guest's import map and transpile/resolve sources exactly as
  Orca's build-less loader, or with the plugin's own vitest via a generated config.
- `orca plugin check [dir]` validates, then renders each components panel once and reports what it
  threw (file:line), layouts Orca would refuse, and props it would drop.
- The kit, hooks and register entry ship minified beside orca-runtime.mjs and are unpacked from asar;
  typings land in .orca/types/orca-testing. The components template and hello-tsx get sample tests.
- ui.error carries an optional stack; a new runtime starts every atom from its initial value; the
  hydration fallback timer is cleared once hydrated.

* plugins: run plugin test/check on a system Node or Orca's own, and warn they are unsandboxed

* test(plugins): run the shipped example plugin tests from the unit suite
2026-11-01 02:42:12 -08:00

20 lines
950 B
JavaScript

import { readFileSync } from 'node:fs'
import { expect, it } from 'vitest'
import { bundleDeclarativeFiles } from './build-plugin-declarative-runtime.mjs'
it('keeps the checked-in runtime, testing kit and test hooks in sync with their sources', async () => {
const bundles = await bundleDeclarativeFiles()
for (const { output, text } of bundles) {
expect({ output, fresh: readFileSync(output, 'utf8') === text }).toEqual({
output,
fresh: true
})
}
const runtime = bundles.find(({ output }) => output.endsWith('orca-runtime.mjs'))?.text ?? ''
// A bare import would fail in the guest: it has no module resolver beyond the import map.
expect(runtime).not.toMatch(/^\s*import\s/m)
// The kit must share the panel's runtime instance, never carry its own copy.
const testing = bundles.find(({ output }) => output.endsWith('orca-testing.mjs'))?.text ?? ''
expect(testing).toContain('"./orca-runtime.mjs"')
}, 60_000)