Documentation
¶
Index ¶
- Constants
- func RunTypeScriptTest(ctx context.Context, le *logrus.Entry, pluginID string, tsFilePath string) (success bool, errorMsg string, err error)
- func SetupResourceClient(ctx context.Context, t *testing.T, tb *world_testbed.Testbed) (*resource_client.Client, func())
- func SetupTestbedWithClient(ctx context.Context, t *testing.T) (*world_testbed.Testbed, *resource_client.Client, func())
- type BrowserTestServerdeprecated
- type LayoutServerHelper
- type TestbedResourceServer
- func (s *TestbedResourceServer) AccessStateAtom(ctx context.Context, req *s4wave_testbed.AccessStateAtomRequest) (*s4wave_testbed.AccessStateAtomResponse, error)
- func (s *TestbedResourceServer) CreateWorld(ctx context.Context, req *s4wave_testbed.CreateWorldRequest) (*s4wave_testbed.CreateWorldResponse, error)
- func (s *TestbedResourceServer) GetMux() srpc.Invoker
- func (s *TestbedResourceServer) MarkTestResult(ctx context.Context, req *s4wave_testbed.MarkTestResultRequest) (*s4wave_testbed.MarkTestResultResponse, error)
- func (s *TestbedResourceServer) Register(mux srpc.Mux) error
- func (s *TestbedResourceServer) WaitForTestResult(ctx context.Context) (success bool, errorMsg string, err error)
- type TestbedWithQuickJS
Constants ¶
const StateAtomObjectStoreID = "testbed-state-atoms"
StateAtomObjectStoreID is the object store ID for testbed state atoms.
Variables ¶
This section is empty.
Functions ¶
func RunTypeScriptTest ¶
func RunTypeScriptTest( ctx context.Context, le *logrus.Entry, pluginID string, tsFilePath string, ) (success bool, errorMsg string, err error)
RunTypeScriptTest builds a wrapper around a TypeScript test file and runs it in QuickJS. The test file should export a default async function with signature:
export default async function main( backendAPI: BackendAPI, abortSignal: AbortSignal, testbedRoot: TestbedRoot, )
The wrapper automatically sets up the resources client, testbed root, and reports test results via MarkTestResult. This is the recommended way to run TypeScript E2E tests.
Example test file (my-test.ts):
import type { BackendAPI } from '@aptre/bldr-sdk'
import type { TestbedRoot } from '../../../sdk/testbed/testbed.js'
export default async function main(
backendAPI: BackendAPI,
abortSignal: AbortSignal,
testbedRoot: TestbedRoot,
) {
// Create a world engine
using engine = await testbedRoot.createWorld('my-engine')
// Do your test logic here
const ws = engine.asWorldState()
using obj = await ws.createObject('test-key', {})
console.log('Test passed!')
}
Usage in Go test:
func TestMyFeature(t *testing.T) {
ctx := context.Background()
log := logrus.New()
log.SetLevel(logrus.DebugLevel)
le := logrus.NewEntry(log)
success, errorMsg, err := RunTypeScriptTest(ctx, le, "my-test", "my-test.ts")
if err != nil {
t.Fatal(err)
}
if !success {
t.Fatalf("test failed: %s", errorMsg)
}
}
func SetupResourceClient ¶
func SetupResourceClient(ctx context.Context, t *testing.T, tb *world_testbed.Testbed) (*resource_client.Client, func())
SetupResourceClient creates pipes, muxed connections, and resource client for testing. Returns the resource client and a cleanup function.
func SetupTestbedWithClient ¶
func SetupTestbedWithClient(ctx context.Context, t *testing.T) (*world_testbed.Testbed, *resource_client.Client, func())
SetupTestbedWithClient creates a hydra testbed and resource client for testing. Returns the testbed, resource client, and a cleanup function.
Types ¶
type BrowserTestServer
deprecated
type BrowserTestServer = browser_testbed.LayoutServer
BrowserTestServer provides a WebSocket-based RPC server for browser E2E tests. It exposes a LayoutHost service that can be connected to from browser tests.
Deprecated: Use browser_testbed.LayoutServer directly instead.
func NewBrowserTestServer
deprecated
func NewBrowserTestServer(le *logrus.Entry, _ any) *BrowserTestServer
NewBrowserTestServer creates a new BrowserTestServer.
Deprecated: Use browser_testbed.NewLayoutServer directly instead.
type LayoutServerHelper ¶
type LayoutServerHelper struct {
*browser_testbed.LayoutServer
}
LayoutServerHelper provides helper methods for working with LayoutServer in tests.
func NewLayoutServerHelper ¶
func NewLayoutServerHelper(server *browser_testbed.LayoutServer) *LayoutServerHelper
NewLayoutServerHelper creates a new LayoutServerHelper wrapping a LayoutServer.
func (*LayoutServerHelper) SetupInitialLayoutModel ¶
func (h *LayoutServerHelper) SetupInitialLayoutModel()
SetupInitialLayoutModel sets up a standard initial layout model for tests.
func (*LayoutServerHelper) WaitForLayoutUpdateWithTimeout ¶
func (h *LayoutServerHelper) WaitForLayoutUpdateWithTimeout(ctx context.Context) (*s4wave_layout.LayoutModel, error)
WaitForLayoutUpdateWithTimeout waits for a layout update with context timeout handling.
type TestbedResourceServer ¶
type TestbedResourceServer struct {
// contains filtered or unexported fields
}
TestbedResourceServer implements the TestbedResourceService. It acts as the root resource for creating world engine resources.
func NewTestbedResourceServer ¶
func NewTestbedResourceServer(ctx context.Context, le *logrus.Entry, bus bus.Bus, volumeID string, bucketID string) *TestbedResourceServer
NewTestbedResourceServer creates a new TestbedResourceServer. ctx is used for long-lived resources like BusEngine instances.
func (*TestbedResourceServer) AccessStateAtom ¶
func (s *TestbedResourceServer) AccessStateAtom( ctx context.Context, req *s4wave_testbed.AccessStateAtomRequest, ) (*s4wave_testbed.AccessStateAtomResponse, error)
AccessStateAtom accesses a state atom resource.
func (*TestbedResourceServer) CreateWorld ¶
func (s *TestbedResourceServer) CreateWorld(ctx context.Context, req *s4wave_testbed.CreateWorldRequest) (*s4wave_testbed.CreateWorldResponse, error)
CreateWorld creates a new world engine and returns an EngineResource.
func (*TestbedResourceServer) GetMux ¶
func (s *TestbedResourceServer) GetMux() srpc.Invoker
GetMux returns the mux for this root resource.
func (*TestbedResourceServer) MarkTestResult ¶
func (s *TestbedResourceServer) MarkTestResult(ctx context.Context, req *s4wave_testbed.MarkTestResultRequest) (*s4wave_testbed.MarkTestResultResponse, error)
MarkTestResult marks the test result (success or failure).
func (*TestbedResourceServer) Register ¶
func (s *TestbedResourceServer) Register(mux srpc.Mux) error
Register registers the server with the mux.
func (*TestbedResourceServer) WaitForTestResult ¶
func (s *TestbedResourceServer) WaitForTestResult(ctx context.Context) (success bool, errorMsg string, err error)
WaitForTestResult waits for the test to complete and returns the result. This is useful for the Go test harness to wait for the TypeScript test to finish.
type TestbedWithQuickJS ¶
type TestbedWithQuickJS struct {
// Testbed is the underlying bldr testbed
Testbed *testbed.Testbed
// Bus is the controller bus
Bus bus.Bus
// ResourceServer is the testbed resource server
ResourceServer *TestbedResourceServer
// VolumeID is the volume ID used for world engines
VolumeID string
// BucketID is the bucket ID used for world engines
BucketID string
// Logger is the logger entry
Logger *logrus.Entry
// QuickJSHost is the QuickJS plugin host controller
QuickJSHost *plugin_host_wazero_quickjs.Controller
// QuickJSHostRef is the reference to release
QuickJSHostRef directive.Reference
// ObjectTypeCtrlRelease releases the ObjectType controller
ObjectTypeCtrlRelease func()
}
TestbedWithQuickJS wraps a bldr testbed with QuickJS plugin host and resource server setup.
func SetupTestbedWithQuickJS ¶
SetupTestbedWithQuickJS creates a testbed with QuickJS plugin host and resource server. This is useful for e2e tests that need to run TypeScript code via QuickJS.
Returns the configured testbed and an error if setup fails.
func (*TestbedWithQuickJS) LoadQuickJSPlugin ¶
func (t *TestbedWithQuickJS) LoadQuickJSPlugin( ctx context.Context, pluginID string, scriptContents string, ) (directive.Reference, error)
LoadQuickJSPlugin loads a QuickJS plugin with the given script contents. Calls QuickJSHost.ExecutePlugin directly (bypassing the scheduler) so the testbed's ResourceServer is used as the plugin's resource root. Returns a release function.
func (*TestbedWithQuickJS) Release ¶
func (t *TestbedWithQuickJS) Release()
Release releases the testbed and all associated resources.