postgresdk 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -28
- package/dist/cli.js +44 -11
- package/dist/index.js +44 -11
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1005,38 +1005,30 @@ When tests are enabled, postgresdk generates:
|
|
1005
1005
|
|
1006
1006
|
### Running Tests with Docker
|
1007
1007
|
|
1008
|
-
The generated
|
1008
|
+
The generated test setup includes a Docker Compose file and a test runner script:
|
1009
1009
|
|
1010
1010
|
```bash
|
1011
|
-
#
|
1012
|
-
|
1013
|
-
|
1014
|
-
#
|
1015
|
-
|
1016
|
-
|
1017
|
-
#
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
#
|
1025
|
-
#
|
1026
|
-
|
1027
|
-
#
|
1028
|
-
npm run dev &
|
1029
|
-
|
1030
|
-
# Run tests
|
1031
|
-
npm test
|
1032
|
-
|
1033
|
-
# Stop database when done
|
1034
|
-
docker-compose down
|
1035
|
-
|
1036
|
-
# Or use the generated script
|
1037
|
-
bash run-tests.sh
|
1011
|
+
# 1. Make the test script executable (first time only)
|
1012
|
+
chmod +x api/tests/run-tests.sh
|
1013
|
+
|
1014
|
+
# 2. Edit api/tests/run-tests.sh to configure:
|
1015
|
+
# - Your API server startup command
|
1016
|
+
# - Migration commands (if needed)
|
1017
|
+
# - Any other setup specific to your project
|
1018
|
+
|
1019
|
+
# 3. Run the tests
|
1020
|
+
./api/tests/run-tests.sh
|
1021
|
+
|
1022
|
+
# The script will:
|
1023
|
+
# - Start a PostgreSQL 17 test database in Docker
|
1024
|
+
# - Wait for it to be ready
|
1025
|
+
# - Run your API server (once configured)
|
1026
|
+
# - Execute the test suite
|
1027
|
+
# - Provide cleanup instructions
|
1038
1028
|
```
|
1039
1029
|
|
1030
|
+
The test script includes detailed comments and examples for common setups. You'll need to uncomment and customize the API server startup section for your specific project.
|
1031
|
+
|
1040
1032
|
### Customizing Tests
|
1041
1033
|
|
1042
1034
|
The generated tests are basic and meant as a starting point. Create your own test files for:
|
package/dist/cli.js
CHANGED
@@ -2428,7 +2428,7 @@ version: '3.8'
|
|
2428
2428
|
|
2429
2429
|
services:
|
2430
2430
|
postgres:
|
2431
|
-
image: postgres:
|
2431
|
+
image: postgres:17-alpine
|
2432
2432
|
environment:
|
2433
2433
|
POSTGRES_USER: testuser
|
2434
2434
|
POSTGRES_PASSWORD: testpass
|
@@ -2452,11 +2452,23 @@ function emitTestScript(framework = "vitest") {
|
|
2452
2452
|
return `#!/bin/bash
|
2453
2453
|
# Test Runner Script
|
2454
2454
|
#
|
2455
|
-
# This script sets up and runs tests with a Docker PostgreSQL database
|
2455
|
+
# This script sets up and runs tests with a Docker PostgreSQL database.
|
2456
|
+
#
|
2457
|
+
# Usage:
|
2458
|
+
# chmod +x run-tests.sh # Make executable (first time only)
|
2459
|
+
# ./run-tests.sh
|
2460
|
+
#
|
2461
|
+
# Prerequisites:
|
2462
|
+
# - Docker installed and running
|
2463
|
+
# - Your API server code in the parent directories
|
2464
|
+
# - Test framework installed (${framework})
|
2456
2465
|
|
2457
2466
|
set -e
|
2458
2467
|
|
2468
|
+
SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
|
2469
|
+
|
2459
2470
|
echo "\uD83D\uDC33 Starting test database..."
|
2471
|
+
cd "$SCRIPT_DIR"
|
2460
2472
|
docker-compose up -d --wait
|
2461
2473
|
|
2462
2474
|
# Export test database URL
|
@@ -2465,24 +2477,43 @@ export TEST_API_URL="http://localhost:3000"
|
|
2465
2477
|
|
2466
2478
|
# Wait for database to be ready
|
2467
2479
|
echo "⏳ Waiting for database..."
|
2468
|
-
sleep
|
2480
|
+
sleep 3
|
2469
2481
|
|
2470
|
-
# Run migrations
|
2471
|
-
#
|
2482
|
+
# TODO: Run your migrations on the test database
|
2483
|
+
# Example:
|
2484
|
+
# echo "\uD83D\uDCCA Running migrations..."
|
2485
|
+
# npm run migrate -- --database-url="$TEST_DATABASE_URL"
|
2472
2486
|
|
2473
2487
|
echo "\uD83D\uDE80 Starting API server..."
|
2474
|
-
|
2475
|
-
|
2488
|
+
echo "⚠️ TODO: Uncomment and customize the API server startup command below:"
|
2489
|
+
echo ""
|
2490
|
+
echo " # Example for Node.js/Bun:"
|
2491
|
+
echo " # cd ../.. && npm run dev &"
|
2492
|
+
echo " # SERVER_PID=$!"
|
2493
|
+
echo ""
|
2494
|
+
echo " # Example for custom server file:"
|
2495
|
+
echo " # cd ../.. && node server.js &"
|
2496
|
+
echo " # SERVER_PID=$!"
|
2497
|
+
echo ""
|
2498
|
+
echo " Please edit this script to start your API server."
|
2499
|
+
echo ""
|
2500
|
+
# cd ../.. && npm run dev &
|
2476
2501
|
# SERVER_PID=$!
|
2477
2502
|
# sleep 3
|
2478
2503
|
|
2479
2504
|
echo "\uD83E\uDDEA Running tests..."
|
2480
|
-
${runCommand} $@
|
2505
|
+
${runCommand} "$@"
|
2481
2506
|
|
2482
2507
|
# Cleanup
|
2483
|
-
#
|
2508
|
+
# if [ ! -z "\${SERVER_PID}" ]; then
|
2509
|
+
# echo "\uD83D\uDED1 Stopping API server..."
|
2510
|
+
# kill $SERVER_PID 2>/dev/null || true
|
2511
|
+
# fi
|
2484
2512
|
|
2485
2513
|
echo "✅ Tests completed!"
|
2514
|
+
echo ""
|
2515
|
+
echo "To stop the test database, run:"
|
2516
|
+
echo " cd $SCRIPT_DIR && docker-compose down"
|
2486
2517
|
`;
|
2487
2518
|
}
|
2488
2519
|
function getFrameworkImports(framework) {
|
@@ -2806,8 +2837,10 @@ async function generate(configPath) {
|
|
2806
2837
|
if (generateTests) {
|
2807
2838
|
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2808
2839
|
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2809
|
-
console.log(` \uD83D\
|
2810
|
-
console.log(`
|
2840
|
+
console.log(` \uD83D\uDCDD Test setup:`);
|
2841
|
+
console.log(` 1. Make script executable: chmod +x ${testDir}/run-tests.sh`);
|
2842
|
+
console.log(` 2. Edit the script to configure your API server startup`);
|
2843
|
+
console.log(` 3. Run tests: ${testDir}/run-tests.sh`);
|
2811
2844
|
}
|
2812
2845
|
}
|
2813
2846
|
|
package/dist/index.js
CHANGED
@@ -2158,7 +2158,7 @@ version: '3.8'
|
|
2158
2158
|
|
2159
2159
|
services:
|
2160
2160
|
postgres:
|
2161
|
-
image: postgres:
|
2161
|
+
image: postgres:17-alpine
|
2162
2162
|
environment:
|
2163
2163
|
POSTGRES_USER: testuser
|
2164
2164
|
POSTGRES_PASSWORD: testpass
|
@@ -2182,11 +2182,23 @@ function emitTestScript(framework = "vitest") {
|
|
2182
2182
|
return `#!/bin/bash
|
2183
2183
|
# Test Runner Script
|
2184
2184
|
#
|
2185
|
-
# This script sets up and runs tests with a Docker PostgreSQL database
|
2185
|
+
# This script sets up and runs tests with a Docker PostgreSQL database.
|
2186
|
+
#
|
2187
|
+
# Usage:
|
2188
|
+
# chmod +x run-tests.sh # Make executable (first time only)
|
2189
|
+
# ./run-tests.sh
|
2190
|
+
#
|
2191
|
+
# Prerequisites:
|
2192
|
+
# - Docker installed and running
|
2193
|
+
# - Your API server code in the parent directories
|
2194
|
+
# - Test framework installed (${framework})
|
2186
2195
|
|
2187
2196
|
set -e
|
2188
2197
|
|
2198
|
+
SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
|
2199
|
+
|
2189
2200
|
echo "\uD83D\uDC33 Starting test database..."
|
2201
|
+
cd "$SCRIPT_DIR"
|
2190
2202
|
docker-compose up -d --wait
|
2191
2203
|
|
2192
2204
|
# Export test database URL
|
@@ -2195,24 +2207,43 @@ export TEST_API_URL="http://localhost:3000"
|
|
2195
2207
|
|
2196
2208
|
# Wait for database to be ready
|
2197
2209
|
echo "⏳ Waiting for database..."
|
2198
|
-
sleep
|
2210
|
+
sleep 3
|
2199
2211
|
|
2200
|
-
# Run migrations
|
2201
|
-
#
|
2212
|
+
# TODO: Run your migrations on the test database
|
2213
|
+
# Example:
|
2214
|
+
# echo "\uD83D\uDCCA Running migrations..."
|
2215
|
+
# npm run migrate -- --database-url="$TEST_DATABASE_URL"
|
2202
2216
|
|
2203
2217
|
echo "\uD83D\uDE80 Starting API server..."
|
2204
|
-
|
2205
|
-
|
2218
|
+
echo "⚠️ TODO: Uncomment and customize the API server startup command below:"
|
2219
|
+
echo ""
|
2220
|
+
echo " # Example for Node.js/Bun:"
|
2221
|
+
echo " # cd ../.. && npm run dev &"
|
2222
|
+
echo " # SERVER_PID=$!"
|
2223
|
+
echo ""
|
2224
|
+
echo " # Example for custom server file:"
|
2225
|
+
echo " # cd ../.. && node server.js &"
|
2226
|
+
echo " # SERVER_PID=$!"
|
2227
|
+
echo ""
|
2228
|
+
echo " Please edit this script to start your API server."
|
2229
|
+
echo ""
|
2230
|
+
# cd ../.. && npm run dev &
|
2206
2231
|
# SERVER_PID=$!
|
2207
2232
|
# sleep 3
|
2208
2233
|
|
2209
2234
|
echo "\uD83E\uDDEA Running tests..."
|
2210
|
-
${runCommand} $@
|
2235
|
+
${runCommand} "$@"
|
2211
2236
|
|
2212
2237
|
# Cleanup
|
2213
|
-
#
|
2238
|
+
# if [ ! -z "\${SERVER_PID}" ]; then
|
2239
|
+
# echo "\uD83D\uDED1 Stopping API server..."
|
2240
|
+
# kill $SERVER_PID 2>/dev/null || true
|
2241
|
+
# fi
|
2214
2242
|
|
2215
2243
|
echo "✅ Tests completed!"
|
2244
|
+
echo ""
|
2245
|
+
echo "To stop the test database, run:"
|
2246
|
+
echo " cd $SCRIPT_DIR && docker-compose down"
|
2216
2247
|
`;
|
2217
2248
|
}
|
2218
2249
|
function getFrameworkImports(framework) {
|
@@ -2536,8 +2567,10 @@ async function generate(configPath) {
|
|
2536
2567
|
if (generateTests) {
|
2537
2568
|
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2538
2569
|
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2539
|
-
console.log(` \uD83D\
|
2540
|
-
console.log(`
|
2570
|
+
console.log(` \uD83D\uDCDD Test setup:`);
|
2571
|
+
console.log(` 1. Make script executable: chmod +x ${testDir}/run-tests.sh`);
|
2572
|
+
console.log(` 2. Edit the script to configure your API server startup`);
|
2573
|
+
console.log(` 3. Run tests: ${testDir}/run-tests.sh`);
|
2541
2574
|
}
|
2542
2575
|
}
|
2543
2576
|
export {
|