0

Is it possible to raise a Warning message within a hook function? I can log a message with hook.log() but would like it to be properly handled as loglevel 'warning'.

hooks.log("WARNING: Something unusual has happened")

TrickiDicki
  • 143
  • 2
  • 13

1 Answers1

0

I'm the Dredd maintainer. You didn't mention whether you use the standard Node.js hooks or the now deprecated and removed sandboxed JavaScript hooks.

In Node.js hooks there's no way you can hack into Dredd's own logging output, but you could implement it on your own. Dredd's logging uses winston, so you could set it up the same way as in Dredd in your hooks and then log a warning, which is going to look like Dredd's warning.

However, my honest advice would be forget about warnings. Make strict rules and let the testing fail. People overlook warnings in the output, or don't read them at all when the project is tested on CI.

Honza Javorek
  • 8,566
  • 8
  • 47
  • 66
  • Thanks for the reply. The issue is that the API under test currently has an unresolved defect that required a work-around on the test side. I don't want to be unable to complete the rest of the testing due to this issue causing all tests to fail. I also don't want the issue to go unacknowledged. – TrickiDicki Apr 01 '19 at 03:03
  • Can you skip that particular test in hooks? – Honza Javorek Apr 01 '19 at 16:40
  • No, it's a connectivity issue that impacts all tests. I can 'fix' it with a hook but would like to issue a warning. – TrickiDicki Apr 02 '19 at 23:42