Skip to content

Commit 81bb967

Browse files
committed
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 5955618 commit 81bb967

File tree

8 files changed

+1137
-288
lines changed

8 files changed

+1137
-288
lines changed

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)