Skip to content

Commit 0193a46

Browse files
committed
Reset db.json before each json-server start in Docker
- Created start-json-server.sh script to reset db.json from backup - This ensures each test run starts with clean data - Fixes accumulating test data causing failures in CI - DELETE requests work correctly but data was persisting across runs
1 parent 7bb7e62 commit 0193a46

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ services:
7070
json_server:
7171
<<: *test-service
7272
entrypoint: []
73-
command: npm run test-server
73+
command: /bin/bash /codecept/test/scripts/start-json-server.sh
7474
ports:
7575
- '8010:8010' # Expose to host
7676
restart: always # Automatically restart the container if it fails or becomes unhealthy

test/scripts/start-json-server.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Reset db.json to its initial state before starting json-server
3+
# This ensures tests always start with clean data
4+
5+
DB_FILE="/codecept/test/data/rest/db.json"
6+
BACKUP_FILE="/codecept/test/data/rest/db.json.backup"
7+
8+
# Create backup if it doesn't exist
9+
if [ ! -f "$BACKUP_FILE" ]; then
10+
echo "Creating backup of original db.json..."
11+
cp "$DB_FILE" "$BACKUP_FILE"
12+
fi
13+
14+
# Always restore from backup before starting
15+
echo "Restoring db.json from backup..."
16+
cp "$BACKUP_FILE" "$DB_FILE"
17+
18+
# Start the server
19+
echo "Starting json-server..."
20+
exec npm run test-server

0 commit comments

Comments
 (0)