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