portal-test
Add or run a Jest test for a portal file in apps/portal/. Use when the user says "add a test for X", "why is this test failing", "run tests for Y", or imports a new workspace package that needs a Jest
SKILL.md.claude/plugins/arch-mk2-dev/skills/portal-test/SKILL.md
GitHubPortal Test
User-only side-effect skill. Walks the contributor through adding or running a Jest test for a portal file, with explicit handling of the repo's brittle Jest moduleNameMapper setup.
When to use
- User says "add a test for X", "test this file", "run the test for Y"
- User imports a new workspace package (
@repo/*) subpath in portal code - A test file is failing with
Cannot find module '@repo/...'even though the import works at runtime
When NOT to use
- The work is E2E (Playwright) — point the user to
pnpm test:e2eand the integration-tester agent - The work is unit-test scaffolding in a non-portal package (
packages/*) — those have their own Jest configs
Workflow
- Detect the new import. Read the file the user wants to test. List every
importof a@repo/*package. Cross-reference withapps/portal/jest.config.jsmoduleNameMapperentries. - Check the Jest mapping. The portal's Jest config uses explicit
moduleNameMapperentries; wildcards alone don't always resolve subpaths. For each new import, verify the mapping exists. If missing, add it. - If mapping is missing, add the entry to
apps/portal/jest.config.js. The pattern is:'^@repo/<pkg>$': '<rootDir>/../../packages/<pkg>/src', '^@repo/<pkg>/<subpath>$': '<rootDir>/../../packages/<pkg>/src/<subpath>', - Find or create the test file. Look for
foo.test.ts(or.test.tsx) co-located withfoo.ts. If absent, scaffold using the project pattern (jest + ts-jest + jsdom + @testing-library/react for components, or just jest + ts-jest for pure logic). - Run the test in isolation with
pnpm --filter portal test -- --testPathPatterns=<relative/path/to/foo.test.ts>. Cap at 60s — full suite is part ofpnpm quality. - Report coverage delta by running
pnpm --filter portal test -- --coverage --testPathPatterns=<relative/path>and comparing against the existing baseline (currently 40% lines, 30% branches, 35% functions, 40% statements per CLAUDE.md). - Common pitfalls to surface:
Cannot find module '@repo/ui/widgets/X'— wildcard pattern didn't catch it; add an explicit entryJest encountered an unexpected tokenin TSX — usually a transform config issue, not a mapping issue- Test passes locally but fails in CI — usually a missing env var; check
apps/portal/.env.example
Agents to consider
| Agent | When |
|---|---|
test-writer |
New unit test for a pure function or component |
integration-tester |
E2E / cross-app flows |
frontend-developer |
Component-level tests, render output, user interaction |
Anti-patterns
- Editing
moduleNameMapperto a wildcard ('@repo/.*': '<rootDir>/...') — breaks the existing precedence and often silently resolves to the wrong subpath. Always add explicit entries. - Mocking
@repo/supabase/serverglobally — break the auth flow tests; mock at the test-file level only. - Skipping the mapping check when the test "fails locally, works in dev" — always check the mapping first, even if the import "should" resolve via the catalog.
- Running the full suite when one test fails — the portal Jest config is slow; iterate per-file.
Hook pairing
The portal-test-on-edit PostToolUse hook in .claude/settings.json (async) auto-runs the matching test file when a file in apps/portal/app/api/** or apps/portal/lib/ai/** is edited. This skill handles the slower, more deliberate "add a new test" workflow.