Skip to content

Commit 898ef84

Browse files
committed
feat(doc) database setup and test execution
Enhances documentation for contributing, specifically focusing on database setup and running tests. Clarifies the setup process for different database types (SQLite, MySQL, PostgreSQL), including environment variables and Docker commands. Also, documents the usage of shell scripts for simplified test execution for each database. Improves clarity around CI configuration, detailing how tests are run against all supported databases and the steps involved in the CI workflow. Simplifies example passwords.
1 parent a19a681 commit 898ef84

2 files changed

Lines changed: 65 additions & 11 deletions

File tree

docs/contributing/development-setup.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ nuxt-users/
7676
├── test/ # Test files
7777
├── playground/ # Test application
7878
├── docs/ # Documentation
79-
└── scripts/ # Test scripts
79+
├── scripts/ # Test scripts
80+
│ ├── test-sqlite.sh # SQLite test runner
81+
│ ├── test-mysql.sh # MySQL test runner
82+
│ └── test-postgresql.sh # PostgreSQL test runner
83+
└── .github/workflows/ # CI/CD configuration
84+
└── ci.yml # Continuous integration
8085
```
8186

8287
## Database Setup for Development
@@ -113,7 +118,7 @@ For PostgreSQL testing, you need a running PostgreSQL instance:
113118
```bash
114119
# Using Docker
115120
docker run --name postgres-test \
116-
-e POSTGRES_PASSWORD=postgres \
121+
-e POSTGRES_PASSWORD=123 \
117122
-e POSTGRES_DB=test_db \
118123
-p 5432:5432 \
119124
-d postgres:13
@@ -123,7 +128,7 @@ export DB_CONNECTOR=postgresql
123128
export DB_HOST=localhost
124129
export DB_PORT=5432
125130
export DB_USER=postgres
126-
export DB_PASSWORD=postgres
131+
export DB_PASSWORD=123
127132
export DB_NAME=test_db
128133
```
129134

docs/contributing/running-tests.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ yarn test:watch
2323

2424
## Database-Specific Tests
2525

26+
The project uses shell scripts to set up the proper environment for each database type before running tests.
27+
2628
### SQLite Tests
2729

2830
```bash
@@ -50,6 +52,12 @@ yarn test:mysql test/login.test.ts
5052
yarn test:mysql -- --grep "authentication"
5153
```
5254

55+
The MySQL test script (`scripts/test-mysql.sh`) automatically:
56+
- Sets up environment variables for MySQL
57+
- Waits for MySQL to be ready (with retry logic)
58+
- Creates the test database if it doesn't exist
59+
- Handles authentication with `MYSQL_PWD` environment variable
60+
5361
### PostgreSQL Tests
5462

5563
```bash
@@ -63,6 +71,35 @@ yarn test:postgresql test/login.test.ts
6371
yarn test:postgresql -- --grep "authentication"
6472
```
6573

74+
The PostgreSQL test script (`scripts/test-postgresql.sh`) automatically:
75+
- Sets up environment variables for PostgreSQL
76+
- Waits for PostgreSQL to be ready (with retry logic)
77+
- Creates the test database if it doesn't exist
78+
- Uses `PGPASSWORD` for authentication
79+
80+
## Test Scripts
81+
82+
The project includes shell scripts in the `scripts/` directory that handle database setup and test execution:
83+
84+
### `scripts/test-sqlite.sh`
85+
- Sets `DB_CONNECTOR=sqlite` environment variable
86+
- Runs tests against SQLite database
87+
- No additional setup required
88+
89+
### `scripts/test-mysql.sh`
90+
- Sets up MySQL environment variables
91+
- Waits for MySQL connection with retry logic (up to 10 attempts)
92+
- Creates test database if it doesn't exist
93+
- Sets `MYSQL_PWD` for authentication
94+
- Provides helpful error messages if MySQL is not accessible
95+
96+
### `scripts/test-postgresql.sh`
97+
- Sets up PostgreSQL environment variables
98+
- Waits for PostgreSQL connection with retry logic (up to 10 attempts)
99+
- Creates test database if it doesn't exist
100+
- Uses `PGPASSWORD` for authentication
101+
- Provides helpful error messages if PostgreSQL is not accessible
102+
66103
## Test Files Overview
67104

68105
| File | Description |
@@ -121,7 +158,7 @@ For PostgreSQL tests, you need a running PostgreSQL instance. The tests use thes
121158
- **Host**: `localhost`
122159
- **Port**: `5432`
123160
- **User**: `postgres`
124-
- **Password**: `postgres`
161+
- **Password**: `123`
125162
- **Database**: `test_db`
126163

127164
### Environment Variables
@@ -142,7 +179,7 @@ export DB_NAME=your-test-db
142179
```bash
143180
# Start PostgreSQL container for testing
144181
docker run --name postgres-test \
145-
-e POSTGRES_PASSWORD=postgres \
182+
-e POSTGRES_PASSWORD=123 \
146183
-e POSTGRES_DB=test_db \
147184
-p 5432:5432 \
148185
-d postgres:13
@@ -285,13 +322,25 @@ yarn lint --fix
285322

286323
## Continuous Integration
287324

288-
The project includes CI configuration that:
325+
The project includes CI configuration (`.github/workflows/ci.yml`) that:
326+
327+
1. **Runs tests against all databases**:
328+
- SQLite (no additional setup required)
329+
- MySQL (with MariaDB 10.5 service and health checks)
330+
- PostgreSQL (with PostgreSQL 13 service and health checks)
331+
332+
2. **Database setup in CI**:
333+
- Installs database clients (`mariadb-client`, `postgresql-client`)
334+
- Uses health checks to ensure databases are ready before testing
335+
- Sets up proper environment variables for each database type
336+
337+
3. **Additional checks**:
338+
- Checks TypeScript types
339+
- Runs linting
340+
- Builds the module
341+
- Builds documentation
289342

290-
1. Runs tests against SQLite, MySQL, and PostgreSQL
291-
2. Checks TypeScript types
292-
3. Runs linting
293-
4. Builds the module
294-
5. Builds documentation
343+
The CI workflow automatically handles database setup and teardown, making it easy to run tests in a clean environment.
295344

296345
## Debugging Tests
297346

0 commit comments

Comments
 (0)