Thank you for considering contributing to serverless-mysql! This document provides guidelines and instructions for contributing to the project.
Please be respectful and considerate of others when contributing to this project. We aim to foster an inclusive and welcoming community.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Clone the repository
- Install dependencies with
npm install
- Set up MySQL for testing:
- Option 1: Install MySQL locally
- Option 2: Use Docker (recommended):
docker compose up -d
- Run unit tests with
npm run test:unit
- Run integration tests with
npm run test:integration
(requires MySQL) - Or run all tests with Docker handling MySQL automatically:
npm run test:docker
The project includes both unit tests and integration tests to ensure everything works correctly.
Unit tests don't require any external dependencies and can be run with:
npm run test:unit
Integration tests require a MySQL database. You can use the included Docker Compose file to start a MySQL instance:
# Start MySQL container
docker compose up -d
# Run integration tests
npm run test:integration
# Stop MySQL container when done
docker compose down
For convenience, you can use the provided script to run the integration tests with Docker:
# This will start MySQL, run the tests, and stop MySQL automatically
npm run test:integration:docker
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.
You can also configure the MySQL connection using environment variables:
MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_DATABASE=serverless_mysql_test MYSQL_USER=root MYSQL_PASSWORD=password npm run test:integration
To run both unit and integration tests:
npm test
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:
-
Start MySQL manually before running tests:
docker compose up -d npm test docker compose down
-
Use the Docker-managed test script instead, which handles MySQL automatically:
npm run test:docker
If you want to run all tests with Docker handling the MySQL database:
npm run test:docker
This will run the unit tests first, and if they pass, it will run the integration tests with Docker.
To run tests with coverage reporting:
npm run test-cov
This will generate an HTML coverage report in the coverage
directory.
- Unit tests are located in
test/unit/*.spec.js
- Integration tests are located in
test/integration/*.spec.js
- Test helpers are in:
test/unit/helpers/
- Helpers for unit tests (mocks, etc.)test/integration/helpers/
- Helpers for integration tests (database setup, etc.)
The integration tests support multiple MySQL versions in the CI environment to ensure compatibility across different database environments. The GitHub Actions workflow is configured to test against:
- MySQL 5 (latest in the 5.x series)
- MySQL LTS (Long Term Support version)
For local development, the docker-compose.yml
file includes a single MySQL service using the mysql:lts
image to ensure we always test against the most recent Long Term Support version. The connection details are:
- Host: 127.0.0.1
- Port: 3306
- Database: serverless_mysql_test
- User: root
- Password: password
# Start MySQL container
docker compose up -d
# Run integration tests
npm run test:integration
# Stop MySQL container when done
docker compose down
The MySQL container is configured with:
- 1000 max connections
- Extended wait timeout (28800 seconds)
The GitHub Actions workflow runs integration tests against both MySQL versions to ensure compatibility.
The project uses GitHub Actions for continuous integration. Two workflows are configured:
- Unit Tests - Runs unit tests and linting on pull requests and pushes to master
- Integration Tests - Runs both unit and integration tests with a MySQL service container
Both workflows run on Node.js versions 18, 20, and 22 to ensure compatibility across supported versions.
- Ensure your code passes all tests and linting
- Update documentation if necessary
- The PR should work in all supported Node.js versions (currently 18, 20, 22)
- Your PR will be reviewed by maintainers who may request changes
- Follow the existing code style
- Write tests for new features
- Keep the code simple and maintainable
- Document public APIs
- Run
npm run lint
to check your code against our ESLint rules
When working on connection management features, be particularly careful about:
- Properly closing connections to prevent leaks
- Handling timeouts and error conditions
- Testing with concurrent connections
- Ensuring compatibility with serverless environments
By contributing to serverless-mysql, you agree that your contributions will be licensed under the project's MIT License.