Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda