jest-dynamodb not running on Gitlab CI with error connect ECONNREFUSED ::1:8000

26 Views Asked by At

I want to implement tests using jest-dynamodb. It works locally on my machine. However when I want to run the tests on Gitlab CI as part of our CI/CD pipeline, it doesn't work. This error message appears:

Error: connect ECONNREFUSED ::1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)

I double and tripple checked networking, ports and everything else.

1

There are 1 best solutions below

0
sebbulon On

Please check which Linux distribution you are using in your image for your Gitlab CI Job. Because jest-dynamodb comes with DynamoDb-Local, it requires a Java runtime, and you likely have installed OpenJDK. If you are using Alpine Linux, it will run the JVM with a c-compiler called musl. But Dynamodb-Local requires glibc. Therefore it will simply not start up on the Alpine image.

The fastest way to fix this is to run your tests with a different image based on a different Linux distribution, for example Debian. Debian OpenJDK will include glibc and DynamoDB-Local will run.

Alternative: Use jest-dynalite (https://github.com/freshollie/jest-dynalite)- this comes without the Java dependency using Dynalite as DynamoDB, with a similar API.