integration-singleton-isolation

Resets module-level singleton state between integration tests to remove ordering dependencies.

1|Updated Jun 9, 2026
One-click install
npx skills add https://github.com/VilnaCRM-Org/claude-plugins --skill integration-singleton-isolation-vilnacrm-org
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: integration-singleton-isolation
Source: https://github.com/VilnaCRM-Org/claude-plugins/tree/main/plugins/react-frontend-sdlc/skills/integration-singleton-isolation
Command: npx skills add https://github.com/VilnaCRM-Org/claude-plugins --skill integration-singleton-isolation-vilnacrm-org

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integration and unit tests that mutate module-level singletons, environment variables, or shared i18n state leak those mutations into later tests, causing assertions that pass only in one execution order and previously green tests to break when a new case is added. ## Core Features & Use Cases - State Reset Pattern: Restores process.env, singleton bindings, and shared i18n language in a single afterEach hook so every test runs against clean state. - Test Splitting and Precedence Pinning: Splits merged tests that encode ordering dependencies and writes dedicated cases that pin fallback-chain precedence (explicit ?? bound ?? env). - Repository Shape Guidance: Adapts the isolation rules for React SPA, Next.js app, and component-library shapes based on profile keys like framework.di and architecture.source_root. - Use Case: A locale formatter integration test binds a language source and changes the i18n language; without an afterEach reset, every later test formats against the wrong locale. This Skill rewrites the file so each behaviour has its own case and all mutations are reversed. ## Quick Start Ask the AI to fix an integration test file where adding a new test breaks a previously green sibling due to leaked singleton or environment state.

Frequently Asked Questions about integration-singleton-isolation

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

FAQPage Schema
How do I fix tests that only pass in a certain order?▼

Order-dependent tests usually leak module-level state. Restore every mutation the test makes in an afterEach hook, including process.env, singleton bindings, and shared library state like the active i18n language, so each test runs against clean state.

How do I reset a singleton between Jest integration tests?▼

Reset the singleton through its public API, such as bindLanguageSource(null) or set(initialState), inside afterEach. Avoid jest.resetModules(), which gives later tests a different instance than the one resolved at the top of the describe block.

Why does adding a new test break an unrelated passing test?▼

The new test likely mutates shared state that the older test implicitly depends on, such as a bound language source or an environment variable. Split merged assertions into separate cases and reverse all mutations in one afterEach.

Should I reset test state in beforeEach or afterEach?▼

Use afterEach. Resetting only in beforeEach leaves the last test's mutations in place for the next file when the runner shares a module registry, while afterEach guarantees state is restored regardless of execution order.

When does this isolation pattern not apply?▼

It does not apply when state is already scoped per test by the runner, such as React Testing Library cleanup or a fresh store created inside each test. It targets module-level singletons and process-level mutations that outlive individual cases.