How do I run an application, and run tests against it?

I am running an application using
npm start

I then want to run tests against it, but I need to pass in an address of the running application.

Does the network IP stay consistent? - From the looks of it, it does not by default, so I can’t use something like: http://172.17.0.2:port

I am unable to use localhost for this.

Any ideas?

Any help on this will be much appreciated!

Hi @cciuser! Welcome to the community. Can you clarify where you are setting the address? Thanks!

Hi there, thank you for your response! I am not setting the address. It is the address that the application is running on as a result of npm run

Okay, I think I understand.

Does it not work locally or are you unable to use localhost for another reason?

A sample from your CircleCI config might help give us more details about what’s going on.

The tests run within a docker container, so I cannot use localhost.
Locally, on my machine, I would use the network address, rather than localhost.

  - run:
      name: Run application
      command: |
        npm_run
        docker run -t samples/tests -t http://172.17.0.2:3000

Okay, Docker changes the approach here.

One option would be to use remote Docker. You’d need to set up an image/dockerfile that runs the app, and another attached to the same docker network that runs the tests.

If you are installing Docker in your build machine, then you can run Docker-in-Docker from there. I expect that you would be able to use Docker in that fashion - DinD works very well in CircleCI. I expect you’d just drop the -t option and use localhost (since from the perspective of your build machine, one layer down, localhost does indeed refer to your Docker API address, to control containers two layers down).

Could you prep a small example on a public GitHub/Bitbucket repo?

1 Like