Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
44cc4d3
initial step of refactoring builder API to be created by a factory + …
seefeldb Jun 6, 2025
8c4f7fa
deno.lock change, not sure this is right
seefeldb Jun 6, 2025
2a712d9
let's just go back to `any` here, this is wonky
seefeldb Jun 6, 2025
2ac3fe2
builder/interface.ts and builder/schema-to-ts.ts are now together ent…
seefeldb Jun 6, 2025
27de921
lots of types fixes for previous change
seefeldb Jun 6, 2025
d8837ba
more type fixes
seefeldb Jun 6, 2025
14b319b
remove this syntax for now
seefeldb Jun 6, 2025
82ca353
remove extraneous parameter for createBuilder
seefeldb Jun 6, 2025
9c614de
add back ability to set schema with cell/opaqueRef
seefeldb Jun 7, 2025
f2fe26a
fix more tests
seefeldb Jun 7, 2025
79ef937
export opaqueRef directly still, for internal use outside of recipes
seefeldb Jun 7, 2025
6074063
partially fix test
seefeldb Jun 7, 2025
c630bc1
import type with `type` annotation
seefeldb Jun 9, 2025
6f97b4d
interface is now truly just the public interface. users should only i…
seefeldb Jun 9, 2025
d6398e3
separated imports in other places
seefeldb Jun 9, 2025
4d9e789
fix misaligned exports
seefeldb Jun 9, 2025
f11897e
removed Mutable from interface
seefeldb Jun 9, 2025
255a1cb
change all recipes to import from /interface.
seefeldb Jun 9, 2025
70139fe
redo use of SchemaWithoutCell in the right places, this fixed the tests
seefeldb Jun 9, 2025
0206774
need Mutable<> after all, so duplicating here to keep interface.ts an…
seefeldb Jun 9, 2025
fe6edc7
recipe also needs SchemaWithoutCell
seefeldb Jun 9, 2025
65c14ca
and recipe needs that also for the recipe function!
seefeldb Jun 9, 2025
1300446
fix recipes
seefeldb Jun 9, 2025
2a226d6
move getRecipeEnvironment to public environment
seefeldb Jun 9, 2025
5c4f4b7
revert to original deno.lock
seefeldb Jun 9, 2025
2bb1e50
also exports constants via builder!
seefeldb Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix more tests
  • Loading branch information
seefeldb committed Jun 9, 2025
commit f2fe26a38f9499b93f21c49b7f04c035814779b7
31 changes: 21 additions & 10 deletions packages/builder/test/opaque-ref-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import { afterEach, beforeEach, describe, it } from "@std/testing/bdd";
import { expect } from "@std/expect";
import { recipe } from "../src/index.ts";
import { createBuilder } from "../src/index.ts";
import { popFrame, pushFrame } from "../src/recipe.ts";
import { opaqueRef } from "../src/opaque-ref.ts";
import type { Frame, JSONSchema } from "../src/types.ts";
import { Runtime } from "@commontools/runner";

describe("OpaqueRef Schema Support", () => {
let frame: Frame;
let runtime: Runtime;
let recipe: ReturnType<typeof createBuilder>["recipe"];
let cell: ReturnType<typeof createBuilder>["cell"];

beforeEach(() => {
// Setup frame for the test
frame = pushFrame();

// Set up runtime and builder
runtime = new Runtime({
storageUrl: "volatile://",
});
const builder = createBuilder(runtime);
({ recipe, cell } = builder);
});

afterEach(() => {
afterEach(async () => {
popFrame(frame);
await runtime?.dispose();
});

describe("Schema Setting and Retrieval", () => {
Expand All @@ -29,7 +40,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref
const ref = opaqueRef<{ name: string; age: number }>(undefined, schema);
const ref = cell<{ name: string; age: number }>(undefined, schema);

// Export the ref and check the schema is included
const exported = ref.export();
Expand All @@ -54,7 +65,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref
const ref = opaqueRef<{ name: string; details: { age: number } }>(
const ref = cell<{ name: string; details: { age: number } }>(
undefined,
rootSchema,
).key("details");
Expand All @@ -80,7 +91,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref
const ref = opaqueRef<{ name: string; age: number }>(undefined, schema);
const ref = cell<{ name: string; age: number }>(undefined, schema);

// Get a child property
const nameRef = ref.key("name");
Expand Down Expand Up @@ -111,7 +122,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref with an array
const ref = opaqueRef<{ items: Array<{ id: number; text: string }> }>(
const ref = cell<{ items: Array<{ id: number; text: string }> }>(
undefined,
schema,
);
Expand Down Expand Up @@ -153,7 +164,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref with nested objects
const ref = opaqueRef<{
const ref = cell<{
user: {
profile: {
name: string;
Expand Down Expand Up @@ -192,7 +203,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref with nested objects
const ref = opaqueRef<{
const ref = cell<{
details: {
name: string;
age: number;
Expand Down Expand Up @@ -232,7 +243,7 @@ describe("OpaqueRef Schema Support", () => {
} as const satisfies JSONSchema;

// Create an opaque ref with nested objects, and a property that isn't in the schema
const ref = opaqueRef<{
const ref = cell<{
details: {
name: string;
age: number;
Expand Down
72 changes: 44 additions & 28 deletions packages/html/test/html-recipes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, it, afterEach } from "@std/testing/bdd";
import { h, render, VNode } from "../src/index.ts";
import { lift, recipe, str, UI } from "@commontools/builder";
import { createBuilder, UI } from "@commontools/builder";
import { Runtime } from "@commontools/runner";
import * as assert from "./assert.ts";
import { JSDOM } from "jsdom";
Expand All @@ -9,6 +9,9 @@ describe("recipes with HTML", () => {
let dom: JSDOM;
let document: Document;
let runtime: Runtime;
let lift: ReturnType<typeof createBuilder>["lift"];
let recipe: ReturnType<typeof createBuilder>["recipe"];
let str: ReturnType<typeof createBuilder>["str"];

beforeEach(() => {
// Set up a fresh JSDOM instance for each test
Expand All @@ -25,6 +28,9 @@ describe("recipes with HTML", () => {
runtime = new Runtime({
storageUrl: "volatile://"
});

const builder = createBuilder(runtime);
({ lift, recipe, str } = builder);
});

afterEach(async () => {
Expand All @@ -39,9 +45,11 @@ describe("recipes with HTML", () => {
},
);

const space = "test";
const resultCell = runtime.documentMap.getDoc(undefined, "simple-ui-result", space);
const result = runtime.runner.run(simpleRecipe, { value: 5 }, resultCell);
const result = runtime.run(
simpleRecipe,
{ value: 5 },
runtime.documentMap.getDoc(undefined, "simple-ui-result", "test")
);

await runtime.idle();
const resultValue = result.get();
Expand Down Expand Up @@ -81,15 +89,17 @@ describe("recipes with HTML", () => {
};
});

const space = "test";
const resultCell = runtime.documentMap.getDoc(undefined, "todo-list-result", space);
const result = runtime.runner.run(todoList, {
title: "test",
items: [
{ title: "item 1", done: false },
{ title: "item 2", done: true },
],
}, resultCell);
const result = runtime.run(
todoList,
{
title: "test",
items: [
{ title: "item 1", done: false },
{ title: "item 2", done: true },
],
},
runtime.documentMap.getDoc(undefined, "todo-list-result", "test")
);

await runtime.idle();

Expand Down Expand Up @@ -121,15 +131,17 @@ describe("recipes with HTML", () => {
return { [UI]: h("div", null, summaryUI as any) };
});

const space = "test";
const resultCell = runtime.documentMap.getDoc(undefined, "nested-todo-result", space);
const result = runtime.runner.run(todoList, {
title: { name: "test" },
items: [
{ title: "item 1", done: false },
{ title: "item 2", done: true },
],
}, resultCell);
const result = runtime.run(
todoList,
{
title: { name: "test" },
items: [
{ title: "item 1", done: false },
{ title: "item 2", done: true },
],
},
runtime.documentMap.getDoc(undefined, "nested-todo-result", "test")
);

await runtime.idle();

Expand All @@ -146,9 +158,11 @@ describe("recipes with HTML", () => {
return { [UI]: h("div", null, str`Hello, ${name}!`) };
});

const space = "test";
const resultCell = runtime.documentMap.getDoc(undefined, "str-recipe-result", space);
const result = runtime.runner.run(strRecipe, { name: "world" }, resultCell);
const result = runtime.run(
strRecipe,
{ name: "world" },
runtime.documentMap.getDoc(undefined, "str-recipe-result", "test")
);

await runtime.idle();

Expand Down Expand Up @@ -185,9 +199,11 @@ describe("recipes with HTML", () => {
),
}));

const space = "test";
const resultCell = runtime.documentMap.getDoc(undefined, "nested-map-result", space);
const result = runtime.runner.run(nestedMapRecipe, data, resultCell);
const result = runtime.run(
nestedMapRecipe,
data,
runtime.documentMap.getDoc(undefined, "nested-map-result", "test")
);

await runtime.idle();

Expand Down