feat: add Docker configuration for consistent test environment#2
Conversation
- Executar testes em Node.js 18.x e 20.x - Rodar consumer e provider tests - Upload dos arquivos pact como artefatos
There was a problem hiding this comment.
Pull request overview
This PR adds Docker configuration to enable consistent testing environments across different development machines. It introduces containerized test execution while maintaining compatibility with existing local development workflows.
Changes:
- Added Docker configuration with optimized Node.js 20-slim image and native build dependencies
- Created docker-compose services for running all tests, consumer-only tests, provider-only tests, and an interactive development environment
- Added comprehensive .dockerignore to exclude unnecessary files from Docker builds
- Added GitHub Actions workflow for automated contract testing on CI/CD
- Updated README with Docker usage instructions
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Dockerfile | Defines optimized container image with Node.js 20-slim, build dependencies, and test directory structure |
| docker-compose.yml | Configures four services (tests, consumer-tests, provider-tests, dev) with appropriate volume mounts and commands |
| .dockerignore | Excludes unnecessary files (node_modules, IDE configs, Docker files, documentation) from Docker builds |
| README.md | Documents Docker commands for running tests and development environment |
| .github/workflows/pact-tests.yml | Adds CI/CD workflow for automated contract testing using Node.js 20.x |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| RUN mkdir -p __tests__/contract/logs __tests__/contract/pacts | ||
|
|
||
| EXPOSE 8081 8082 8083 | ||
| CMD ["npm", "test"] |
There was a problem hiding this comment.
The CMD references "npm test" but there is no "test" script defined in package.json. The available scripts are "test:consumer" and "test:provider". Consider either adding a "test" script to package.json that runs both test commands, or update this CMD to match an existing script like "test:consumer".
| CMD ["npm", "test"] | |
| CMD ["npm", "run", "test:consumer"] |
| on: | ||
| push: | ||
| branches: [main] | ||
| branches: [main, fix/pact-contract-tests] |
There was a problem hiding this comment.
The workflow is configured to run on push to branch 'fix/pact-contract-tests', which appears to be a feature/fix branch. For a production workflow, this branch should likely be removed from the trigger list after the PR is merged, leaving only 'main'.
| branches: [main, fix/pact-contract-tests] | |
| branches: [main] |
|
|
||
| ### Docker 🐳 | ||
|
|
||
| ```ruby |
There was a problem hiding this comment.
The code block is incorrectly marked as 'ruby' when it contains bash/shell commands. Change the language identifier from 'ruby' to 'bash' or 'sh' for proper syntax highlighting.
| container_name: pact-tests | ||
| volumes: | ||
| - ./src:/app/src:ro | ||
| - ./__tests__:/app/__tests__ | ||
| command: sh -c "npm run test:consumer && npm run test:provider" | ||
|
|
||
| consumer-tests: | ||
| build: . | ||
| container_name: pact-consumer-tests | ||
| volumes: | ||
| - ./src:/app/src:ro | ||
| - ./__tests__:/app/__tests__ | ||
| command: npm run test:consumer | ||
|
|
||
| provider-tests: | ||
| build: . | ||
| container_name: pact-provider-tests | ||
| volumes: | ||
| - ./src:/app/src:ro | ||
| - ./__tests__:/app/__tests__ | ||
| command: npm run test:provider | ||
|
|
||
| dev: | ||
| build: . | ||
| container_name: pact-dev |
There was a problem hiding this comment.
Using fixed container_name with 'docker compose run' can cause conflicts if multiple instances are run concurrently. Since the README suggests using 'docker compose run --rm', which creates temporary containers, the container_name directives will prevent running multiple instances simultaneously. Consider removing container_name for all services to allow parallel execution, or document that only one instance can run at a time.
Descrição
Adiciona configuração Docker para ambiente de testes consistente e atualiza documentação.
Alterações
Dockerfile- Imagem otimizada com Node.js 20-slimdocker-compose.yml- Serviços para testes (all, consumer, provider, dev).dockerignore- Exclusão de arquivos desnecessáriosREADME.md- Documentação dos comandos DockerComandos Docker disponíveis
Testes