|
| 1 | +# docker-compose-jest-runner |
| 2 | + |
| 3 | +This package allows to run tests that use `docker-compose` and supports multi-stage setup. |
| 4 | + |
| 5 | +## How it works? |
| 6 | + |
| 7 | +This runner creates docker-compose services in stopped state and then starts them accordingly to the stages. It will start the new stage only when all the services on current one will be running. When all the stages are done the actual Jest tests will be run. After the tests will be completed the services will be teared down. |
| 8 | +## Setup |
| 9 | + |
| 10 | +1. Run `npm install --save-dev docker-compose-jest-runner` |
| 11 | +2. Add `dc-jest-runner.yml` to the root repo or use `DC_JEST_RUNNER_CONFIG` environment variable for path to the config file. |
| 12 | +3. Add `runner`: `docker-compose-jest-runner` to `jest.config.js` file. |
| 13 | + |
| 14 | +That's all |
| 15 | + |
| 16 | +## Configuration |
| 17 | + |
| 18 | +```yaml |
| 19 | + files: string | string[] (optional, default 'docker-compose.yaml') # docker-compose yaml files |
| 20 | + skipPull: boolean (optional, default false) # skips pulling docker images |
| 21 | + skipBuild: boolean (optional, default false) # skips building docker images |
| 22 | + timeout: number (optional, default Infinity) # maximum time in ms to wait for service on each stage |
| 23 | + interval: number (optional, default 250) # interval to check service in ms |
| 24 | + stages: |
| 25 | + - name: string |
| 26 | + services: |
| 27 | + - name: string # should be exactly as in docker-compose files |
| 28 | + timeout: number (optional, defaults to stage's value) |
| 29 | + interval: number (optional, defaults to stage's value) |
| 30 | + logs: boolean (optional, default false) # if "true" prints the container logs after tests execution |
| 31 | + check: string or object # based on `wait-on` npm package |
| 32 | + protocol: tcp | http | https | http-get | https-get |
| 33 | + port: number (optional, default 80 for http and 443 for https) |
| 34 | + path: string |
| 35 | +``` |
| 36 | +
|
| 37 | +Look [here](https://github.com/jeffbski/wait-on#usage) for more details regarding service check definition. |
| 38 | +
|
| 39 | +## Example |
| 40 | +
|
| 41 | + ```yaml |
| 42 | + files: |
| 43 | + - ./tests/docker-compose.yml |
| 44 | + timeout: 2000 |
| 45 | + interval: 100 |
| 46 | + stages: |
| 47 | + - name: Infra |
| 48 | + services: |
| 49 | + - name: mongo |
| 50 | + check: 'tcp:localhost:27017' |
| 51 | + - name: Service |
| 52 | + services: |
| 53 | + - name: api |
| 54 | + logs: true |
| 55 | + check: |
| 56 | + port: 3000 |
| 57 | + protocol: http-get |
| 58 | + path: /posts |
| 59 | + |
| 60 | + ``` |
| 61 | + |
| 62 | +## Contributing |
| 63 | + |
| 64 | +### Requirements |
| 65 | + |
| 66 | +1. [Docker](https://www.docker.com/) |
| 67 | + |
| 68 | +2. [NodeJS](https://nodejs.org/en/) |
| 69 | + |
| 70 | +### Getting started |
| 71 | + |
| 72 | +1. Clone the repo: |
| 73 | + |
| 74 | + ```sh |
| 75 | + git clone [email protected]:AleF83/docker-compose-jest-runner.git |
| 76 | + ``` |
| 77 | + |
| 78 | +2. Install `npm` packages: |
| 79 | + |
| 80 | + ```sh |
| 81 | + npm ci |
| 82 | + ``` |
| 83 | + |
| 84 | +3. Build the project: |
| 85 | + |
| 86 | + ```sh |
| 87 | + npm run build |
| 88 | + ``` |
| 89 | + |
| 90 | +4. Run tests: |
| 91 | + |
| 92 | + ```sh |
| 93 | + npm run test |
| 94 | + ``` |
0 commit comments