Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to setup unit test in Docker for nodejs application?

I am trying to run mocha unit test for my node application. The application is built by a docker image.

Docker image:

FROM node:6.10.0-alpine

RUN mkdir -p /app
WORKDIR /app

COPY package.json /app
RUN npm install

COPY . /app

EXPOSE 3000
CMD ["npm", "start"]

Docker compose:

version: "3"
services:
  web: #### nodejs image
    build: .
    volumes:
      - ./app/         
    ports:
      - "3000:3000"
    depends_on:
      - db
  db:
    build:  ##### postgres db image
      context: .
      dockerfile: dbDockerfile
    ports:
      - 5432:5432

The setup can be built and worked as expected. The problem is not I am sure how to run unit test commands like mocha to perform the test.

I see a module called dockunit but I am not sure if that's the only way for now. Can anyone help me out about this?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

With docker (and docker-compose), you can run arbitrary commands in a container. The Dockerfile defines the default command that is run when no other command is specified, but that doesn't mean it's the only one you can run.

In your case: npm start is run when no other command is specified. That happens when you do docker-compose up.

But, you can run any command using docker run or docker-compose run. For your tests, that might look like this: docker-compose run web mocha.

There is a slight difference in up and run, and I encourage you to read up on it: Should I use docker-compose start up or run?

Does this help you get started?

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!