testjavascript / nodejs-integration-tests-best-practices

✅ Beyond the basics of Node.js testing. Including a super-comprehensive best practices list and an example app (March 2024)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test error handling recipe

goldbergyoni opened this issue · comments

I'm working on the error handing tests recipe, what do you think that this should cover? My thoughts below

We assume that the app has its own CustomError which can tell whether the error is catastrophic (process should exit) and a dedicated ErrorHandler object

Core Flows

  • When a typical non-catastrophic error is being thrown inside API request, then it gets logged and metric is fired
  • When a typical catastrophic error is being thrown inside API request, then log+metric and the process exits
  • When a typical non-catastrophic error is being thrown on startup, then it's logged and metric is fired
  • When invalid request arrives (400), then it's logged and metric is fired

Different Error objects

  • When CustomError is being thrown, then it is being handled (log+metric)
  • When JS Error object is being thrown, then it is being handled (log+metric)
  • When string is being thrown, then it is being handled (log+metric)
  • When null is being thrown, then it is being handled (log+metric)

Different throwing code location

  • When error is thrown during API request, then it is being handled (log+metric)
  • When error is thrown during message queue processing, then it is being handled (log+metric)
  • When error is thrown on warmup, then it is being handled (log+metric)
  • When error is thrown by middleware, then it is being handled (log+metric)
  • When error is thrown by domain service, then it is being handled (log+metric)
  • When error is thrown by async timer, then it is being handled (log+metric)
  • When error is thrown by global event emitter (e.g. DB connection), then it is being handled (log+metric)
  • When error is uncaught exception, then it is being handled (log+metric)
  • When error is unhandled rejection, then it is being handled (log+metric)