4

I am using mocha, chain, nyc supertest for unit test in my nodejs app. I am able to generate test reports at the end of the run, but is there anyway to send email notifications when a test fails during a test run or email a test report?

sotn
  • 1,833
  • 5
  • 35
  • 65
  • What testing framework are you using? – Lin Du Sep 15 '21 at 05:15
  • Updated post with info. – sotn Sep 15 '21 at 12:14
  • @sotn you can use [`after`](https://mochajs.org/#hooks) hook with [`nodemailer`](https://nodemailer.com/about/) to send report in mail after all the test blocks are completed – Chandan Sep 15 '21 at 14:12
  • @sotn Is this needed when these unit tests run during PR checks in git/bitbucket like in travis or git actions? Because Node libraries require the password to send the mail, which you possibly might need to store in code/db, which might be risky. If you need it locally itself, such libs can help – Omkar Sep 18 '21 at 04:24

1 Answers1

0

@sotn, You can write the mail notification function call inside of after hook, to send the mail with html attachment you can refer to below answer.

Send email with html attachment

Govind
  • 41
  • 4