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 is a major update that fixes some long-standing frustrations with the test runner.

What Changed and Why It Matters

Dropping Node.js v0.8 Support

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

This makes sense. Node v0.8 was released in 2012 and maintaining compatibility was holding back developer tool improvements. By the time v3 shipped, most teams had moved to newer Node versions anyway.

The .only() Fix Everyone Wanted

.only() is no longer "fuzzy", can be used multiple times, and generally just works like you think it should.

Before v3, .only() was broken 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, if you had a describe.only() anywhere, individual it.only() calls in other suites wouldn't run. The behavior was "fuzzy" and 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 */ });
});

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

Better Visual Feedback

The dot reporter now uses more visually distinctive characters when indicating "pending" and "failed" tests.

This sounds minor but matters when you're staring at terminal output all day. Clear visual distinction between passing (.), pending (,), and failing (!) tests helps you spot problems faster.

Upgrading from v2

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

Key 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() behavior, you might see different tests running after upgrade. This is a good thing—it means 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 choice for serious projects.

The v3 release showed the maintainers were listening to real developer pain points. 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. While Mocha's improvements were significant at the time, the broader trend was toward faster, more integrated tooling—something that became even more apparent with the shift from Webpack to Vite years later.