Docker Compose Testing Node

How do I run tests within Docker containers?

To goal is to use “npm test” in a node.js API application within a Docker container

The key is to execute this command within the container itself:

  • Change the directory to the docker compose yml file and execute “docker-compose up”
  • Open another console and execute: “docker exec -ti api-server sh”
  • If you define in the docker compose file a specific location for the “volumes”, change directory to that directory
  • Then execute “npm test”

Happy testing!!

Leave a comment

Your email address will not be published. Required fields are marked *