Skip to content

Commit 2f2c31f

Browse files
authored
test(typegen): add mock infrastructure for unit tests (#103)
## Summary - Create layout metadata fixtures (`tests/fixtures/layout-metadata.ts`) - Add mock fetch utility for mocking FM Data API calls (`tests/utils/mock-fetch.ts`) - Move E2E tests requiring live FM server to `tests/e2e/` - Create unit tests that use mocked metadata (11 tests) - Update `vitest.config.ts` to exclude e2e tests by default - Add `test:e2e` script for running E2E tests with doppler ## Test plan - [x] `pnpm --filter @proofkit/typegen lint` passes - [x] `pnpm --filter @proofkit/typegen typecheck` passes - [x] `pnpm --filter @proofkit/typegen test` passes (11 unit tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Modernizes testing and docs across packages, separating fast unit tests from live E2E runs and adding reusable CLI/docs components. > > - Testing: Add mock fetch utilities and recorded fixtures for `@proofkit/better-auth` and `@proofkit/fmdapi`; create layout metadata fixtures and unit tests in `@proofkit/typegen`; move live tests to `tests/e2e`; update `vitest.config.ts` to exclude E2E by default; add `test:e2e` scripts and Turbo pipeline > - CI: Simplify `continuous-release.yml` test job to run unit tests only (remove Doppler/OIDC/E2E); keep build after tests > - Tooling: Add `scripts/capture-responses.ts` to record FM API responses for mocks; add `vitest.config.ts` per package with E2E exclusion > - Docs/UI: Introduce `PackageInstall` component and enhance `CliCommand` (new `packageName` prop); update MDX guides to use these components and stable package refs > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3e25bc9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b5ff936 commit 2f2c31f

File tree

15 files changed

+1202
-320
lines changed

15 files changed

+1202
-320
lines changed

apps/docs/content/docs/better-auth/installation.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Installation & Usage
55
import { Callout } from "fumadocs-ui/components/callout";
66

77
import { CliCommand } from "@/components/CliCommand";
8+
import { PackageInstall } from "@/components/PackageInstall";
89

910

1011
<Callout type="warning">
@@ -31,9 +32,7 @@ Follow the [Better-Auth installation guide](https://better-auth.com/docs/install
3132
### Database Setup
3233

3334
Ensure you have the @proofkit/better-auth package installed in your app.
34-
```package-install
35-
@proofkit/better-auth@beta
36-
```
35+
<PackageInstall packages="@proofkit/better-auth" />
3736

3837
Configure your database connection in your `auth.ts` file. Be sure to set these value secrets in your environment variables. The credentials you use here need `fmodata` permissions enabled, and read/write access to the better-auth tables.
3938
```ts title="auth.ts"
@@ -62,10 +61,10 @@ export const auth = betterAuth({
6261
# Step 2: Create/Update Database Tables
6362

6463
Run the following command to create the necessary tables and fields in your FileMaker file. It will show you a confirmation before any changes are applied, so you can review them.
65-
<CliCommand command="migrate" exec execPackage="@proofkit/better-auth@beta" />
64+
<CliCommand command="migrate" exec packageName="@proofkit/better-auth" />
6665

6766
[Full Access] credentials are required for the schema changes to be applied automatically, but you may want to use a more restricted account for the rest of better-auth usage. If your credentials that you entered earlier in the `auth.ts` file do not have the [Full Access] permissions, you can override them in the CLI.
68-
<CliCommand command={`migrate --username "full_access_username" --password "full_access_password"`} exec execPackage="@proofkit/better-auth@beta" />
67+
<CliCommand command={`migrate --username "full_access_username" --password "full_access_password"`} exec packageName="@proofkit/better-auth" />
6968

7069
These changes affect database schema only. No layouts or relationships are created or modified during this process.
7170

apps/docs/content/docs/better-auth/troubleshooting.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Troubleshooting
33
---
44

5+
import { CliCommand } from "@/components/CliCommand";
6+
57
## Error when generating schema
68
```bash
79
ERROR [Better Auth]: filemaker is not supported. If it is a custom adapter, please request the maintainer to implement createSchema
810
```
911

1012
This means you used the better-auth CLI directly instead of the @proofkit/better-auth version. Run this instead:
1113

12-
```bash
13-
pnpm dlx @proofkit/better-auth@beta migrate
14-
```
14+
<CliCommand command="migrate" exec packageName="@proofkit/better-auth" />

apps/docs/content/docs/fmodata/quick-start.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { Callout } from "fumadocs-ui/components/callout";
1313
import { Card } from "fumadocs-ui/components/card";
1414
import { CliCommand } from "@/components/CliCommand";
15+
import { PackageInstall } from "@/components/PackageInstall";
1516
import { Badge } from "@/components/ui/badge";
1617

1718
Here's a minimal example to get you started with `@proofkit/fmodata`:
@@ -20,9 +21,7 @@ Here's a minimal example to get you started with `@proofkit/fmodata`:
2021
<Step>
2122
### Install the package
2223

23-
```package-install
24-
@proofkit/fmodata@beta
25-
```
24+
<PackageInstall packages="@proofkit/fmodata" />
2625

2726
</Step>
2827

@@ -67,7 +66,7 @@ Here's a minimal example to get you started with `@proofkit/fmodata`:
6766
</TabsList>
6867
<TabsContent value="automatic">
6968
Run this command in your project to launch a browser-based UI for configuring your schema definitions. You will need environment variables set for your FileMaker server and database.
70-
<CliCommand command="ui" exec execPackage="@proofkit/typegen@beta" />
69+
<CliCommand command="ui" exec packageName="@proofkit/typegen" />
7170

7271
Learn more about the [@proofkit/typegen](/docs/typegen) tool.
7372

apps/docs/content/docs/typegen/index.mdx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Tabs, TabItem } from "fumadocs-ui/components/tabs";
77
import { Callout } from "fumadocs-ui/components/callout";
88
import { File, Folder, Files } from "fumadocs-ui/components/files";
99
import { IconFileTypeTs } from "@tabler/icons-react";
10+
import { CliCommand } from "@/components/CliCommand";
1011

1112
A utility for generating runtime validators and TypeScript files from your
1213
own FileMaker layouts.
@@ -15,13 +16,7 @@ own FileMaker layouts.
1516

1617
Run this command to initialize `@proofkit/typegen` in your project:
1718

18-
```bash tab="pnpm"
19-
pnpm dlx @proofkit/typegen@beta
20-
```
21-
22-
```bash tab="npm"
23-
npx @proofkit/typegen@beta
24-
```
19+
<CliCommand command="" exec packageName="@proofkit/typegen" />
2520

2621
## Configuring Typegen
2722

@@ -51,14 +46,7 @@ If you need to use different env variable names (i.e. for multiple FileMaker con
5146
## Running Typegen
5247
Once you have a config file setup, you can run the command to generate the types:
5348

54-
55-
```bash tab="pnpm"
56-
pnpm dlx @proofkit/typegen@beta
57-
```
58-
59-
```bash tab="npm"
60-
npx @proofkit/typegen@beta
61-
```
49+
<CliCommand command="" exec packageName="@proofkit/typegen" />
6250

6351
<Callout type="info">
6452
We suggest adding a script to your `package.json` to run this command more easily

apps/docs/content/docs/typegen/ui.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Typegen UI
33
---
44

5+
import { CliCommand } from "@/components/CliCommand";
6+
57
The typegen tool has a built-in web interface for editing your JSON config file and running the typegen scripts. It's helpful for making sure your environment variables are setup correctly and can help autocomplete layout/field/table names into the config file.
68

79
To launch the UI, run the following command and a browser window will open at `http://localhost:3141`:
810

9-
```bash
10-
npx @proofkit/typegen@beta ui
11-
```
11+
<CliCommand command="ui" exec packageName="@proofkit/typegen" />
1212

1313

1414
## CLI options

apps/docs/src/components/CliCommand.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ const MANAGERS = [
3333
export function CliCommand({
3434
command,
3535
exec,
36-
execPackage = `@proofkit/cli@${cliVersion}`,
36+
execPackage,
37+
packageName = "@proofkit/cli",
3738
}: {
3839
command: string;
3940
exec?: boolean;
41+
/** @deprecated Use packageName instead */
4042
execPackage?: string;
43+
packageName?: string;
4144
}) {
45+
const pkg = execPackage ?? `${packageName}@${cliVersion}`;
4246
return (
4347
<Tabs groupId="package-manager" id="package-manager" items={MANAGERS.map((m) => m.label)} persist>
4448
{MANAGERS.map((manager) => (
4549
<Tab key={manager.key} value={manager.label}>
4650
<DynamicCodeBlock
47-
code={`${exec ? `${manager.execPrefix} ${execPackage}` : manager.prefix} ${command}`}
51+
code={`${exec ? `${manager.execPrefix} ${pkg}` : manager.prefix} ${command}`}
4852
lang="bash"
4953
/>
5054
</Tab>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use client";
2+
import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";
3+
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
4+
import { cliVersion } from "@/lib/constants";
5+
6+
const MANAGERS = [
7+
{ key: "npm", label: "npm", prefix: "npm install" },
8+
{ key: "pnpm", label: "pnpm", prefix: "pnpm add" },
9+
{ key: "yarn", label: "yarn", prefix: "yarn add" },
10+
{ key: "bun", label: "bun", prefix: "bun add" },
11+
];
12+
13+
const WHITESPACE_RE = /\s+/;
14+
15+
/**
16+
* Renders a tabbed package install command.
17+
* Automatically appends @{cliVersion} to @proofkit/* packages unless version is already specified.
18+
*/
19+
export function PackageInstall({ packages }: { packages: string }) {
20+
const pkgs = packages
21+
.trim()
22+
.split(WHITESPACE_RE)
23+
.map((pkg) => {
24+
// If it's a @proofkit package without a version, append the cliVersion
25+
if (pkg.startsWith("@proofkit/") && !pkg.includes("@", 1)) {
26+
return `${pkg}@${cliVersion}`;
27+
}
28+
return pkg;
29+
})
30+
.join(" ");
31+
32+
return (
33+
<Tabs groupId="package-manager" id="package-manager" items={MANAGERS.map((m) => m.label)} persist>
34+
{MANAGERS.map((manager) => (
35+
<Tab key={manager.key} value={manager.label}>
36+
<DynamicCodeBlock code={`${manager.prefix} ${pkgs}`} lang="bash" />
37+
</Tab>
38+
))}
39+
</Tabs>
40+
);
41+
}
42+
43+
export default PackageInstall;

packages/typegen/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"dev": "pnpm build:watch",
99
"dev:ui": "concurrently -n \"web,api\" -c \"cyan,magenta\" \"pnpm -C web dev\" \"pnpm run dev:api\"",
1010
"dev:api": "concurrently -n \"build,server\" -c \"cyan,magenta\" \"pnpm build:watch\" \"nodemon --watch dist/esm --delay 1 --exec 'node dist/esm/cli.js ui --port 3141 --no-open'\"",
11-
"test": "doppler run -- vitest run",
11+
"test": "vitest run",
1212
"test:watch": "vitest --watch",
13+
"test:e2e": "doppler run -- vitest run tests/e2e",
1314
"typecheck": "tsc --noEmit",
1415
"build": "pnpm -C web build && pnpm vite build && node scripts/build-copy.js && publint --strict",
1516
"build:watch": "vite build --watch",

packages/typegen/tests/fmodata-preserve-customizations.test.ts renamed to packages/typegen/tests/e2e/fmodata-preserve-customizations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import fs from "node:fs/promises";
22
import os from "node:os";
33
import path from "node:path";
44
import { describe, expect, it } from "vitest";
5-
import { generateODataTypes } from "../src/fmodata/generateODataTypes";
6-
import type { ParsedMetadata } from "../src/fmodata/parseMetadata";
5+
import { generateODataTypes } from "../../src/fmodata/generateODataTypes";
6+
import type { ParsedMetadata } from "../../src/fmodata/parseMetadata";
77

88
function makeMetadata({
99
entitySetName,

packages/typegen/tests/fmodata-typegen.test.ts renamed to packages/typegen/tests/e2e/fmodata-typegen.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { execSync } from "node:child_process";
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import { afterEach, beforeEach, describe, expect, it } from "vitest";
5-
import { generateODataTypes, parseMetadataFromFile } from "../src/fmodata";
6-
import type { FmodataConfig } from "../src/types";
5+
import { generateODataTypes, parseMetadataFromFile } from "../../src/fmodata";
6+
import type { FmodataConfig } from "../../src/types";
77

88
// Helper to read fixture files
9-
const fixturesDir = path.resolve(__dirname, "fixtures");
9+
const fixturesDir = path.resolve(__dirname, "../fixtures");
1010
const outputDir = path.resolve(__dirname, "fmodata-output");
1111

1212
/**
@@ -438,7 +438,7 @@ describe("fmodata typegen - snapshot tests", () => {
438438
await generateODataTypes(metadata, config);
439439

440440
const content = await fs.readFile(path.join(outputDir, "Customers.ts"), "utf-8");
441-
await expect(content).toMatchFileSnapshot(path.join(__dirname, "__snapshots__", "fmodata-customers.snap.ts"));
441+
await expect(content).toMatchFileSnapshot(path.join(__dirname, "../__snapshots__", "fmodata-customers.snap.ts"));
442442
});
443443

444444
it("generates expected Orders table output", async () => {
@@ -455,7 +455,7 @@ describe("fmodata typegen - snapshot tests", () => {
455455
await generateODataTypes(metadata, config);
456456

457457
const content = await fs.readFile(path.join(outputDir, "Orders.ts"), "utf-8");
458-
await expect(content).toMatchFileSnapshot(path.join(__dirname, "__snapshots__", "fmodata-orders.snap.ts"));
458+
await expect(content).toMatchFileSnapshot(path.join(__dirname, "../__snapshots__", "fmodata-orders.snap.ts"));
459459
});
460460

461461
it("generates expected index file output", async () => {
@@ -472,7 +472,7 @@ describe("fmodata typegen - snapshot tests", () => {
472472
await generateODataTypes(metadata, config);
473473

474474
const content = await fs.readFile(path.join(outputDir, "index.ts"), "utf-8");
475-
await expect(content).toMatchFileSnapshot(path.join(__dirname, "__snapshots__", "fmodata-index.snap.ts"));
475+
await expect(content).toMatchFileSnapshot(path.join(__dirname, "../__snapshots__", "fmodata-index.snap.ts"));
476476
});
477477

478478
it("generates expected output with all typeOverride transformations", async () => {
@@ -502,6 +502,8 @@ describe("fmodata typegen - snapshot tests", () => {
502502
await generateODataTypes(metadata, config);
503503

504504
const content = await fs.readFile(path.join(outputDir, "Customers.ts"), "utf-8");
505-
await expect(content).toMatchFileSnapshot(path.join(__dirname, "__snapshots__", "fmodata-type-overrides.snap.ts"));
505+
await expect(content).toMatchFileSnapshot(
506+
path.join(__dirname, "../__snapshots__", "fmodata-type-overrides.snap.ts"),
507+
);
506508
});
507509
});

0 commit comments

Comments
 (0)