testing

Test @rangojs/router apps across unit, integration, RSC Flight, and Playwright e2e layers.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill testing-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/testing
Command: npx skills add https://github.com/rangojs/rango --skill testing-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires vitest, @playwright/test, @testing-library/react, and includes references (resource) components.

What problem does it solve? Testing a React Server Components router is hard because the correct test layer depends on what the behavior touches — a pure predicate needs a one-line vitest test, while a real async Server Component cannot run in a plain node test at all. This Skill maps each behavior (loaders, middleware, server actions, handles, client components, response routes, cache/prerender, navigation) to the right testing primitive and import entry so tests are neither too slow nor silently asserting nothing. ## Core Features & Use Cases - Layer decision tree: Routes each behavior to the correct primitive — runLoader/runMiddleware/runInRequestContext for node unit tests, renderRoute for DOM client components, renderServerTree/renderToFlightString/renderHandler for real Flight renders, and dispatch for response routes. - Dev/prod and progressive-enhancement e2e parity: parityDescribe generates both dev and production describes from one body, and expectParity asserts JS and no-JS flows produce identical observable results. - Cache, SWR, and prerender assertions: assertCacheStatus reads the X-Rango-Cache header while createCacheSink/assertCacheDecision capture telemetry events with zero production surface. - Use Case: You need to test a loader that reads env.DB, sets a cookie, and throws a redirect. Use runLoaderResult with a D1 double injected via the env option, then assert the thrown redirect's Location header and the Set-Cookie output. ## Quick Start Ask the assistant to write a unit test for a loader or middleware in your @rangojs/router app, or to set up a dev-and-production e2e test for a route using parityDescribe.

Frequently Asked Questions about testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a loader in @rangojs/router?

Use runLoader from @rangojs/router/testing to execute a loader against a real RequestContext in plain node. Seed params, env, vars, and search data via options; use runLoaderResult instead when you need to assert cookies, headers, redirects, or handle writes.

How do I test an async React Server Component in node?

Use renderServerTree or renderToFlightString from @rangojs/router/testing/flight under the react-server vitest project. A real async Server Component cannot run in a plain node test — it requires the react-server condition, the index.rsc.ts alias, and files named *.rsc-test.ts run via the RSC test project.

Does @rangojs/router provide mocks for D1 or Durable Objects?

No, rango ships no doubles for platform bindings by design. You build your own double matching the driver contract (e.g. drizzle-orm/d1 needs positional row arrays from .raw() and { success, meta } from .run()) and inject it through the env option every testing primitive accepts.

How do I run e2e tests in both dev and production mode?

Use parityDescribe from @rangojs/router/testing/e2e, which registers a dev describe and a production describe from a single test body. This structurally enforces the rule that every e2e covers both modes, since a dev-only e2e is not acceptable.

Why does my Flight test fail to compile in a plain vitest project?

The Flight serializer only loads under the react-server node condition, so importing @rangojs/router/testing/flight elsewhere throws. Configure a separate vitest project with resolve.conditions including react-server, the @rangojs/router to index.rsc.ts alias, and NODE_ENV=production.

When should I use renderRoute versus an e2e test?

Use renderRoute from @rangojs/router/testing/dom for client components reading router context like useParams or useReverse, where loader data is seeded rather than executed. Navigation lifecycle states, hydration, Flight serialization, and progressive-enhancement parity require a Playwright e2e test.