Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(sdk): export getAllRegisteredComponents + add editor-bridge tests

esenginecc2b298da8d6
diff --git a/sdk/src/core-runtime.ts b/sdk/src/core-runtime.ts
index d462be75e..1fbcf8f42 100644
--- a/sdk/src/core-runtime.ts
+++ b/sdk/src/core-runtime.ts
@@ -66,6 +66,7 @@ export {
unregisterComponent,
registerComponent,
getComponent,
+ getAllRegisteredComponents,
type ComponentDef,
type BuiltinComponentDef,
type AnyComponentDef,
diff --git a/sdk/tests/editor-bridge.test.ts b/sdk/tests/editor-bridge.test.ts
new file mode 100644
index 000000000..701f680f7
--- /dev/null
+++ b/sdk/tests/editor-bridge.test.ts
@@ -0,0 +1,106 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import {
+ clearUserComponents,
+ defineComponent,
+ defineTag,
+ getAllRegisteredComponents,
+ getComponent,
+ isBuiltinComponent,
+} from '../src/component';
+import { getDefaultContext } from '../src/context';
+
+/**
+ * Confirms that the SDK-side `editorBridge` hook and the exports the
+ * editor uses for initial-replay (`getAllRegisteredComponents`,
+ * `isBuiltinComponent`) behave as the bridge plugin expects.
+ *
+ * These tests don't cover the editor plugin itself — that's wired in
+ * the Editrix app and doesn't ship in the SDK package. But the SDK
+ * contract they depend on is exercised here so a future refactor can't
+ * silently break the bridge.
+ */
+describe('editor bridge', () => {
+ const ctx = getDefaultContext();
+
+ beforeEach(() => {
+ ctx.editorBridge = null;
+ clearUserComponents();
+ });
+
+ afterEach(() => {
+ ctx.editorBridge = null;
+ clearUserComponents();
+ });
+
+ it('calls editorBridge.registerComponent on defineComponent', () => {
+ const seen: { name: string; isTag: boolean; defaultsKeys: string[] }[] = [];
+ ctx.editorBridge = {
+ registerComponent(name, defaults, isTag): void {
+ seen.push({ name, isTag, defaultsKeys: Object.keys(defaults) });
+ },
+ };
+
+ defineComponent('BridgeTestA', { x: 0, y: 0 });
+
+ expect(seen).toHaveLength(1);
+ expect(seen[0]?.name).toBe('BridgeTestA');
+ expect(seen[0]?.isTag).toBe(false);
+ expect(seen[0]?.defaultsKeys.sort()).toEqual(['x', 'y']);
+ });
+
+ it('calls editorBridge.registerComponent with isTag=true on defineTag', () => {
+ const seen: boolean[] = [];
+ ctx.editorBridge = {
+ registerComponent(_name, _defaults, isTag): void { seen.push(isTag); },
+ };
+
+ defineTag('BridgeTestTag');
+
+ expect(seen).toEqual([true]);
+ });
+
+ it('skips the callback when bridge is null (degrades to no-op)', () => {
+ expect(() => defineComponent('BridgeTestC', { n: 1 })).not.toThrow();
+ expect(getComponent('BridgeTestC')?._name).toBe('BridgeTestC');
+ });
+
+ it('the def is in the registry before the bridge callback fires', () => {
+ let defPresent = false;
+ ctx.editorBridge = {
+ registerComponent(name): void {
+ defPresent = getComponent(name) !== undefined;
+ },
+ };
+
+ defineComponent('BridgeTestD', { v: true });
+
+ expect(defPresent).toBe(true);
+ });
+
+ it('getAllRegisteredComponents exposes both builtins and user-defined', () => {
+ defineComponent('BridgeTestUser1', { z: 0 });
+ const all = getAllRegisteredComponents();
+
+ expect(all.has('BridgeTestUser1')).toBe(true);
+ // Transform is one of the core builtins — it must be present and
+ // flagged builtin so the bridge can skip it during replay.
+ const transform = all.get('Transform');
+ expect(transform).toBeDefined();
+ if (transform) expect(isBuiltinComponent(transform)).toBe(true);
+
+ const user = all.get('BridgeTestUser1');
+ expect(user).toBeDefined();
+ if (user) expect(isBuiltinComponent(user)).toBe(false);
+ });
+
+ it('carries assetFields through the registry so the bridge sees subtypes', () => {
+ defineComponent('BridgeTestAssetField', { ref: '' }, {
+ assetFields: [{ field: 'ref', type: 'audio' }],
+ });
+ const def = getComponent('BridgeTestAssetField');
+ expect(def).toBeDefined();
+ if (!def) return;
+ expect(def.assetFields).toHaveLength(1);
+ expect(def.assetFields[0]).toEqual({ field: 'ref', type: 'audio' });
+ });
+});