Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda