|
| 1 | +# Contributing to serverless-mysql |
| 2 | + |
| 3 | +Thank you for considering contributing to serverless-mysql! This document provides guidelines and instructions for contributing to the project. |
| 4 | + |
| 5 | +## Code of Conduct |
| 6 | + |
| 7 | +Please be respectful and considerate of others when contributing to this project. We aim to foster an inclusive and welcoming community. |
| 8 | + |
| 9 | +## How to Contribute |
| 10 | + |
| 11 | +1. Fork the repository |
| 12 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 13 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 14 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 15 | +5. Open a Pull Request |
| 16 | + |
| 17 | +## Development Setup |
| 18 | + |
| 19 | +1. Clone the repository |
| 20 | +2. Install dependencies with `npm install` |
| 21 | +3. Set up MySQL for testing: |
| 22 | + - Option 1: Install MySQL locally |
| 23 | + - Option 2: Use Docker (recommended): |
| 24 | + ```bash |
| 25 | + docker compose up -d |
| 26 | + ``` |
| 27 | +4. Run unit tests with `npm run test:unit` |
| 28 | +5. Run integration tests with `npm run test:integration` (requires MySQL) |
| 29 | +6. Or run all tests with Docker handling MySQL automatically: |
| 30 | + ```bash |
| 31 | + npm run test:docker |
| 32 | + ``` |
| 33 | + |
| 34 | +## Running Tests |
| 35 | + |
| 36 | +The project includes both unit tests and integration tests to ensure everything works correctly. |
| 37 | + |
| 38 | +### Unit Tests |
| 39 | + |
| 40 | +Unit tests don't require any external dependencies and can be run with: |
| 41 | +
|
| 42 | +```bash |
| 43 | +npm run test:unit |
| 44 | +``` |
| 45 | +
|
| 46 | +### Integration Tests |
| 47 | +
|
| 48 | +Integration tests require a MySQL database. You can use the included Docker Compose file to start a MySQL instance: |
| 49 | +
|
| 50 | +```bash |
| 51 | +# Start MySQL container |
| 52 | +docker compose up -d |
| 53 | +
|
| 54 | +# Run integration tests |
| 55 | +npm run test:integration |
| 56 | +
|
| 57 | +# Stop MySQL container when done |
| 58 | +docker compose down |
| 59 | +``` |
| 60 | +
|
| 61 | +For convenience, you can use the provided script to run the integration tests with Docker: |
| 62 | +
|
| 63 | +```bash |
| 64 | +# This will start MySQL, run the tests, and stop MySQL automatically |
| 65 | +npm run test:integration:docker |
| 66 | +``` |
| 67 | +
|
| 68 | +The script includes a watchdog process that will automatically terminate tests if they run for too long (60 seconds), which helps prevent hanging test processes. |
| 69 | +
|
| 70 | +You can also configure the MySQL connection using environment variables: |
| 71 | +
|
| 72 | +```bash |
| 73 | +MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_DATABASE=serverless_mysql_test MYSQL_USER=root MYSQL_PASSWORD=password npm run test:integration |
| 74 | +``` |
| 75 | +
|
| 76 | +### Running All Tests |
| 77 | +
|
| 78 | +To run both unit and integration tests: |
| 79 | +
|
| 80 | +```bash |
| 81 | +npm test |
| 82 | +``` |
| 83 | +
|
| 84 | +**Important:** The `npm test` command requires a running MySQL instance, as it runs both unit and integration tests. If you don't have MySQL running, the tests will fail with connection errors. Use one of these approaches: |
| 85 | + |
| 86 | +1. Start MySQL manually before running tests: |
| 87 | + ```bash |
| 88 | + docker compose up -d |
| 89 | + npm test |
| 90 | + docker compose down |
| 91 | + ``` |
| 92 | + |
| 93 | +2. Use the Docker-managed test script instead, which handles MySQL automatically: |
| 94 | + ```bash |
| 95 | + npm run test:docker |
| 96 | + ``` |
| 97 | + |
| 98 | +If you want to run all tests with Docker handling the MySQL database: |
| 99 | + |
| 100 | +```bash |
| 101 | +npm run test:docker |
| 102 | +``` |
| 103 | + |
| 104 | +This will run the unit tests first, and if they pass, it will run the integration tests with Docker. |
| 105 | + |
| 106 | +### Test Coverage |
| 107 | + |
| 108 | +To run tests with coverage reporting: |
| 109 | + |
| 110 | +```bash |
| 111 | +npm run test-cov |
| 112 | +``` |
| 113 | + |
| 114 | +This will generate an HTML coverage report in the `coverage` directory. |
| 115 | + |
| 116 | +## Test Structure |
| 117 | + |
| 118 | +- Unit tests are located in `test/unit/*.spec.js` |
| 119 | +- Integration tests are located in `test/integration/*.spec.js` |
| 120 | +- Test helpers are in: |
| 121 | + - `test/unit/helpers/` - Helpers for unit tests (mocks, etc.) |
| 122 | + - `test/integration/helpers/` - Helpers for integration tests (database setup, etc.) |
| 123 | + |
| 124 | +## Integration Test Environment |
| 125 | + |
| 126 | +The integration tests use a MySQL 8.0 container with the following configuration: |
| 127 | + |
| 128 | +- Host: 127.0.0.1 |
| 129 | +- Port: 3306 |
| 130 | +- Database: serverless_mysql_test |
| 131 | +- User: root |
| 132 | +- Password: password |
| 133 | + |
| 134 | +The MySQL container is configured with: |
| 135 | +- Native password authentication |
| 136 | +- 1000 max connections |
| 137 | +- Extended wait timeout (28800 seconds) |
| 138 | + |
| 139 | +This is configured in the `docker-compose.yml` file and used by the GitHub Actions workflow for CI. |
| 140 | + |
| 141 | +## Continuous Integration |
| 142 | + |
| 143 | +The project uses GitHub Actions for continuous integration. Two workflows are configured: |
| 144 | + |
| 145 | +1. **Unit Tests** - Runs unit tests and linting on pull requests and pushes to master |
| 146 | +2. **Integration Tests** - Runs both unit and integration tests with a MySQL service container |
| 147 | + |
| 148 | +Both workflows run on Node.js versions 18, 20, and 22 to ensure compatibility across supported versions. |
| 149 | + |
| 150 | +## Pull Request Process |
| 151 | + |
| 152 | +1. Ensure your code passes all tests and linting |
| 153 | +2. Update documentation if necessary |
| 154 | +3. The PR should work in all supported Node.js versions (currently 18, 20, 22) |
| 155 | +4. Your PR will be reviewed by maintainers who may request changes |
| 156 | + |
| 157 | +## Coding Standards |
| 158 | + |
| 159 | +- Follow the existing code style |
| 160 | +- Write tests for new features |
| 161 | +- Keep the code simple and maintainable |
| 162 | +- Document public APIs |
| 163 | +- Run `npm run lint` to check your code against our ESLint rules |
| 164 | + |
| 165 | +## Connection Management |
| 166 | + |
| 167 | +When working on connection management features, be particularly careful about: |
| 168 | +- Properly closing connections to prevent leaks |
| 169 | +- Handling timeouts and error conditions |
| 170 | +- Testing with concurrent connections |
| 171 | +- Ensuring compatibility with serverless environments |
| 172 | + |
| 173 | +## License |
| 174 | + |
| 175 | +By contributing to serverless-mysql, you agree that your contributions will be licensed under the project's MIT License. |
0 commit comments