In order to answer your questions clearly, I'm going to refer to each of your commands as follows:
- To run tests you run
npm test
- To run selenium you run
npm start selenium
- 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.