Testing
Unit tests with a fake bridge
Pass your own port to createLex to test without a host:
ts
import { createLex } from '@lex/sdk';
const listeners: Array<(e: { data: unknown }) => void> = [];
const port = {
postMessage(msg: { type: string; id: string }) {
if (msg.type === 'request') {
queueMicrotask(() => listeners.forEach((l) =>
l({ data: { lex: 1, type: 'response', id: msg.id, ok: true, result: { value: null } } })));
}
},
addEventListener(_type: 'message', l: (e: { data: unknown }) => void) { listeners.push(l); },
};
const lex = createLex({ port });
expect(await lex.storage.get('missing')).toBeNull();End-to-end in Preview
Preview on the contributor platform runs your build in the real sandbox with a simulated host: in-memory storage, notifications shown as toasts and a simulated assistant reply. Use it to check that nothing the sandbox blocks is on your critical path.
Before you submit
- The build has no warnings about network APIs,
eval, browser storage orwindow.parent. - Every SDK call is covered by a permission in the manifest, and nothing more is requested.
versionis bumped if you've published before.
