fxa-test-independence

Validates Jest tests pass both as a full suite and in isolated runs.

685|236|Updated Jun 3, 2015
One-click install
npx skills add https://github.com/mozilla/fxa --skill fxa-test-independence
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fxa-test-independence
Source: https://github.com/mozilla/fxa/tree/main/.claude/skills/fxa-test-independence
Command: npx skills add https://github.com/mozilla/fxa --skill fxa-test-independence

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Jest tests that pass in a full suite but fail when run alone hide order dependencies and shared mutable state, masking real bugs in the test suite. This Skill detects those hidden dependencies by running every test twice and comparing results.

Core Features & Use Cases

  • Dual-mode execution: Runs the full spec file once, then re-runs each it(...)/test(...) individually with --testNamePattern from the correct package root.
  • Classified diagnosis: Labels each test as OK, ORDER DEPENDENCY, FALSE POSITIVE, or BROKEN, with likely causes such as missing beforeEach resets or polluted shared mocks.
  • Use Case: After editing packages/fxa-auth-server/lib/account.spec.ts, invoke the Skill to confirm all 12 tests pass both together and in isolation before committing.

Quick Start

Ask the assistant to validate test independence for a given spec file, for example: run fxa-test-independence on packages/fxa-auth-server/lib/metricsCache.spec.ts.

Frequently Asked Questions about fxa-test-independence

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

FAQPage Schema
How do I check if my Jest tests have order dependencies?

Run the full spec file once, then re-run each test individually using npx jest with --testNamePattern for the exact test name. A test that passes in the suite but fails alone has an order dependency on state set by a prior test.

How to run a single Jest test by name in a monorepo package?

Change into the package root so the local jest.config is picked up, then run npx jest <relative-spec-path> --testNamePattern="<exact test name>" --no-coverage. Avoid nx test-unit, which runs the entire package suite regardless of the file argument.

Why does my Jest test pass in the suite but fail when run alone?

This indicates an order dependency: a prior test mutates shared module-level state, a singleton is not re-initialized, or a missing beforeEach reset leaves stale data. The fix is to isolate state per test rather than change the implementation.

What does it mean when a test passes alone but fails in the full suite?

That is a false positive pattern: the test pollutes shared state, such as mutating a global mock without an afterEach cleanup, which breaks other tests. Add proper teardown so each test leaves shared state untouched.

Does this Jest validation modify or fix my failing tests automatically?

No. It reports a results table with failure output, a diagnosis of likely causes, and a suggested concrete fix for each non-OK test, but the engineer decides whether and how to apply the fix.