scaffold-tests
Skill106 starsChanged 7 months agoMITView on GitHub
Set up Vitest for pracht routes, loaders, and middleware in browser mode or JSDOM, with `@pracht/test` helpers and runnable example tests. Use for "scaffold tests", "set up Vitest", "add unit tests", "test this loader", "test this route".
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- IvandoNascimento/skillstheir own version, first seen Jun 7, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- IvandoNascimento/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- add-authSkill
- add-capabilitiesSkill
- add-contentSkill
- add-dbSkill
- add-i18nSkill
- add-imagesSkill
- add-observabilitySkill
- add-openapiSkill
- audit-a11ySkill
- audit-agent-surfaceSkill
- audit-authSkill
- audit-bundlesSkill
- audit-csrfSkill
- audit-depsSkill
- audit-headersSkill
- audit-islandsSkill
- audit-loadersSkill
- audit-redirectsSkill
- audit-secretsSkill
- audit-seoSkill
- audit-shellsSkill
- configure-isgSkill
- migrate-nextjsSkill
- pracht-debugSkill
- pracht-deploySkill
- pracht-scaffoldSkill
- pracht-test-apiSkill
- pre-deploySkill
- scaffold-e2eSkill
- tune-render-modeSkill
- typed-routesSkill
- upgrade-prachtSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
Use AskUserQuestion to choose between:
- Distinctive: line 39
If the project already has one configured, default to it and confirm.
- Distinctive: line 72
If the project only needs loader/middleware tests (no component rendering), skip the extras entirely and use the plugin-less config in Step …
- Very specific: line 130
If vitest.config.ts already exists, merge — never clobber.
- Very specific: line 140
Use pracht inspect routes --json to find targets.
- Distinctive: line 227
Add (or merge) scripts:
- Very specific: line 238
If pnpm test already exists, do not overwrite.
- Distinctive: line 247
If anything fails on first run, report the failure and the fix.
- Very specific: line 252
Ask the rendering-strategy question once per project.
- Distinctive: line 254
Only test exports that exist — read the route file before generating.
- Very specific: line 255
Use @pracht/test's factories for BaseRouteArgs/LoaderArgs construction instead of hand-building args objects.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pracht Scaffold Tests
Generate Vitest tests aligned with pracht's testing recipe (https://pracht.resynapse.dev/docs/recipes/testing). Loaders and API handlers are plain async functions — they test directly with no framework bootstrap. Component tests need a renderer; the user picks the flavor.
Step 1: Pick the rendering strategy
Use AskUserQuestion to choose between:
- Browser mode —
vitestwith@vitest/browserandvitest-browser-preact.- Pros: real browser, real events, fewer hydration false positives, screenshots, works for SPA-mode interaction tests.
- Cons: slower, heavier setup, requires a browser binary on CI.
- JSDOM —
vitestwith@testing-library/preact.- Pros: fast, lightweight, runs anywhere.
- Cons: JSDOM lacks layout, certain DOM APIs; brittle for complex UIs.
If the project already has one configured, default to it and confirm.
Step 2: Install dependencies
Detect the package manager from the lockfile.
Common (both modes):
pnpm add -D vitest @types/node @pracht/test@pracht/test provides the typed args factories (createLoaderArgs,
createApiArgs, createMiddlewareArgs, createApiMiddlewareArgs), the
runMiddleware() chain runner, submitForm(), and the
readJson()/readRedirect() response readers used in the templates below.
Component-test extras — @preact/preset-vite must be an explicit dev
dependency: the configs in Step 3 import it, and a transitive-only copy
fails under pnpm's strict node_modules.
Browser mode:
pnpm add -D @vitest/browser playwright vitest-browser-preact @preact/preset-viteJSDOM mode:
pnpm add -D jsdom @testing-library/preact @testing-library/jest-dom @preact/preset-viteIf the project only needs loader/middleware tests (no component rendering), skip the extras entirely and use the plugin-less config in Step 3.
Step 3: Wire vitest.config.ts
Browser mode:
import { defineConfig } from "vitest/config";
import preact from "@preact/preset-vite";
export default defineConfig({
plugins: [preact()],
test: {
browser: {
enabled: true,
provider: "playwright",
instances: [{ browser: "chromium" }],
},
},
});JSDOM mode:
import { defineConfig } from "vitest/config";
import preact from "@preact/preset-vite";
export default defineConfig({
plugins: [preact()],
test: {
environment: "jsdom",
setupFiles: ["./test/setup.ts"],
},
});test/setup.ts (JSDOM only):
import "@testing-library/jest-dom/vitest";Loader/middleware-only mode (no components) — matches the minimal config in https://pracht.resynapse.dev/docs/recipes/testing.md; no preset, no extra deps:
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
// Exclude E2E tests (run those with Playwright)
exclude: ["e2e/**", "node_modules/**"],
},
});If vitest.config.ts already exists, merge — never clobber.
Step 4: Generate the tests
MCP: if pracht dev-mcp is registered, prefer its inspect_*, generate_*, doctor, and verify tools to the CLI.
This skill covers loaders, middleware, and components. For API handlers
(src/api/**), delegate to /pracht-test-api — it owns handler enumeration and
per-method test generation; don't duplicate a weaker version here.
Use pracht inspect routes --json to find targets. Ask the user which subset
to scaffold, or pass paths via $ARGUMENTS.
Loader test template
import { describe, it, expect } from "vitest";
import { createLoaderArgs } from "@pracht/test";
import { loader } from "./<route-file>";
describe("<route> loader", () => {
it("returns the expected shape", async () => {
const data = await loader(createLoaderArgs({ url: "/<path>" }));
expect(data).toBeDefined();
});
});Pass params, headers, a partial context, or a JSON-encoding body as
needed; the factory defaults everything else and exposes controller (the
AbortController behind args.signal) for cancellation tests.
Middleware test template
import { describe, it, expect } from "vitest";
import { createMiddlewareArgs, readRedirect, runMiddleware } from "@pracht/test";
import { middleware } from "./<middleware-file>";
describe("<name> middleware", () => {
it("redirects unauthenticated requests", async () => {
const response = await runMiddleware(middleware, createMiddlewareArgs({ url: "/dashboard" }));
expect(readRedirect(response).location).toMatch(/^\/login/);
});
it("calls through when authenticated", async () => {
const response = await runMiddleware(
middleware,
createMiddlewareArgs({ url: "/dashboard", headers: { cookie: "session=valid" } }),
async () => new Response("handler ran"),
);
expect(await response.text()).toBe("handler ran");
});
});runMiddleware() accepts an array to test a chain in manifest order,
including context mutations flowing downstream and returned-response
short-circuits. A thrown Response resolves by default, matching page/API
outer normalization. For raw capability-chain behavior, pass
undefined, { thrownResponse: "reject" } after the args/final-handler slots;
prefer createCapabilityTestHost() so the test asserts the real typed
internal_error envelope. For middleware attached through defineApp({ api }),
use createApiMiddlewareArgs() so route has the API metadata shape.
Component test template (browser mode)
import { describe, it, expect } from "vitest";
import { render } from "vitest-browser-preact";
import { Component } from "./<route-file>";
describe("<route> component", () => {
it("renders the heading", async () => {
const screen = render(<Component data={{ /* mock loader data */ }} params={{}} />);
await expect.element(screen.getByRole("heading")).toBeVisible();
});
});Component test template (JSDOM)
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/preact";
import { Component } from "./<route-file>";
describe("<route> component", () => {
it("renders the heading", () => {
render(<Component data={{ /* mock loader data */ }} params={{}} />);
expect(screen.getByRole("heading")).toBeInTheDocument();
});
});Step 5: Wire package.json
Add (or merge) scripts:
{
"scripts": {
"test": "vitest run",
"test:watch": "vitest"
}
}If pnpm test already exists, do not overwrite.
Step 6: Verify
pnpm test
pracht verify --jsonIf anything fails on first run, report the failure and the fix. Do not commit broken scaffolding.
Rules
- Ask the rendering-strategy question once per project; persist by
inspecting
vitest.config.tson subsequent runs. - Only test exports that exist — read the route file before generating.
- Use
@pracht/test's factories forBaseRouteArgs/LoaderArgsconstruction instead of hand-building args objects. - For routes with
getStaticPaths, scaffold a separate test that calls it. - Generated tests should pass on first run with a placeholder assertion; the user fills in real expectations.
$ARGUMENTS
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

