KahWee - Web Development, AI Tools & Tech Trends

Expert takes on AI tools like Claude and Sora, modern web development with React and Vite, and tech trends. By KahWee.

Mocha v3: Major Improvements to the Test Runner

[2025 Update: Mocha remains a popular JavaScript testing framework. While newer tools like Jest and Vitest have emerged, Mocha's flexibility and plugin ecosystem keep it relevant. The .only() improvements described here became foundational to modern test filtering.]

Mocha v3 fixes several long-standing frustrations with the test runner.

What Changed

Dropping Node.js v0.8 Support

Due to the increasing difficulty of applying security patches and looming incompatibilities with Node.js v7.0, Mocha no longer supports Node.js v0.8.

Node v0.8 shipped in 2012. Maintaining compatibility held back developer tool improvements. By the time v3 shipped, most teams had moved to newer Node versions.

The .only() Fix

.only() is no longer "fuzzy", can be used multiple times, and works like you'd expect.

Before v3, .only() broke in confusing ways:

describe.only('Feature A', () => {
  it('test 1', () => { /* runs */ });
  it('test 2', () => { /* runs */ });
});

describe('Feature B', () => {
  it.only('test 3', () => { /* doesn't run?! */ });
});

In Mocha v2, a describe.only() anywhere prevented individual it.only() calls in other suites from running, which was unpredictable.

After v3, multiple .only() calls work correctly:

describe.only('Feature A', () => {
  it('test 1', () => { /* runs */ });
});

describe.only('Feature B', () => {
  it('test 3', () => { /* also runs */ });
});

During debugging, you often want to isolate specific tests without commenting out entire suites. The new .only() makes test-driven development much smoother.

Better Visual Feedback

The dot reporter now uses more distinct characters for "pending" and "failed" tests.

Sounds minor, but it matters when you stare at terminal output all day. Clear distinction between passing (.), pending (,), and failing (!) tests helps you spot problems faster.

Upgrading from v2

I upgraded two repositories at work. The migration was smooth with the latest Karma and Chai.

Compatibility notes:

  • Works with Karma v1.x
  • Works with Chai v3.x
  • Node v0.8 projects need to upgrade Node first
  • .only() behavior changes might reveal hidden test dependencies

If your tests relied on the old "fuzzy" .only(), you might see different tests running after upgrade. That's good—your test isolation wasn't working correctly before.

The Testing Landscape in 2016

Mocha dominated JavaScript testing in 2016. Jasmine was the main alternative, but Mocha's flexibility and plugin ecosystem (Chai for assertions, Sinon for mocks) made it the go-to for serious projects.

The .only() fix alone justified the upgrade for most teams.

See the full changelog for complete details.

Developer tools have come a long way since 2016. The broader trend was toward faster, more integrated tooling—something that became even more apparent with the shift from Webpack to Vite years later.