Files
agentic-dev/turbo/generators/config.test.ts
Danijel Martinek b593bea8ca fix(generators): wire lint+typecheck into pipeline and fix uncovered errors
The turbo/generators package shipped without `lint` or `typecheck` scripts,
so `pnpm lint` / `pnpm typecheck` at the root silently skipped it. This
masked 2 ESLint errors (unused imports) and 11 TypeScript errors (relative
imports missing the `.js` extension required by `moduleResolution: NodeNext`,
plus JSON imports missing the `with { type: "json" }` attribute).

- Add `lint` and `typecheck` scripts to turbo/generators/package.json so the
  turbo pipeline picks them up (lint: 14/14, was 13/13).
- Add `.js` extensions to 7 relative imports across config.test.ts,
  lib/core-package-utils.test.ts, lib/snapshot.test.ts, and the 4 e2e tests.
- Add `with { type: "json" }` attributes to 4 snapshot JSON imports in the
  e2e tests.
- Remove unused `existsSync` and `splicePluginImportsAt` imports from
  lib/core-package-utils.test.ts.
- Declare `@repo/core-typescript` + `typescript` devDependencies so the
  generators package can run `tsc --noEmit` for typecheck.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 08:09:17 +02:00

59 lines
2.7 KiB
TypeScript

import { describe, it, expect } from "vitest";
import type { PlopTypes } from "@turbo/gen";
import generator from "./config.js";
describe("core-package generator", () => {
it("is registered with realtime and events in choices list", () => {
const captured: Array<{ name: string; def: PlopTypes.PlopGeneratorConfig }> = [];
const plopMock = {
setHelper: () => {},
setGenerator: (name: string, def: PlopTypes.PlopGeneratorConfig) =>
captured.push({ name, def }),
} as unknown as PlopTypes.NodePlopAPI;
generator(plopMock);
const corePkg = captured.find((c) => c.name === "core-package");
expect(corePkg).toBeDefined();
const prompts = corePkg!.def.prompts as Array<{ name: string; choices: unknown[] }>;
expect(prompts[0]!.name).toBe("name");
expect(prompts[0]!.choices).toContain("realtime");
expect(prompts[0]!.choices).toContain("events");
expect(prompts[0]!.choices).toContain("trpc");
expect(prompts[0]!.choices).toContain("ui");
});
});
describe("core-package realtime", () => {
it("emits actions covering package files, transpilePackages, and ESLint rules", () => {
// Capture the actions returned by the realtime entry.
const captured: Array<{ name: string; def: PlopTypes.PlopGeneratorConfig }> = [];
const plop = {
setHelper: () => {},
setGenerator: (n: string, d: unknown) => captured.push({ name: n, def: d as PlopTypes.PlopGeneratorConfig }),
} as unknown as PlopTypes.NodePlopAPI;
generator(plop);
const corePkg = captured.find((c) => c.name === "core-package")!.def;
const actions = (corePkg.actions as (a: { name: string }) => PlopTypes.ActionType[])(
{ name: "realtime" },
);
// Expectations: at least one assertNotPresent guard, multiple `add` actions, and a transpilePackages action.
expect(actions.length).toBeGreaterThan(20); // 28 files + extras
});
});
describe("core-package events", () => {
it("emits actions covering package files, transpilePackages, and ESLint rule splice", () => {
const captured: Array<{ name: string; def: PlopTypes.PlopGeneratorConfig }> = [];
const plop = {
setHelper: () => {},
setGenerator: (n: string, d: unknown) => captured.push({ name: n, def: d as PlopTypes.PlopGeneratorConfig }),
} as unknown as PlopTypes.NodePlopAPI;
generator(plop);
const corePkg = captured.find((c) => c.name === "core-package")!.def;
const actions = (corePkg.actions as (a: { name: string }) => PlopTypes.ActionType[])(
{ name: "events" },
);
// 1 guard + 15 template files + transpilePackages + ESLint splice + printNextSteps = 19
expect(actions.length).toBeGreaterThanOrEqual(18);
});
});