0

I have an application that runs its tests with Jasmine and WebdriverIO which I would like to automate in CircleCI. I'm new to testing in general so I'm not sure what to do.

Here's what I know:

  • To run the tests, I invoke npm test
  • A selenium server is required on port 4444 (which I can start with npm start)
  • The application should be running on port 80 (which I can serve with another npm command)
  • When the tests complete, I'm returned to command line, but the other services (on p4444 and p80) are still running

Here's what I don't fully understand:

  • Locally, these require 3 terminals to run concurrently, is there a way to do this with CircleCI?
  • If so, how do I tell when the p4444 and p80 are ready to test on, or cancel them when the tests are done?
  • Is my issue with Docker, or CircleCI?
leander
  • 534
  • 1
  • 4
  • 18

1 Answers1

0

In order to answer your questions clearly, I'm going to refer to each of your commands as follows:

  1. To run tests you run npm test
  2. To run selenium you run npm start selenium
  3. To run your app you run npm start app

Questions/Answers:

Locally, these require 3 terminals to run concurrently, is there a way to do this with CircleCI?

Yes. you just need to start a process with background set to true

i.e. to start Selenium in the background you can run the following

    - run:
        name: Start Selenium in background 
        command: |
          npm start selenium
        background: true

After starting a process, but before using it, wait for the process to be ready on the given port

    - run:
        name: Waiting for Selenium server to be ready
        command: |
          for i in `seq 1 10`;
          do
            nc -z localhost 4444 && echo Success && exit 0
            echo -n .
            sleep 1
          done
          echo Failed waiting for Selenium && exit 1

Note if you replace 4444 in the above command, you can wait for a process on another port

How do I tell when the p4444 and p80 are ready to test on, or cancel them when the tests are done?

Your CircleCi commands might look like this

     - run:
        name: Start Selenium in background 
        command: |
          npm start selenium
        background: true
    - run:
        name: Start App in background 
        command: |
          npm start app
        background: true

    - run:
        name: Waiting for Selenium server to be ready
        command: |
          for i in `seq 1 10`;
          do
            nc -z localhost 4444 && echo Success && exit 0
            echo -n .
            sleep 1
          done
          echo Failed waiting for Selenium && exit 

      - run:
        name: Waiting for App server to be ready
        command: |
          for i in `seq 1 10`;
          do
            nc -z localhost 80 && echo Success && exit 0
            echo -n .
            sleep 1
          done
          echo Failed waiting for Selenium && exit 

   - run:
        name: Run Tests 
        command: |
          npm test 

You asked a separate question - How do I cancel the processes on port 4444 and 80 when the tests are done? You don't really need to. When the test job finishes the container will be disposed and the helper apps will stop.

However, if you want to stop those processes in order to run some other job steps, you can run kill commands (I can elaborate if this is unclear)

Is my issue with Docker, or CircleCI?

It looks like it's just an issue in understanding how to run a series of commands in CircleCi

If you follow the steps above you should be able to accomplish your goal.

Parzie
  • 210
  • 1
  • 12