Debug issues and write tests for deployed applications. Use this skill when the user reports bugs, wants to add tests, or needs help troubleshooting. Covers unit testing for rapid iteration, browser console debugging, and systematic bug reproduction.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
The command stays on one line. Scroll horizontally to inspect it before copying.
Prefer a local copy? Download the files currently available to SkillsMP.
Showing SKILL.md
SKILL.md
Source instructions · Read-only preview
name
testing-debugging
description
Debug issues and write tests for deployed applications. Use this skill when the user reports bugs, wants to add tests, or needs help troubleshooting. Covers unit testing for rapid iteration, browser console debugging, and systematic bug reproduction.
license
Complete terms in LICENSE.txt
Testing and Debugging
This skill guides debugging deployed applications and writing tests for rapid iteration. The key insight: unit tests are the fastest way to reproduce and fix bugs.
The Unit Test Debugging Workflow
This is the most effective debugging workflow. Instead of repeatedly deploying and manually testing in the browser, write a unit test that reproduces the bug:
Why Unit Tests for Debugging?
Approach
Cycle Time
Reliability
Deploy → Browser → Manual test
30-60 seconds
Variable
Run unit test
1-2 seconds
Consistent
A 30x speedup means you can iterate 30 times faster. This compounds: what takes an hour with manual testing takes 2 minutes with unit tests.
The Workflow
Understand the bug - Read the user report, check console errors, understand expected vs actual behavior
Write a failing test - Create a test that reproduces the exact failure
// Example: User reports "discount not applied to cart total"test('applies discount code to cart total', () => {
const cart = createCart([
{ name: 'Widget', price: 100 },
{ name: 'Gadget', price: 50 }
]);
cart.applyDiscount('SAVE20'); // 20% offexpect(cart.total).toBe(120); // Was returning 150
});
Run the test to confirm it fails - Verify you've reproduced the bug
bun test
Fix the code - Make changes to fix the failing test
Run the test again - Confirm the fix works
bun test
Deploy - Once tests pass, deploy with confidence
bun deploy
Test File Location
Place test files next to the code they test:
src/
cart.ts
cart.test.ts # Tests for cart.ts
utils/
discount.ts
discount.test.ts
Or use a __tests__ directory:
src/
cart.ts
__tests__/
cart.test.ts
Writing Effective Debug Tests
Isolate the Problem
Test the smallest unit that could be failing:
// Bad: Tests too much, hard to pinpoint failuretest('checkout flow works', async () => {
awaitaddToCart(item);
awaitapplyDiscount('CODE');
awaitenterShipping(address);
awaitprocessPayment(card);
expect(order.status).toBe('complete');
});
// Good: Isolates the discount logictest('applyDiscount calculates percentage correctly', () => {
const subtotal = 100;
const result = applyDiscount(subtotal, { type: 'percent', value: 20 });
expect(result).toBe(80);
});
import { vi } from'vitest';
test('displays error when API fails', async () => {
// Mock the fetch to simulate API failure
vi.spyOn(global, 'fetch').mockRejectedValue(newError('Network error'));
const result = awaitloadUserData('user-123');
expect(result.error).toBe('Failed to load user data');
});
functionprocessOrder(order: Order) {
debugger; // Browser will pause here when DevTools is open// ... rest of function
}
Common Bug Patterns
Off-by-One Errors
// Bug: Loop skips last itemfor (let i = 0; i < items.length - 1; i++) { ... }
// Fix: Include last itemfor (let i = 0; i < items.length; i++) { ... }
Async/Await Issues
// Bug: Not awaiting async functionfunctionloadData() {
const data = fetchData(); // Returns Promise, not data!returnprocessData(data);
}
// Fix: Await the promiseasyncfunctionloadData() {
const data = awaitfetchData();
returnprocessData(data);
}
Type Coercion
// Bug: String concatenation instead of additionconst total = price + tax; // "100" + "10" = "10010"// Fix: Parse numbersconst total = Number(price) + Number(tax); // 110
Null/Undefined Access
// Bug: Accessing property on undefinedconst name = user.profile.name; // Crashes if profile is undefined// Fix: Optional chainingconst name = user?.profile?.name ?? 'Unknown';
Test Commands
# Run all tests
bun test# Run tests in watch mode (re-runs on file changes)
bun test --watch
# Run a specific test file
bun test src/cart.test.ts
# Run tests matching a pattern
bun test -t "discount"# Run with coverage report
bun test --coverage
E2E Testing with Playwright
Playwright is available as a project dependency in the starter template. Install browser binaries on demand before running end-to-end tests, for example with bunx playwright install chromium.
Private apps require authentication. Use the CHIRIDION_APP_SESSION env var (automatically available in the sandbox) to set the dispatcher session cookie: