mock-module

Mock Node.js built-in modules by spreading real exports to prevent cross-test pollution.

437|45|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill mock-module
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mock-module
Source: https://github.com/ZaxbyHub/opencode-swarm/tree/main/.opencode/skills/generated/mock-module
Command: npx skills add https://github.com/ZaxbyHub/opencode-swarm --skill mock-module

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Improper mocking of Node.js built-in modules in test suites causes cross-test pollution, leading to flaky, unreliable test results that waste developer time and break CI/CD pipelines.

Core Features & Use Cases

  • Enforces spreading real module exports when mocking Node.js built-ins to isolate test environments
  • Eliminates state leakage between test cases that causes inconsistent, hard-to-debug test failures
  • Use Case: When writing unit tests for a Node.js app that uses the fs or path built-in modules, this skill ensures your mocks don't leak state between test runs, so every test produces consistent, reliable results.

Quick Start

Use the mock-module skill to properly mock the Node.js fs built-in module in your test suite without causing cross-test pollution.

Frequently Asked Questions about mock-module

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

FAQPage Schema
How do I prevent cross-test pollution when mocking Node.js built-in modules?▼

To prevent cross-test pollution when mocking Node.js built-in modules, you must spread the real module's exports when creating mocks. This ensures proper test isolation and eliminates state leakage between test cases.

Why do my Node.js unit tests fail inconsistently when mocking the fs module?▼

Node.js unit tests fail inconsistently when mocking the fs module due to state leakage from improper mocking. Spreading the real module exports isolates the test environment and ensures consistent unit test results.

What is the best way to mock Node.js built-in modules like path or http without leaking state?▼

The best way to mock Node.js built-in modules like path or http without leaking state is to spread the real module's exports during mock creation. This prevents cross-test pollution and ensures reliable test outcomes.

Does improper mocking of Node.js built-in modules break CI/CD pipelines?▼

Improper mocking of Node.js built-in modules does break CI/CD pipelines by causing flaky and unreliable test results. Spreading real module exports resolves this state leakage and stabilizes the test suite.

How do I isolate test environments for Node.js applications that use built-in modules?▼

To isolate test environments for Node.js applications using built-in modules, spread the real module's exports when generating mocks. This prevents cross-test pollution and maintains consistent test runs.