A comprehensive Mocha test adapter that integrates seamlessly with VS Code's native Testing API. Run, debug, and get coverage for your Mocha tests with a rich, feature-packed experience.
- Native Testing UI - Uses VS Code's built-in Testing API for a familiar experience
- Automatic Discovery - Finds
.test.{js,ts}and.spec.{js,ts}files automatically - Run & Debug - Execute and debug individual tests, suites, or entire files
- Nested Suites - Full support for nested
describeblocks with proper hierarchy - TypeScript & JavaScript - Works with both TS and JS test files seamlessly
- Beautiful Test Output - Color-coded results with ✓ pass, ✗ fail, ○ skip indicators
- Test Timings - Shows duration for each test with slow test warnings (⚠ slow)
- Detailed Summaries - Clear statistics showing passed, failed, skipped, and slow tests
- Nested Suite Formatting - Tests grouped under parent suites with proper indentation
- Failure Grouping - Failed tests collected at the end with detailed error info
- Problems Integration - Test failures appear in VS Code's Problems panel (⇧⌘M)
- Clickable Stack Traces - Jump directly to failing code from error messages
- Diff Viewer - Shows expected vs actual values for assertion failures
- Code Coverage - Built-in coverage with c8, showing statement and branch coverage
- Continuous Run - Auto-run tests on file save with smart source-to-test mapping
- Test Tags - Organize tests with
@unit,@integration,@e2etags - Config File Support - Loads
.mocharc.{js,json,yaml}orpackage.jsonconfig - Hot Reload - Config changes auto-reload tests (500ms debounce)
- Context Menu - Right-click actions: Go to Test, Copy Name, Run Only This, Reveal in Explorer
- Yarn PnP Support - Full compatibility with Yarn 2+ Plug'n'Play
- Install the extension from the VS Code Marketplace
- Install Mocha and c8 in your project:
npm install --save-dev mocha c8
# or
yarn add -D mocha c8- Open the Testing view (🧪 icon in Activity Bar)
- Tests will be automatically discovered!
- All tests: Click
▶️ at the top of the Testing view - File tests: Click
▶️ next to a test file - Suite tests: Click
▶️ next to adescribeblock - Single test: Click
▶️ next to anitblock
Click 🐛 instead of
- Set breakpoints in your test code
- Step through execution
- Inspect variables
- Click the Coverage button (🔬) in Testing view
- View coverage in editor gutters (green/red lines)
- Check detailed coverage in Test Coverage view
Click the terminal icon (�) in Testing panel to see:
- Formatted test results with suite hierarchy
- Console.log output from tests
- Detailed failure information with diffs
Organize tests with tags for targeted test runs:
describe('User API @integration @api', () => {
it('should create user @smoke', () => {
// Test code
});
});Use tag-specific profiles (Unit, Integration, E2E) to run filtered test subsets.
The extension respects your Mocha configuration files:
.mocharc.js,.mocharc.cjs.mocharc.json,.mocharc.jsonc.mocharc.yaml,.mocharc.ymlmochasection inpackage.json
Supported options include: timeout, slow, grep, bail, retries, require, and more.
Configuration changes are automatically detected and tests are rediscovered.
test/example.test.ts
Running 5 tests...
Example Test Suite
Math operations
✓ should add two numbers correctly (2ms)
✓ should multiply two numbers correctly (1ms)
String operations
✓ should concatenate strings (1ms)
Test Results: 3 passing (4ms)
Failed Tests:
Math Suite > Advanced > should calculate correctly
Expected values to be strictly equal:
42 !== 41
+ expected - actual
-42
+41
at Context.<anonymous> (test/math.spec.js:15:14)
Tests exceeding the slow threshold (default 75ms) are highlighted:
✓ should process data ⚠ slow (150ms)
- VS Code: 1.88.0 or higher
- Mocha: 10.x
- c8: 10.x (for coverage support)
Found a bug or have a feature request? Please open an issue on GitHub.
MIT - See LICENSE for details
Built with VS Code's Testing API and powered by Mocha and c8.
Enjoy testing! 🧪✨
When tests fail, you get detailed information:
- Stack Traces: Clickable links to the exact line where the error occurred
- Assertion Diffs: For failed assertions, see expected vs. actual values side-by-side
- Error Context: Full error messages with all details from Mocha
Click on any stack trace line to jump directly to that location in your code.
Organize your tests using tags to run specific subsets of tests:
Tagging Tests:
Use [tag] or @tag syntax in test names:
describe('[unit] Math utilities', () => {
it('@slow should calculate factorial', () => {
// Test code
});
});
describe('@integration API tests', () => {
it('[e2e] should handle full workflow', () => {
// Test code
});
});Running Tagged Tests: The extension creates separate run profiles for different tags:
- Click the dropdown arrow next to the Run button in the Testing view
- Select a tag-specific profile:
- Run Unit Tests - Only runs tests tagged with
[unit]or@unit - Run Integration Tests - Only runs
@integrationtests - Run E2E Tests - Only runs
[e2e]tests
- Run Unit Tests - Only runs tests tagged with
- Only tests with matching tags will execute
How It Works:
- Tests with
[unit]or@unittags can ONLY be run via the "Run Unit Tests" profile - Tests without tags can be run with the default "Run Tests" profile
- VS Code's Testing API ensures tests only appear under their matching profiles
- This prevents accidentally running slow integration/e2e tests during unit test runs
Common Tags:
unit- Fast, isolated unit testsintegration- Integration tests with external dependenciese2e- End-to-end testsslow- Tests that take longer to run
Tag Inheritance: Tests automatically inherit tags from their parent describe blocks.
Enable auto-run on save for instant feedback during TDD:
- Click the continuous run button (⏯️) in the Testing view toolbar
- Select which profile to watch (Run Tests, Unit Tests, etc.)
- Save any file → Corresponding tests automatically run after 1 second
- See instant results without clicking anything
- Click stop (⏹️) to disable continuous mode
Smart File Mapping:
- ✅ Source files → Automatically finds and runs corresponding test files
src/math.ts→ Runssrc/math.test.tsortest/math.test.ts- Supports multiple patterns:
*.test.ts,*.spec.ts,__tests__/*.ts, etc.
- ✅ Test files → Runs the saved test file directly
- ✅ Only changed tests run - Saves
math.ts→ Only runsmath.test.ts, not entire suite - ✅ 1-second debounce - Multiple saves within 1 second batched into single run
- ✅ Fast unit tests shine - Typical unit test file completes in <1 second
⚠️ E2E tests disabled - Continuous mode not available for slow E2E tests
Perfect for:
- Test-Driven Development (TDD) workflows
- Red-Green-Refactor cycles
- Immediate feedback when modifying implementation
- Catching regressions instantly as you code
You have two ways to configure Mocha options:
Create a Mocha configuration file in your project root. The extension automatically loads configuration from:
.mocharc.jsor.mocharc.cjs(JavaScript - can export a function).mocharc.jsonor.mocharc.jsonc(JSON with comments support).mocharc.yamlor.mocharc.yml(YAML - requiresyamlorjs-yamlpackage)package.json(add a"mocha"property)
Example .mocharc.js:
module.exports = {
// Test behavior
timeout: '5s', // Can be number (ms) or string ('5s')
slow: 100,
bail: false,
retries: 2,
allowUncaught: false,
asyncOnly: false,
checkLeaks: false,
forbidOnly: false,
forbidPending: false,
// File handling
require: ['@babel/register'],
extension: ['ts', 'tsx'],
recursive: true,
ignore: ['**/.git/**', '**/node_modules/**'],
// Test filtering
grep: 'should', // String or RegExp
fgrep: 'API', // Fixed string match
invert: false,
// Parallel execution
parallel: false,
jobs: 4,
// Reporting
reporter: 'spec',
inlineDiffs: true,
color: true,
diff: true
};Example .mocharc.json:
{
"timeout": 10000,
"slow": 100,
"bail": false,
"reporter": "spec",
"inlineDiffs": true,
"retries": 2,
"require": ["@babel/register"],
"extension": ["ts", "tsx"]
}Example package.json:
{
"mocha": {
"timeout": "10s",
"slow": 100,
"inlineDiffs": true
}
}Configuration Priority:
- Command-line arguments (not applicable in VS Code context)
.mocharc.js→.mocharc.cjs→.mocharc.yaml→.mocharc.yml→.mocharc.jsonc→.mocharc.json→package.json- Extension defaults
Hot-Reload:
- Configuration files are automatically watched for changes
- When a config file changes, it's reloaded and tests are rediscovered (500ms debounce)
- If a config file is deleted, defaults are restored
- No extension reload needed!
The extension respects the following Mocha configuration options. Configuration files are the only way to configure the extension (no UI-based configuration).
✅ Fully Implemented (8 properties):
timeout(number | string): Test timeout in milliseconds. Supports strings like "5s". (Default: 5000)slow(number): Threshold for marking tests as slow in milliseconds. (Default: 75)bail(boolean): Stop test execution after first failure. (Default: false)grep(string | RegExp): Only run tests matching pattern. Converted to string if RegExp. (Default: undefined)extension(string[]): File extensions to consider as test files (e.g.,['ts', 'mjs', 'cjs']). (Default: ['js', 'ts'])retries(number): Number of times to retry failed tests. Useful for flaky tests. (Default: 0)require(string[]): Modules to load before running tests (e.g.,['ts-node/register']). (Default: [])ignore(string[]): Glob patterns to exclude from test discovery (e.g.,['**/*.helper.js']). (Default: [])
🚧 Work In Progress (9 properties):
fgrep(string): Fixed string match for test filtering (simpler than regex)invert(boolean): Invert grep/fgrep matches (exclude tests instead of include)forbidOnly(boolean): Fail if.only()tests found (CI validation)forbidPending(boolean): Fail if pending/skipped tests foundcheckLeaks(boolean): Check for global variable leaks between testsallowUncaught(boolean): Allow uncaught exceptions to propagate (debugging)asyncOnly(boolean): Require all tests to be asyncfile(string[]): Files to load before other test files (global setup)nodeOption(string[]): Node.js command-line options (e.g., memory limits)
🚫 Not Applicable (14 properties): These properties conflict with VS Code's Test Explorer or are redundant in an IDE context:
reporter,spec,watch,watchFiles,watchIgnore: VS Code Test Explorer provides these featuresrecursive: Extension always searches recursivelyparallel,jobs: VS Code Test Explorer manages executionui: Extension only supports BDD interface (describe,it)color,diff,inlineDiffs,fullTrace: VS Code handles output formattinggrowl,delay,dryRun,failZero: Not relevant in IDE contextdelay(boolean): Delay root suite executiondryRun(boolean): Report tests without runningfailZero(boolean): Fail if no tests foundnodeOption(string[]): Node.js optionspackage(string): Path to package.jsonconfig(string | false): Path to config file or disablespec(string[]): Test file patterns (extension discovers files automatically)
🔮 Future Implementation Priority:
retries- Useful for flaky tests, easy to implement in test runnerfgrep/invert- Simple filtering additions to grep functionalityignore- Filter out specific files from test discoveryparallel- Significant performance improvement for large test suitesinlineDiffs/diff/color- Better test output formattingreporter- Allow custom Mocha reporters (currently hardcoded to JSON)forbidOnly/forbidPending- CI-friendly test validation
All configuration properties are loaded and stored by the extension, but only the "Fully Implemented" ones currently affect extension behavior. Properties marked "Not Yet Implemented" are available for future development.
- Click the dropdown arrow next to "Run Tests" in the Testing view
- Select "Configure Test Profiles..." from the menu
- Choose which profile to configure (Run Tests, Debug Tests, etc.)
- Enter your preferences in the dialogs:
- Timeout: Maximum time for tests (default: 5000ms)
- Grep Pattern: Filter tests by name (e.g., "should work" or "/pattern/")
- Slow Threshold: Mark tests as slow above this duration (default: 75ms)
- Bail: Stop after first test failure (useful for debugging)
Note: UI configuration applies to the current session only. For persistent configuration, use a config file.
Configuration file settings are loaded at startup and take precedence over defaults. UI configuration temporarily overrides both.
If tests don't appear, open the Command Palette (⇧⌘P on Mac, Ctrl+Shift+P on Windows/Linux) and run:
Mocha: Refresh Tests
The extension logs all activity to an output channel:
- Open the Output panel: View → Output (or ⇧⌘U on Mac, Ctrl+Shift+U on Windows/Linux)
- Select "Mocha Tests" from the dropdown
- You'll see detailed logs of:
- Extension activation
- Test discovery
- File watching events
- Test execution
- Errors and stack traces
This is helpful for debugging issues or understanding what the extension is doing.
The extension recognizes standard Mocha test patterns:
import { describe, it } from 'mocha';
import * as assert from 'assert';
describe('Math Operations', () => {
it('should add numbers', () => {
assert.strictEqual(2 + 2, 4);
});
describe('Multiplication', () => {
it('should multiply numbers', () => {
assert.strictEqual(3 * 4, 12);
});
});
});**/*.test.ts- TypeScript test files**/*.spec.ts- TypeScript spec files**/*.test.js- JavaScript test files**/*.spec.js- JavaScript spec files
See DEVELOPMENT.md for detailed development instructions.
yarn install
yarn compilePress F5 in VS Code to launch the extension in debug mode.
- TypeScript with ESM modules
- ESLint with flat config (latest)
- Prettier for code formatting
- Mocha test framework
- Yarn 4 with Plug'n'Play (PnP)
- Test parsing is based on regex patterns (may not catch all edge cases)
- Only 5 Mocha configuration options are fully implemented (see Configuration section for details)
- Parallel test execution not yet supported (parallel: true ignored)
- Custom Mocha reporters not supported (extension uses JSON reporter internally)
- Some configuration options like
ignorepatterns not yet applied during test discovery
This is an early version. Contributions, bug reports, and feature requests are welcome!
MIT