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

59
Vistas
Informe de Mocha para contener solo casos fallidos

Quiero cofigurar el informe mocha para que solo contenga casos fallidos. Estoy usando el siguiente código para leer archivos de prueba js y enviar correo al finalizar. Quiero enviar solo casos de falla. ¿Cómo configurarlo en 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 Respuestas
Responde la pregunta

0

Um, suponiendo en su función mocha.reporter que if(err) el caso de prueba es un error, puede hacer esto (sin embargo, ni siquiera estoy seguro de qué sería un error para usted, no veo que desee ningún resultado específico o algo)

 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 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