Import tools/verify-directory-flow.mjs

This commit is contained in:
QQ 2026-11-11 22:34:56 +08:00
parent 4e2224ee34
commit 7b26460981
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import assert from 'node:assert/strict'
import { directoryFlowFromEntry } from '../src/client/directory-flow.ts'
assert.equal(directoryFlowFromEntry(undefined), null)
const component = () => null
const workspaces = { create() {} }
let called = 0
const entry = { component, options: {}, inject: () => { called++; return { workspaces } } }
const flow = directoryFlowFromEntry(entry)
assert.equal(flow.component, component)
assert.equal(flow.injected.workspaces, workspaces)
assert.equal(called, 1)
assert.deepEqual(directoryFlowFromEntry({ component, options: {} }).injected, {})
for (const extra of [{ locale: 'picker' }, { store: {} }, { children: {} }, { component: null }]) {
assert.throws(() => directoryFlowFromEntry({ ...entry, ...extra }), /unsupported renderer context/)
}
assert.throws(() => directoryFlowFromEntry({ ...entry, inject: () => { throw new Error('service unavailable') } }), /service unavailable/)
console.log('directory flow adapter: all assertions passed')