Error while testing handler wrapper by datadog()
DanielScharfsteinGit opened this issue · 1 comments
DanielScharfsteinGit commented
Expected Behavior
Tests should pass locally and on CI when DD_LOCAL_TEST or DD_LOCAL_TESTING is set to true.
Actual Behavior
Encounter an error in every test when wrapping the handlers with datadog().
Steps to Reproduce the Problem
- Added datadog() from datadog-lambda-js to my handlers:
Example:
export const handler = datadog( middy(cancelPaymentHandler) );
- When running local or CI testing, received the error Cannot set properties of undefined (setting 'done').
- When the code is deployed to the AWS environment, it runs perfectly and custom metrics are working.
Specifications
- Node Layer Version: 96
- Extension Layer Version: 47
- Node Version: 18
Stacktrace
Error:
Cannot set properties of undefined (setting 'done')
TypeError: Cannot set properties of undefined (setting 'done')
at /*datadog-lambda-js/src/utils/handler.ts:115:17
at /*datadog-lambda-js/src/index.ts:187:21
at step (/*datadog-lambda-js/dist/index.js:44:23)
at Object.next (/*datadog-lambda-js/dist/index.js:25:53)
at /*datadog-lambda-js/dist/index.js:19:71
at new Promise (<anonymous>)
at Object.<anonymous>.__awaiter (/*datadog-lambda-js/dist/index.js:15:12)
at traceListenerOnWrap (/*datadog-lambda-js/dist/index.js:204:36)
at /*datadog-lambda-js/src/index.ts:203:58
at step (/*datadog-lambda-js/dist/index.js:44:23)
at Object.next (/*datadog-lambda-js/dist/index.js:25:53)
at fulfilled (**/*datadog-lambda-js/dist/index.js:16:58)
DanielScharfsteinGit commented
I discovered that we needed to mock the library, as outlined in this link: #431 (comment).
Implementing jest.mock in the global setup resolved the issue.