writing-tests

Write and organize bun:test tests with mock isolation rules.

1|Updated May 17, 2026
One-click install
npx skills add https://github.com/djimit/djimitflo --skill writing-tests-djimit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/djimit/djimitflo/tree/main/.opencode/skills/writing-tests
Command: npx skills add https://github.com/djimit/djimitflo --skill writing-tests-djimit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires bun:test, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill unit addresses the need for clear guidelines and best practices for writing, organizing, and maintaining tests in the opencode-swarm repository, ensuring consistent quality and reliability of the testing process.

Core Features & Use Cases

  • Test Writing Guidelines: Provides detailed instructions on how to write tests according to the bun:test framework and bun:test compatibility layer.
  • Mock Isolation Rules: Defines critical rules for isolating mocks within the same Bun process to prevent pollution.
  • Framework and Mocking: Outlines the use of bun:test for testing and the preferred APIs for mocking to ensure isolation and type safety.
  • Mocking Best Practices: Offers best practices for mocking Node built-ins, other application modules, and within the same module.
  • Test Isolation Failures: Suggests a protocol for diagnosing and resolving test isolation failures when tests pass individually but fail when run together.
  • Two-Tier Mock Convention: Explains the two-tier strategy for mock isolation and a zero-mock testing pattern for file-scoped mocks.
  • Mock Module Export Completeness: Ensures that all named exports of the target module are provided when using mock.module().

Quick Start

Load the writing-tests skill to review the guidelines and rules for writing tests in the opencode-swarm repository.

Frequently Asked Questions about writing-tests

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

FAQPage Schema
How do I isolate mocks in bun:test to prevent test pollution?

Mocks are isolated in bun:test by applying a two-tier mock convention strategy and ensuring all named exports of the target module are provided when using mock.module(). This prevents state leakage within the same Bun process.

Why do my bun:test tests pass individually but fail when run together?

Tests passing individually but failing together indicates a test isolation failure. Diagnose this by checking for mock pollution and verifying that mock.module() provides complete named exports for all targeted modules.

What are the best practices for mocking Node built-ins with bun:test?

Best practices for mocking Node built-ins with bun:test involve using preferred mocking APIs to ensure isolation and type safety. Follow specific guidelines for mocking built-ins, application modules, and within the same module.

Do I need the bun:test compatibility layer to write tests for opencode-swarm?

Yes, writing tests for the opencode-swarm repository requires the bun:test framework and the bun:test compatibility layer. This ensures adherence to the repository's specific test writing guidelines and mocking strategies.

What is the zero-mock testing pattern for file-scoped mocks?

The zero-mock testing pattern is a file-scoped isolation strategy within the two-tier mock convention. It defines rules for isolating mocks within the same Bun process to prevent pollution and ensure reliable testing.