Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Is it possible to remove the millisecond speed reported by Mocha?

In the Mocha/Chai javascript testing framework is it possible to remove the millisecond speed reported by Mocha?

I'd like an easier way to compare outputs from different tests, and currently each test line shows a diff since the speed (ms) varies from run to run.

test1.js
    description here
      ✔ should do the things (211ms)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Mocha use spec as its default reporter.The spec reporter inherits from Base reporter. It use .epilogue() method of Base for EVENT_RUN_END event.

The method will print the milliseconds, the source code:

Base.consoleLog(fmt, stats.passes || 0, milliseconds(stats.duration));

You can create a custom reporter for mocha.

./reporters/tidy.js:

const Mocha = require('mocha');
const { EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS } = Mocha.Runner.constants;

class Tidy {
  constructor(runner) {
    const stats = runner.stats;
    runner
      .on(EVENT_TEST_PASS, (test) => {
        console.log(`pass: ${test.fullTitle()}`);
      })
      .on(EVENT_TEST_FAIL, (test, err) => {
        console.log(`fail: ${test.fullTitle()} - error: ${err.message}`);
      })
      .once(EVENT_RUN_END, () => {
        console.log(`end: ${stats.passes}/${stats.passes + stats.failures} ok`);
      });
  }
}

module.exports = Tidy;

Use fullTitle() → {string} to

Return the full title generated by recursively concatenating the parent's full title.

It will give you pass: <test suite title> <test case title> string.

Example test:

const { expect } = require('chai');

describe('description here', () => {
  it('should pass', () => {
    expect(1 + 1).to.be.equal(2);
  });
  it('should fail', () => {
    expect(1 + 1).to.be.equal(3);
  });
});

Output:

⚡  npx mocha --reporter ./reporters/tidy.js /Users/dulin/workspace/github.com/mrdulin/expressjs-research/reporters/index.test.js 
pass: description here should pass
fail: description here should fail - error: expected 2 to equal 3
end: 1/2 ok
about 4 years ago · Juan Pablo Isaza Report

0

While the accepted answer is more sophisticated, I've found a much cheaper way to remove the speeds by increasing the --slow option to a very large number since the speed only appears for slow tests.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!