con un clic
fxa-test-draft
// Drafts Jest tests for changed code. Defaults to staged/unstaged changes or the most recent commit. Output is a starting point for review, not final.
// Drafts Jest tests for changed code. Defaults to staged/unstaged changes or the most recent commit. Output is a starting point for review, not final.
Lists open FXA PRs matching a search term with a rich status table — file/line counts, draft state, review activity, and approval status. Defaults to all open PRs needing review.
Approves the on-hold "Approve Functional Tests (PR)" CircleCI job for the current PR branch, kicking off the gated Playwright functional tests. Requires CIRCLECI_TOKEN in the environment.
Reviews changed React/TSX code for component design, hooks misuse, performance, accessibility, and state management issues. Reports findings with severity and concrete fix recommendations. Operates on files changed vs main.
Fast single-pass FXA-specific commit review covering security, conventions, logic/bugs, tests, and migrations. No subagents — runs directly in the main context.
Thorough FXA-specific commit review using parallel specialist agents. Covers security, TypeScript, logic/bugs, test quality, and architecture. Agents explore call sites, git history, and monorepo conventions.
Validates that Jest tests in a given file pass both as a full suite and individually in isolation, catching hidden order dependencies and shared mutable state.
| name | fxa-test-draft |
| description | Drafts Jest tests for changed code. Defaults to staged/unstaged changes or the most recent commit. Output is a starting point for review, not final. |
| allowed-tools | Bash, Read, Grep, Glob |
| argument-hint | ["file-path | commit-ref | git-range"] |
| user-invocable | true |
| context | fork |
Draft Jest tests for changed code following FXA conventions and the project testing guidelines. Output is a draft — review before committing.
Read the shared testing guidelines before proceeding:
.claude/skills/fxa-testing-shared/GUIDELINES.md
If any of the changed files are React/TSX (fxa-settings and similar), also read Section 5 ("Testing Patterns (React/TSX)") of .claude/skills/fxa-check-react/SKILL.md and apply those rules to drafted component tests.
If $ARGUMENTS is provided, use it as the target (file path, commit ref, or git range). Otherwise determine scope automatically:
git diff HEAD # unstaged
git diff --cached # staged
If either produces output, that is your scope.
git diff HEAD~1..HEAD
Read the full diff before proceeding.
From the diff, extract files that:
*.spec.ts, *.test.ts, *.test.tsx)For each source file, check whether a co-located test file already exists and what it already covers. Most times, tests will be co-located but can be in a dedicated test[s]/ directory.
For each source file, read nearby test files and shared mocks to understand the conventions in that package. Substitute <pkg> with the package directory (e.g. fxa-auth-server, fxa-settings) and <src-dir> with the directory of the source file under test.
# 1. Find existing tests near the source file (auth-server uses *.spec.ts in lib/,
# fxa-settings uses co-located *.test.tsx next to components)
find packages/<pkg>/<src-dir> -maxdepth 2 \( -name '*.spec.ts' -o -name '*.test.ts' -o -name '*.test.tsx' \) | head -20
# 2. Find shared mocks at the package root (e.g. packages/fxa-auth-server/test/mocks.js
# exposes mockDB, mockLog, mockMailer, mockPush, etc.)
find packages/<pkg>/test -maxdepth 3 \( -iname 'mocks*' -o -iname 'mock-*' \) 2>/dev/null
# 3. Read a representative existing test in the package to mirror its jest.mock layout,
# setup/teardown structure, and any custom matchers
grep -rn 'jest.mock(' packages/<pkg> --include='*.spec.ts' --include='*.test.ts' --include='*.test.tsx' | head -10
# 4. For React tests in fxa-settings: see how providers are wrapped (Intl, Router, etc.)
grep -rn 'renderWithProviders\|MockedProvider\|IntlProvider' packages/fxa-settings/src --include='*.test.tsx' | head -5
Determine:
*.spec.ts (auth-server lib/) or *.test.tsx (fxa-settings)mockDB, mockLog, mockMailer, mockPush, etc. from test/mocks.jsjest.mock() is structured in this packageFor each changed function or module, identify:
if/else, switch, ternary, optional chaining pathCall out any code that is difficult to test due to:
new Foo() instantiation inside logic)Do not skip coverage for hard-to-test code — flag it explicitly and suggest a refactor where applicable.
Pick the right layer before drafting. Before writing route-handler or component tests, ask: is the branching here business logic, or wiring? If the changeset has nuanced internal rules (validation, calculation, decision logic) sitting inside a route handler or component, propose extracting the rule first and unit-testing the extracted unit. Reserve route/component tests for wiring (auth, request/response shape, error propagation, rendering). Heavy per-branch fixtures at the route/component level are the signal you're testing at the wrong layer.
Before writing any code, output a test plan table for the engineer to review:
| File | Function / Handler | Type | Proposed test name |
|---|---|---|---|
lib/account.ts | getAccount | happy path | returns account when found |
lib/account.ts | getAccount | error | throws NotFound when account does not exist |
lib/account.ts | getAccount | edge case | returns null when db returns empty result |
Include a row for every case identified in Step 4. Mark any cases flagged as difficult to test with a ⚠️ and a brief inline note.
Pause here. Ask the engineer if the coverage looks right, if any cases should be added or removed, or if the scope should be adjusted. Do not proceed to drafting until confirmed.
Write Jest tests for each identified case following the shared guidelines.
Place tests in the co-located test file (*.spec.ts or *.test.tsx). If the file doesn't exist, create it with the MPL-2.0 license header at the top.
Leave things better than you found them. When adding tests to an existing file, write new tests to the guidelines standard — don't copy existing patterns that violate them. If existing tests have clear issues, note them in the output and suggest the engineer run /fxa-test-repair. Don't rewrite existing tests wholesale unless that's explicitly in scope.
After drafting, consider running /fxa-test-independence to verify the new tests pass both as a suite and in isolation.
For each source file, produce:
If a test file already exists, show only the new blocks to add, not the full file.
Remind the user: these are drafts. Review mock return values, error types, and edge case assumptions before committing.