@joiner-platform/cli 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/tile-creator/references/cli.md +4 -3
- package/src/commands/init/scaffold.ts +2 -9
- package/src/commands/init/sdk-tarball-url.generated.ts +2 -2
- package/src/commands/init/template-names.ts +18 -0
- package/src/commands/schema-input-example.ts +142 -14
- package/bundled-resources/poe-tile-templates/coverage.config.json +0 -6
- package/bundled-resources/poe-tile-templates/index.ts +0 -27
- package/bundled-resources/poe-tile-templates/package.json +0 -31
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +0 -10
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +0 -57
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +0 -52
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +0 -7
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +0 -288
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +0 -132
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +0 -30
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +0 -397
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +0 -131
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +0 -166
- package/bundled-resources/poe-tile-templates/tests/doctor-launcher.test.ts +0 -48
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +0 -67
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +0 -106
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +0 -103
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +0 -67
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +0 -85
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +0 -69
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +0 -73
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +0 -54
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +0 -70
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +0 -85
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +0 -278
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +0 -27
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +0 -99
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +0 -23
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +0 -84
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +0 -56
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +0 -129
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +0 -90
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { afterEach, expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
chmodSync,
|
|
4
|
-
copyFileSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
mkdtempSync,
|
|
7
|
-
realpathSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
writeFileSync,
|
|
10
|
-
} from "node:fs";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
|
|
14
|
-
const roots: string[] = [];
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
for (const root of roots.splice(0))
|
|
17
|
-
rmSync(root, { recursive: true, force: true });
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("doctor runs the npm CLI's poe-tiles bin when only Bun is installed", () => {
|
|
21
|
-
// A tile scaffolded with `bunx @joiner-platform/cli create` has no
|
|
22
|
-
// poe-tiles on PATH and no monorepo checkout around it.
|
|
23
|
-
const root = realpathSync(mkdtempSync(join(tmpdir(), "doctor-launcher-")));
|
|
24
|
-
roots.push(root);
|
|
25
|
-
const scripts = join(root, "tile/scripts");
|
|
26
|
-
mkdirSync(scripts, { recursive: true });
|
|
27
|
-
copyFileSync(
|
|
28
|
-
join(import.meta.dir, "../base/scripts/doctor.sh"),
|
|
29
|
-
join(scripts, "doctor.sh"),
|
|
30
|
-
);
|
|
31
|
-
const bin = join(root, "bin");
|
|
32
|
-
mkdirSync(bin);
|
|
33
|
-
for (const name of ["bun", "bunx"]) {
|
|
34
|
-
writeFileSync(join(bin, name), `#!/bin/sh\necho "${name} $*"\n`);
|
|
35
|
-
chmodSync(join(bin, name), 0o755);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result = Bun.spawnSync(["bash", join(scripts, "doctor.sh")], {
|
|
39
|
-
env: { PATH: `${bin}:/usr/bin:/bin` },
|
|
40
|
-
stdout: "pipe",
|
|
41
|
-
stderr: "pipe",
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(result.stderr.toString()).toBe("");
|
|
45
|
-
expect(result.stdout.toString().trim()).toBe(
|
|
46
|
-
`bunx --bun --package @joiner-platform/cli poe-tiles doctor --cwd ${join(root, "tile")}`,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
/** Exercise the emitted manager example with a non-empty app schema and handler. */
|
|
6
|
-
export function writeCustomizedManagerFixture({
|
|
7
|
-
dir,
|
|
8
|
-
managerExample,
|
|
9
|
-
}: {
|
|
10
|
-
dir: string;
|
|
11
|
-
managerExample: string;
|
|
12
|
-
}): void {
|
|
13
|
-
mkdirSync(dir, { recursive: true });
|
|
14
|
-
writeFileSync(
|
|
15
|
-
join(dir, "schema.ts"),
|
|
16
|
-
`
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
import { defineSchema, table } from "joiner-sdk/v1/backend.js";
|
|
19
|
-
export const tileSchema = defineSchema({
|
|
20
|
-
schemaVersion: 1,
|
|
21
|
-
tables: { moves: { schema: table(z.object({ count: z.number() })) } },
|
|
22
|
-
mutators: { recordMove: { input: z.object({ count: z.number() }) } },
|
|
23
|
-
});
|
|
24
|
-
`,
|
|
25
|
-
);
|
|
26
|
-
writeFileSync(join(dir, "hooks.ts"), "export const tileHooks = {};\n");
|
|
27
|
-
writeFileSync(
|
|
28
|
-
join(dir, "mutators.ts"),
|
|
29
|
-
`
|
|
30
|
-
import type { InferMutatorHandlers } from "joiner-sdk/v1/client.js";
|
|
31
|
-
import { tileSchema } from "./schema";
|
|
32
|
-
export const tileMutators: InferMutatorHandlers<typeof tileSchema> = {
|
|
33
|
-
recordMove: async (ctx, input) => {
|
|
34
|
-
await ctx.table("moves").set({ itemKey: ctx.userId, value: input });
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
`,
|
|
38
|
-
);
|
|
39
|
-
writeFileSync(
|
|
40
|
-
join(dir, "manager.test.ts"),
|
|
41
|
-
managerExample +
|
|
42
|
-
`
|
|
43
|
-
test("the customized app mutation survives the manager example", async () => {
|
|
44
|
-
const h = await createPoeTileInManagerTestHarness({
|
|
45
|
-
tile: { typeId: "customized-app", clientConfig, backendConfig },
|
|
46
|
-
users: ["alice", "bob"],
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
await (await h.tile("alice").poe.store.mutate.recordMove({ count: 7 })).confirmed;
|
|
50
|
-
const bob = h.tile("bob").poe.store;
|
|
51
|
-
await bob.pull();
|
|
52
|
-
const result = await bob.query((ctx) => ctx.table("moves").get("alice"));
|
|
53
|
-
expect(result).toEqual({ count: 7 });
|
|
54
|
-
const count: number | undefined = result?.count;
|
|
55
|
-
expect(count).toBe(7);
|
|
56
|
-
await h.removeUser({ userId: "bob", removedBy: "alice" });
|
|
57
|
-
const alice = h.tile("alice").poe.store;
|
|
58
|
-
await alice.pull();
|
|
59
|
-
expect(await alice.query(async (ctx) => (await ctx.table("$users").get("bob"))?.removedAt)).toBeDefined();
|
|
60
|
-
await h.addUser({ userId: "bob", addedBy: "alice" });
|
|
61
|
-
await bob.pull();
|
|
62
|
-
expect(await bob.query((ctx) => ctx.table("moves").get("alice"))).toEqual({ count: 7 });
|
|
63
|
-
} finally { h.dispose(); }
|
|
64
|
-
});
|
|
65
|
-
`,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { defineBackendConfig, defineSchema, table } from "joiner-sdk/v1/backend.js";
|
|
4
|
-
import { defineClientConfig, type InferMutatorHandlers, type InferSyncedStoreClient, type PoeAPI } from "joiner-sdk/v1/client.js";
|
|
5
|
-
import { createPoeTileTestHarness, createPoeTileInManagerTestHarness, waitForKeyMatch } from "joiner-sdk/v1/test-utils.js";
|
|
6
|
-
import { tileSchema } from "../synced-store/schema";
|
|
7
|
-
|
|
8
|
-
// Extend the installed starter, rather than checking a schema unrelated to it.
|
|
9
|
-
const extendedSchema = defineSchema({
|
|
10
|
-
...tileSchema,
|
|
11
|
-
tables: {
|
|
12
|
-
...tileSchema.tables,
|
|
13
|
-
players: {
|
|
14
|
-
schema: table(z.object({
|
|
15
|
-
userId: z.string(),
|
|
16
|
-
mark: z.enum(["X", "O"]).nullable(),
|
|
17
|
-
score: z.number(),
|
|
18
|
-
})),
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
mutators: {
|
|
22
|
-
setScore: { input: z.object({ score: z.number() }) },
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
type ExtendedSchema = typeof extendedSchema;
|
|
26
|
-
const mutators: InferMutatorHandlers<ExtendedSchema> = {
|
|
27
|
-
setScore: async (ctx, { score }) => {
|
|
28
|
-
await ctx.table("players").set({
|
|
29
|
-
itemKey: ctx.userId,
|
|
30
|
-
value: { userId: ctx.userId, mark: null, score },
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
const backendConfig = defineBackendConfig({ schema: extendedSchema, mutators });
|
|
35
|
-
function createStore() {
|
|
36
|
-
return createPoeTileTestHarness<ExtendedSchema>({ store: { backendConfig } });
|
|
37
|
-
}
|
|
38
|
-
type TodoStore = Awaited<ReturnType<ReturnType<typeof createStore>["createClient"]>>["store"];
|
|
39
|
-
function getPlayer(store: TodoStore, userId: string) {
|
|
40
|
-
return store.query((ctx) => ctx.table("players").get(userId));
|
|
41
|
-
}
|
|
42
|
-
type Player = NonNullable<Awaited<ReturnType<typeof getPlayer>>>;
|
|
43
|
-
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends
|
|
44
|
-
(<T>() => T extends B ? 1 : 2) ? true : false;
|
|
45
|
-
type PlayerRow = { userId: string; mark: "X" | "O" | null; score: number };
|
|
46
|
-
// Store reads return rows whose top-level properties are readonly.
|
|
47
|
-
const exactRow: Equal<Player, { readonly userId: string; readonly mark: "X" | "O" | null; readonly score: number }> = true;
|
|
48
|
-
const exactInput: Equal<Parameters<TodoStore["mutate"]["setScore"]>[0], { score: number }> = true;
|
|
49
|
-
void exactRow;
|
|
50
|
-
void exactInput;
|
|
51
|
-
|
|
52
|
-
// Negative checks without a suppression comment, which the scaffold's
|
|
53
|
-
// type-check rejects: each type is false when the argument is refused.
|
|
54
|
-
type Accepts<Param, Arg> = [Arg] extends [Param] ? true : false;
|
|
55
|
-
// The extended mutator accepts a numeric score, not text.
|
|
56
|
-
const rejectsTextScore: Accepts<Parameters<TodoStore["mutate"]["setScore"]>[0], { score: "high" }> = false;
|
|
57
|
-
// Readers receive transactions, not store instances.
|
|
58
|
-
type ReaderContext = Parameters<Parameters<TodoStore["query"]>[0]>[0];
|
|
59
|
-
const rejectsTransactionAsStore: Accepts<Parameters<typeof getPlayer>[0], ReaderContext> = false;
|
|
60
|
-
void rejectsTextScore;
|
|
61
|
-
void rejectsTransactionAsStore;
|
|
62
|
-
|
|
63
|
-
test("installed manager harness preserves the supplied config's Poe client type", async () => {
|
|
64
|
-
const h = await createPoeTileInManagerTestHarness({
|
|
65
|
-
tile: {
|
|
66
|
-
typeId: "typed-manager",
|
|
67
|
-
clientConfig: defineClientConfig<ExtendedSchema>({ schemaVersion: 1, mutators }),
|
|
68
|
-
backendConfig,
|
|
69
|
-
},
|
|
70
|
-
users: ["alice", "bob"],
|
|
71
|
-
});
|
|
72
|
-
try {
|
|
73
|
-
const alice = h.tile("alice").poe;
|
|
74
|
-
const exactClient: Equal<typeof alice, PoeAPI<InferSyncedStoreClient<ExtendedSchema>>> = true;
|
|
75
|
-
void exactClient;
|
|
76
|
-
await (await alice.store.mutate.setScore({ score: 4 })).confirmed;
|
|
77
|
-
const bob = h.tile("bob").poe.store;
|
|
78
|
-
const matched = await waitForKeyMatch(bob, {
|
|
79
|
-
table: "players", key: "alice", match: (player) => player.score === 4,
|
|
80
|
-
});
|
|
81
|
-
const exactMatch: Equal<typeof matched, PlayerRow> = true;
|
|
82
|
-
void exactMatch;
|
|
83
|
-
expect(await getPlayer(bob, "alice")).toEqual({ userId: "alice", mark: null, score: 4 });
|
|
84
|
-
} finally {
|
|
85
|
-
h.dispose();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("an extended scaffold mutator keeps exact input and row types through installed harness clients", async () => {
|
|
90
|
-
const harness = createStore();
|
|
91
|
-
try {
|
|
92
|
-
const { store: alice } = await harness.createClient({ userId: "alice" });
|
|
93
|
-
const { store: bob } = await harness.createClient({ userId: "bob" });
|
|
94
|
-
const result = await alice.mutate.setScore({ score: 3 });
|
|
95
|
-
await result.confirmed;
|
|
96
|
-
await waitForKeyMatch(bob, {
|
|
97
|
-
table: "players", key: "alice", match: (player) => player.score === 3,
|
|
98
|
-
});
|
|
99
|
-
expect(await getPlayer(bob, "alice")).toEqual({ userId: "alice", mark: null, score: 3 });
|
|
100
|
-
// A new client reads authoritative data, not the writer's optimistic overlay.
|
|
101
|
-
const { store: reopened } = await harness.createClient({ userId: "observer" });
|
|
102
|
-
expect(await getPlayer(reopened, "alice")).toEqual({ userId: "alice", mark: null, score: 3 });
|
|
103
|
-
} finally {
|
|
104
|
-
harness.dispose();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@playwright/test";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import {
|
|
4
|
-
TestServer,
|
|
5
|
-
waitForBlobFrame,
|
|
6
|
-
} from "joiner-sdk/v1/test-utils/playwright.js";
|
|
7
|
-
import { openTwoUserTile, waitForVisualReady } from "./multiplayer";
|
|
8
|
-
|
|
9
|
-
test("visual readiness ignores looping decoration but bounds unfinished finite animations", async ({
|
|
10
|
-
page,
|
|
11
|
-
}) => {
|
|
12
|
-
await page.setContent('<main id="ready">Ready</main>');
|
|
13
|
-
await page.evaluate(() => {
|
|
14
|
-
const element = document.querySelector("main")!;
|
|
15
|
-
element.animate([{ opacity: 1 }, { opacity: 0.8 }], {
|
|
16
|
-
duration: 1000,
|
|
17
|
-
iterations: Infinity,
|
|
18
|
-
});
|
|
19
|
-
const finite = element.animate(
|
|
20
|
-
[{ transform: "scale(1)" }, { transform: "scale(.9)" }],
|
|
21
|
-
{ duration: 1000, iterations: 2 },
|
|
22
|
-
);
|
|
23
|
-
finite.pause();
|
|
24
|
-
});
|
|
25
|
-
// The browser predicate can consume the deadline before Playwright formats
|
|
26
|
-
// our diagnostic. Assert bounded rejection, then successful recovery below.
|
|
27
|
-
await expect(
|
|
28
|
-
waitForVisualReady({
|
|
29
|
-
frame: page.mainFrame(),
|
|
30
|
-
readySelector: "#ready",
|
|
31
|
-
timeoutMs: 100,
|
|
32
|
-
}),
|
|
33
|
-
).rejects.toThrow();
|
|
34
|
-
await page.evaluate(() => {
|
|
35
|
-
for (const animation of document.getAnimations()) {
|
|
36
|
-
if (Number.isFinite(animation.effect?.getComputedTiming().endTime))
|
|
37
|
-
animation.finish();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
await waitForVisualReady({
|
|
41
|
-
frame: page.mainFrame(),
|
|
42
|
-
readySelector: "#ready",
|
|
43
|
-
timeoutMs: 1000,
|
|
44
|
-
});
|
|
45
|
-
expect(
|
|
46
|
-
await page.evaluate(() =>
|
|
47
|
-
document
|
|
48
|
-
.getAnimations()
|
|
49
|
-
.some((animation) => animation.playState === "running"),
|
|
50
|
-
),
|
|
51
|
-
).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("both members are admitted before either client waits for a shared readiness state", async ({
|
|
55
|
-
browser,
|
|
56
|
-
}) => {
|
|
57
|
-
const server = new TestServer();
|
|
58
|
-
await server.start();
|
|
59
|
-
try {
|
|
60
|
-
const tileTypeId = "multiplayer-fixture-probe";
|
|
61
|
-
await server.registerTile({
|
|
62
|
-
typeId: tileTypeId,
|
|
63
|
-
content: {
|
|
64
|
-
type: "directory",
|
|
65
|
-
dir: fileURLToPath(new URL("../dist", import.meta.url)),
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
const users = await openTwoUserTile({
|
|
69
|
-
server,
|
|
70
|
-
browser,
|
|
71
|
-
tileTypeId,
|
|
72
|
-
instanceId: crypto.randomUUID(),
|
|
73
|
-
readySelector:
|
|
74
|
-
'[data-testid="connected-player-count"]:text-is("2 connected players")',
|
|
75
|
-
contextOptions: {
|
|
76
|
-
viewport: { width: 390, height: 760 },
|
|
77
|
-
colorScheme: "dark",
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
try {
|
|
81
|
-
expect(users.alice.page.viewportSize()).toEqual({
|
|
82
|
-
width: 390,
|
|
83
|
-
height: 760,
|
|
84
|
-
});
|
|
85
|
-
expect(users.alice.context).not.toBe(users.bob.context);
|
|
86
|
-
expect(
|
|
87
|
-
new URL(users.alice.page.url()).searchParams.get("use_indexed_db"),
|
|
88
|
-
).toBe("1");
|
|
89
|
-
await users.alice.page.reload();
|
|
90
|
-
const returned = await waitForBlobFrame(users.alice.page);
|
|
91
|
-
await expect(
|
|
92
|
-
returned.locator('[data-testid="connected-player-count"]'),
|
|
93
|
-
).toHaveText("2 connected players");
|
|
94
|
-
await expect(
|
|
95
|
-
users.bob.frame.locator('[data-testid="connected-player-count"]'),
|
|
96
|
-
).toHaveText("2 connected players");
|
|
97
|
-
} finally {
|
|
98
|
-
await users.close();
|
|
99
|
-
}
|
|
100
|
-
} finally {
|
|
101
|
-
await server.closeAndWaitForTesting();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { copyFileSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import type { TemplateName } from "../..";
|
|
6
|
-
|
|
7
|
-
/** Demo-specific assertions belong to scaffold maintenance, not generated apps. */
|
|
8
|
-
export function installStarterDemoTests(
|
|
9
|
-
appDir: string,
|
|
10
|
-
template: TemplateName,
|
|
11
|
-
) {
|
|
12
|
-
copyFileSync(
|
|
13
|
-
join(import.meta.dir, "starter-demo", `${template}.tsx.txt`),
|
|
14
|
-
join(appDir, "ui/starter-demo.test.happydom.tsx"),
|
|
15
|
-
);
|
|
16
|
-
copyFileSync(
|
|
17
|
-
join(import.meta.dir, "starter-demo/seating.ts.txt"),
|
|
18
|
-
join(appDir, "synced-store/starter-demo.test.ts"),
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Replace the app-owned schema without editing any generated tests. */
|
|
23
|
-
export function replaceStarterSchema(appDir: string, template: TemplateName) {
|
|
24
|
-
rmSync(join(appDir, "ui/starter-demo.test.happydom.tsx"));
|
|
25
|
-
rmSync(join(appDir, "synced-store/starter-demo.test.ts"));
|
|
26
|
-
const extension = ["react", "preact", "solidjs"].includes(template)
|
|
27
|
-
? "tsx"
|
|
28
|
-
: "ts";
|
|
29
|
-
for (const [path, edits] of [
|
|
30
|
-
[
|
|
31
|
-
"synced-store/schema.ts",
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
"players: { schema: table(playerRow) }",
|
|
35
|
-
"participants: { schema: table(playerRow) }",
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
'mark: z.enum(["X", "O"]).nullable(),',
|
|
39
|
-
'symbol: z.enum(["X", "O"]).nullable(),\n\tscore: z.number(),',
|
|
40
|
-
],
|
|
41
|
-
],
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
"synced-store/hooks.ts",
|
|
45
|
-
[
|
|
46
|
-
['table("players")', 'table("participants")'],
|
|
47
|
-
["player.mark", "player.symbol"],
|
|
48
|
-
[
|
|
49
|
-
"value: { userId, mark },",
|
|
50
|
-
"value: { userId, symbol: mark, score: 0 },",
|
|
51
|
-
],
|
|
52
|
-
],
|
|
53
|
-
],
|
|
54
|
-
[`ui/App.${extension}`, [['table("players")', 'table("participants")']]],
|
|
55
|
-
] as const) {
|
|
56
|
-
const file = join(appDir, path);
|
|
57
|
-
let source = readFileSync(file, "utf8");
|
|
58
|
-
for (const [before, after] of edits) {
|
|
59
|
-
assert(
|
|
60
|
-
source.includes(before),
|
|
61
|
-
`Missing starter extension point: ${path}: ${before}`,
|
|
62
|
-
);
|
|
63
|
-
source = source.replaceAll(before, after);
|
|
64
|
-
}
|
|
65
|
-
writeFileSync(file, source);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { mountApp } from "./App";
|
|
4
|
-
import { createPoeTileTestHarness, tick } from "joiner-sdk/v1/test-utils.js";
|
|
5
|
-
import type { AppReadContext } from "../client";
|
|
6
|
-
import { tileBackendConfig } from "../synced-store/backend-config";
|
|
7
|
-
import type { AppSchema } from "../synced-store/schema";
|
|
8
|
-
import { createTestAppProps } from "../tests/app-test-props";
|
|
9
|
-
|
|
10
|
-
async function waitFor(
|
|
11
|
-
assertion: () => void,
|
|
12
|
-
timeoutMs = 2_000,
|
|
13
|
-
): Promise<void> {
|
|
14
|
-
const startedAt = Date.now();
|
|
15
|
-
while (true) {
|
|
16
|
-
try {
|
|
17
|
-
assertion();
|
|
18
|
-
return;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
if (Date.now() - startedAt >= timeoutMs) throw error;
|
|
21
|
-
await tick();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
test("renders with a real two-client store and configured DOM matchers", async () => {
|
|
27
|
-
const harness = createPoeTileTestHarness<AppSchema>({
|
|
28
|
-
store: { backendConfig: tileBackendConfig },
|
|
29
|
-
});
|
|
30
|
-
let container: HTMLElement = document.createElement("div");
|
|
31
|
-
try {
|
|
32
|
-
const aliceClient = await harness.createClient({ userId: "alice" });
|
|
33
|
-
const { store: alice } = aliceClient;
|
|
34
|
-
await harness.createClient({ userId: "bob" });
|
|
35
|
-
document.body.appendChild(container);
|
|
36
|
-
mountApp(container, createTestAppProps(aliceClient));
|
|
37
|
-
|
|
38
|
-
await waitFor(() => {
|
|
39
|
-
expect(container.querySelector("#app-heading")).toHaveTextContent(
|
|
40
|
-
"Hello",
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
await waitFor(() => {
|
|
44
|
-
expect(
|
|
45
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
46
|
-
).toHaveTextContent("2 connected players");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const control = document.createElement("button");
|
|
50
|
-
control.disabled = true;
|
|
51
|
-
control.setAttribute("data-state", "ready");
|
|
52
|
-
container.appendChild(control);
|
|
53
|
-
expect(control).toBeInTheDocument();
|
|
54
|
-
expect(control).toBeDisabled();
|
|
55
|
-
expect(control).toHaveAttribute("data-state", "ready");
|
|
56
|
-
expect(control).not.toHaveAttribute("aria-hidden");
|
|
57
|
-
|
|
58
|
-
await harness.addUser({ userId: "carol" });
|
|
59
|
-
const spectator = await alice.query((ctx: AppReadContext) =>
|
|
60
|
-
ctx.table("players").get("carol"),
|
|
61
|
-
);
|
|
62
|
-
expect(spectator).toEqual({ userId: "carol", mark: null });
|
|
63
|
-
await waitFor(() => {
|
|
64
|
-
expect(
|
|
65
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
66
|
-
).toHaveTextContent("3 connected players");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
await harness.removeUser({ userId: "carol" });
|
|
70
|
-
await waitFor(() => {
|
|
71
|
-
expect(
|
|
72
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
73
|
-
).toHaveTextContent("2 connected players");
|
|
74
|
-
});
|
|
75
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
76
|
-
ctx.table("$users").get("carol"),
|
|
77
|
-
)).toMatchObject({ removedAt: expect.any(Number) });
|
|
78
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
79
|
-
ctx.table("players").get("carol"),
|
|
80
|
-
)).toEqual({ userId: "carol", mark: null });
|
|
81
|
-
} finally {
|
|
82
|
-
container.remove();
|
|
83
|
-
harness.dispose();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { cleanup, render, waitFor } from "@testing-library/preact";
|
|
4
|
-
import { App } from "./App";
|
|
5
|
-
import { createPoeTileTestHarness } from "joiner-sdk/v1/test-utils.js";
|
|
6
|
-
import type { AppReadContext } from "../client";
|
|
7
|
-
import { tileBackendConfig } from "../synced-store/backend-config";
|
|
8
|
-
import type { AppSchema } from "../synced-store/schema";
|
|
9
|
-
import { createTestAppProps } from "../tests/app-test-props";
|
|
10
|
-
|
|
11
|
-
test("renders with a real two-client store and configured DOM matchers", async () => {
|
|
12
|
-
const harness = createPoeTileTestHarness<AppSchema>({
|
|
13
|
-
store: { backendConfig: tileBackendConfig },
|
|
14
|
-
});
|
|
15
|
-
let container: Element = document.createElement("div");
|
|
16
|
-
try {
|
|
17
|
-
const aliceClient = await harness.createClient({ userId: "alice" });
|
|
18
|
-
const { store: alice } = aliceClient;
|
|
19
|
-
await harness.createClient({ userId: "bob" });
|
|
20
|
-
({ container } = render(<App {...createTestAppProps(aliceClient)} />));
|
|
21
|
-
|
|
22
|
-
await waitFor(() => {
|
|
23
|
-
expect(container.querySelector("#app-heading")).toHaveTextContent(
|
|
24
|
-
"Hello",
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
await waitFor(() => {
|
|
28
|
-
expect(
|
|
29
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
30
|
-
).toHaveTextContent("2 connected players");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const control = document.createElement("button");
|
|
34
|
-
control.disabled = true;
|
|
35
|
-
control.setAttribute("data-state", "ready");
|
|
36
|
-
container.appendChild(control);
|
|
37
|
-
expect(control).toBeInTheDocument();
|
|
38
|
-
expect(control).toBeDisabled();
|
|
39
|
-
expect(control).toHaveAttribute("data-state", "ready");
|
|
40
|
-
expect(control).not.toHaveAttribute("aria-hidden");
|
|
41
|
-
|
|
42
|
-
await harness.addUser({ userId: "carol" });
|
|
43
|
-
const spectator = await alice.query((ctx: AppReadContext) =>
|
|
44
|
-
ctx.table("players").get("carol"),
|
|
45
|
-
);
|
|
46
|
-
expect(spectator).toEqual({ userId: "carol", mark: null });
|
|
47
|
-
await waitFor(() => {
|
|
48
|
-
expect(
|
|
49
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
50
|
-
).toHaveTextContent("3 connected players");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await harness.removeUser({ userId: "carol" });
|
|
54
|
-
await waitFor(() => {
|
|
55
|
-
expect(
|
|
56
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
57
|
-
).toHaveTextContent("2 connected players");
|
|
58
|
-
});
|
|
59
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
60
|
-
ctx.table("$users").get("carol"),
|
|
61
|
-
)).toMatchObject({ removedAt: expect.any(Number) });
|
|
62
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
63
|
-
ctx.table("players").get("carol"),
|
|
64
|
-
)).toEqual({ userId: "carol", mark: null });
|
|
65
|
-
} finally {
|
|
66
|
-
cleanup(); container.remove();
|
|
67
|
-
harness.dispose();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { act, cleanup, render, waitFor } from "@testing-library/react";
|
|
4
|
-
import { App } from "./App";
|
|
5
|
-
import { createPoeTileTestHarness } from "joiner-sdk/v1/test-utils.js";
|
|
6
|
-
import type { AppReadContext } from "../client";
|
|
7
|
-
import { tileBackendConfig } from "../synced-store/backend-config";
|
|
8
|
-
import type { AppSchema } from "../synced-store/schema";
|
|
9
|
-
import { createTestAppProps } from "../tests/app-test-props";
|
|
10
|
-
|
|
11
|
-
test("renders with a real two-client store and configured DOM matchers", async () => {
|
|
12
|
-
const harness = createPoeTileTestHarness<AppSchema>({
|
|
13
|
-
store: { backendConfig: tileBackendConfig },
|
|
14
|
-
});
|
|
15
|
-
let container: HTMLElement = document.createElement("div");
|
|
16
|
-
try {
|
|
17
|
-
const aliceClient = await harness.createClient({ userId: "alice" });
|
|
18
|
-
const { store: alice } = aliceClient;
|
|
19
|
-
await harness.createClient({ userId: "bob" });
|
|
20
|
-
({ container } = render(<App {...createTestAppProps(aliceClient)} />));
|
|
21
|
-
|
|
22
|
-
await waitFor(() => {
|
|
23
|
-
expect(container.querySelector("#app-heading")).toHaveTextContent(
|
|
24
|
-
"Hello",
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
await waitFor(() => {
|
|
28
|
-
expect(
|
|
29
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
30
|
-
).toHaveTextContent("2 connected players");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const control = document.createElement("button");
|
|
34
|
-
control.disabled = true;
|
|
35
|
-
control.setAttribute("data-state", "ready");
|
|
36
|
-
container.appendChild(control);
|
|
37
|
-
expect(control).toBeInTheDocument();
|
|
38
|
-
expect(control).toBeDisabled();
|
|
39
|
-
expect(control).toHaveAttribute("data-state", "ready");
|
|
40
|
-
expect(control).not.toHaveAttribute("aria-hidden");
|
|
41
|
-
|
|
42
|
-
await act(async () => {
|
|
43
|
-
await harness.addUser({ userId: "carol" });
|
|
44
|
-
});
|
|
45
|
-
const spectator = await alice.query((ctx: AppReadContext) =>
|
|
46
|
-
ctx.table("players").get("carol"),
|
|
47
|
-
);
|
|
48
|
-
expect(spectator).toEqual({ userId: "carol", mark: null });
|
|
49
|
-
await waitFor(() => {
|
|
50
|
-
expect(
|
|
51
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
52
|
-
).toHaveTextContent("3 connected players");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
await act(async () => {
|
|
56
|
-
await harness.removeUser({ userId: "carol" });
|
|
57
|
-
});
|
|
58
|
-
await waitFor(() => {
|
|
59
|
-
expect(
|
|
60
|
-
container.querySelector('[data-testid="connected-player-count"]'),
|
|
61
|
-
).toHaveTextContent("2 connected players");
|
|
62
|
-
});
|
|
63
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
64
|
-
ctx.table("$users").get("carol"),
|
|
65
|
-
)).toMatchObject({ removedAt: expect.any(Number) });
|
|
66
|
-
expect(await alice.query((ctx: AppReadContext) =>
|
|
67
|
-
ctx.table("players").get("carol"),
|
|
68
|
-
)).toEqual({ userId: "carol", mark: null });
|
|
69
|
-
} finally {
|
|
70
|
-
cleanup(); container.remove();
|
|
71
|
-
harness.dispose();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// owner: jyoung-q
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { createPoeTileTestHarness } from "joiner-sdk/v1/test-utils.js";
|
|
4
|
-
import type { AppReadContext } from "../client";
|
|
5
|
-
import { tileBackendConfig } from "./backend-config";
|
|
6
|
-
import type { AppSchema } from "./schema";
|
|
7
|
-
|
|
8
|
-
async function readRoster(ctx: AppReadContext) {
|
|
9
|
-
return {
|
|
10
|
-
players: await ctx.table("players").scan().values().toArray(),
|
|
11
|
-
users: await ctx.table("$users").scan().values().toArray(),
|
|
12
|
-
userInfo: await ctx.table("$userInfo").scan().values().toArray(),
|
|
13
|
-
permissions: await ctx.table("$permissions").scan().values().toArray(),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
test("createClient populates system tables and runs auto-seating hooks", async () => {
|
|
18
|
-
const harness = createPoeTileTestHarness<AppSchema>({
|
|
19
|
-
store: { backendConfig: tileBackendConfig },
|
|
20
|
-
});
|
|
21
|
-
try {
|
|
22
|
-
const { store: alice } = await harness.createClient({
|
|
23
|
-
userId: "alice",
|
|
24
|
-
userInfo: {
|
|
25
|
-
displayName: "Alice Example",
|
|
26
|
-
profilePicture: "https://example.com/alice.png",
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
await harness.createClient({ userId: "bob" });
|
|
30
|
-
await harness.createClient({ userId: "carol" });
|
|
31
|
-
|
|
32
|
-
const roster = await alice.query(readRoster);
|
|
33
|
-
expect(roster.players).toEqual([
|
|
34
|
-
{ userId: "alice", mark: "X" },
|
|
35
|
-
{ userId: "bob", mark: "O" },
|
|
36
|
-
{ userId: "carol", mark: null },
|
|
37
|
-
]);
|
|
38
|
-
expect(roster.users.map((user) => user.userId)).toEqual([
|
|
39
|
-
"alice",
|
|
40
|
-
"bob",
|
|
41
|
-
"carol",
|
|
42
|
-
]);
|
|
43
|
-
expect(roster.userInfo.find((info) => info.userId === "alice")).toMatchObject({
|
|
44
|
-
displayName: "Alice Example",
|
|
45
|
-
profilePicture: "https://example.com/alice.png",
|
|
46
|
-
});
|
|
47
|
-
expect(roster.userInfo.find((info) => info.userId === "bob")?.displayName).toBe(
|
|
48
|
-
"bob",
|
|
49
|
-
);
|
|
50
|
-
expect(roster.permissions).toEqual([]);
|
|
51
|
-
} finally {
|
|
52
|
-
harness.dispose();
|
|
53
|
-
}
|
|
54
|
-
});
|