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

61
Visualizações
Mocha report to contain only failed cases

I want to cofigure mocha report to only contain failed cases. I am using below code to read js test files and send mail on completion . I want to send only failure cases. How to configure it in mocha ?

const Mocha = require('mocha');
const fs = require('fs');
const path = require('path');
const mocha = new Mocha({});
const sendMail = require('./sendMail');
const error = require('./errMsg');

async function executeMocha() {
    const testDirPath = path.resolve('./') + '/test';
    fs.readdirSync(testDirPath).filter(function (file) {
        // Only keep the .js files
        return file.substr(-3) === '.js';
    }).forEach(function (file) {
        mocha.addFile(
            path.join(testDirPath, file)
        );
    });

    mocha.reporter('mocha-simple-html-reporter', { output: '/tmp/testspec.html' }).run(
        async (err,res) => {
            if(err){
                console.log("\n\n\n\nTest Case FAAAAAAAAAAILLLLLL \n\n\n\n");
            }
            console.log("\n\n\n\nTest Case Execution Successfull\n\n\n\n");
            await getResult();
        }
    );
}

async function getResult() {
    fs.readFile(('/tmp/testspec.html'), 'utf8', async (err, res) => {
        if (err) {
            await sendMail((process.env.env_type +error.fail.subject + process.env.CB_TEST_URL ), error.fail.body + err);
        }
        await sendMail((process.env.env_type +error.success.subject + process.env.CB_TEST_URL ), res);
    })
}

module.exports = executeMocha
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Um, assuming in your mocha.reporter function that that if(err) the test case is a fail, u can just do this(however I'm not even sure what would be a fail for u, not seeing you wanting any specific results or anything)

const Mocha = require('mocha');
const fs = require('fs');
const path = require('path');
const mocha = new Mocha({});
const sendMail = require('./sendMail');
const error = require('./errMsg');

async function executeMocha() {
    const testDirPath = path.resolve('./') + '/test';
    fs.readdirSync(testDirPath).filter(function (file) {
        //in case someone has a FOLDER named with '.js' at the end
        if(!fs.lstatSync(file).isFile()){return null}
        // Only keep the .js files
        return file.substr(-3) === '.js';
    }).forEach(function (file) {
        mocha.addFile(
            path.join(testDirPath, file)
        );
    });

    mocha.reporter('mocha-simple-html-reporter', { output: '/tmp/testspec.html' }).run(
        async (err,res) => {
            if(err){
                console.log("\n\n\n\nTest Case FAAAAAAAAAAILLLLLL \n\n\n\n");
                return await sendMail((process.env.env_type +error.fail.subject + process.env.CB_TEST_URL ), error.fail.body + err);
            }
            console.log("\n\n\n\nTest Case Execution Successfull\n\n\n\n");
        }
    );
}

async function getResult() { //error would only happen here if there was a problem READING the html file, unsure where the js files in question would be responsible
    fs.readFile(('/tmp/testspec.html'), 'utf8', async (err, res) => {
        if (err) {
            await sendMail((process.env.env_type +error.fail.subject + process.env.CB_TEST_URL ), error.fail.body + err);
        }
        await sendMail((process.env.env_type +error.success.subject + process.env.CB_TEST_URL ), res);
    })
}

module.exports = executeMocha
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