Development
Testing
Unit testing resource logic with node:test.
Unit testing
Resource lifecycle methods (create, read, update, delete) are plain async functions. Test them directly — no gRPC server needed.
import { test } from "node:test";
import assert from "node:assert/strict";
import { MyCloudServer } from "../src/resources/server.js";
import { Diagnostics } from "terrably";
import type { CreateContext, ReadContext } from "terrably";
// Minimal mock provider
const mockProvider = { apiBase: "https://api.mycloud.example" } as any;
test("create returns state with id", async () => {
const resource = new MyCloudServer(mockProvider);
const ctx: CreateContext = {
diagnostics: new Diagnostics(),
typeName: "mycloud_server",
};
const result = await resource.create(ctx, { name: "test", region: "us-east-1" });
assert.ok(result["id"], "should have an id");
assert.equal(result["name"], "test");
assert.ok(!ctx.diagnostics.hasErrors());
});
test("read returns null for 404", async () => {
const resource = new MyCloudServer(mockProvider);
const ctx: ReadContext = {
diagnostics: new Diagnostics(),
typeName: "mycloud_server",
};
const result = await resource.read(ctx, { id: "nonexistent-id" });
assert.strictEqual(result, null);
});Running tests
# Build first so TypeScript compiles
pnpm exec tsc
node --test dist/tests/*.test.jsOr via the package script –
pnpm run testTesting with a real local API
Start your API server before running tests –
node dist/api-server/index.js &
API_PID=$!
node --test dist/tests/server.test.js
kill $API_PIDLast updated on