mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* 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
60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { ProcessResult, ProcessSpec } from '@orca/process-host/process-spec'
|
|
import { selectPluginTestNode } from './plugin-test-node'
|
|
|
|
const ORCA = { execPath: '/Applications/Orca.app/Contents/MacOS/Orca', version: 'v22.9.0' }
|
|
|
|
function answering(stdout: string | Error, code = 0) {
|
|
const specs: ProcessSpec[] = []
|
|
const run = async (spec: ProcessSpec): Promise<ProcessResult> => {
|
|
specs.push(spec)
|
|
if (stdout instanceof Error) {
|
|
throw stdout
|
|
}
|
|
return { code, signal: null, stdout, stderr: '', timedOut: false }
|
|
}
|
|
return { run, specs }
|
|
}
|
|
|
|
describe('selectPluginTestNode', () => {
|
|
it('uses a new enough system node by the absolute path it reports, probed outside the plugin', async () => {
|
|
const probe = answering('v20.6.0 /usr/local/bin/node\n')
|
|
const node = await selectPluginTestNode({ ...ORCA, electron: '38.0.0', run: probe.run })
|
|
expect(node).toEqual({
|
|
program: '/usr/local/bin/node',
|
|
env: {},
|
|
source: 'system',
|
|
version: 'v20.6.0'
|
|
})
|
|
expect(probe.specs[0]?.program).toBe('node')
|
|
expect(probe.specs[0]?.cwd).toMatch(/orca-plugin-node-/)
|
|
})
|
|
|
|
it('keeps a Windows path with spaces whole', async () => {
|
|
const probe = answering('v22.1.0 C:\\Program Files\\nodejs\\node.exe\r\n')
|
|
const node = await selectPluginTestNode({ ...ORCA, electron: '38.0.0', run: probe.run })
|
|
expect(node.program).toBe('C:\\Program Files\\nodejs\\node.exe')
|
|
})
|
|
|
|
it.each([
|
|
['too old for module.register', answering('v20.5.1 /usr/bin/node')],
|
|
['not on PATH', answering(new Error('spawn node ENOENT'))],
|
|
['failing', answering('', 1)],
|
|
['answering garbage', answering('nope')]
|
|
])('falls back to Orca as Node when the system node is %s', async (_reason, probe) => {
|
|
const node = await selectPluginTestNode({ ...ORCA, electron: '38.0.0', run: probe.run })
|
|
expect(node).toEqual({
|
|
program: ORCA.execPath,
|
|
env: { ELECTRON_RUN_AS_NODE: '1' },
|
|
source: 'orca',
|
|
version: ORCA.version
|
|
})
|
|
})
|
|
|
|
it('needs no Electron switch when the CLI itself runs on plain Node', async () => {
|
|
const probe = answering(new Error('spawn node ENOENT'))
|
|
const node = await selectPluginTestNode({ ...ORCA, electron: undefined, run: probe.run })
|
|
expect(node.env).toEqual({})
|
|
})
|
|
})
|