Skip to content

Commit

Permalink
TC-47 test cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Jan 8, 2025
1 parent 5a792b9 commit eaa5142
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions .github/oxid-esales/cypress.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash

function add_cypress_service() {
echo "Injecting Cypress service into docker-compose.yml..."
echo "Injecting Cypress service and custom network into docker-compose.yml..."

app_network=$(cat <<EOF
networks:
app-network:
driver: bridge
EOF
)

cypress_service=$(cat <<EOF
cypress:
Expand All @@ -11,21 +18,30 @@ function add_cypress_service() {
- ./source:/var/www
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- CYPRESS_baseUrl=http://oxideshop.local
- CYPRESS_baseUrl=http://telecash-module-apache-1
- CYPRESS_WORKDIR=\${CYPRESS_WORKDIR}
- CYPRESS_CONFIG=\${CYPRESS_CONFIG}
ports:
- "5920:5900"
depends_on:
apache:
condition: service_started
condition: service_healthy
php:
condition: service_started
condition: service_healthy
networks:
- app-network
entrypoint: [ "npx", "cypress", "run", "--config-file", "\${CYPRESS_CONFIG}" ]
EOF
)

if [ -f "docker-compose.yml" ]; then
if ! grep -q "networks:" docker-compose.yml; then
echo "$app_network" >> docker-compose.yml
echo "Custom network added to docker-compose.yml."
else
echo "Custom network already exists in docker-compose.yml."
fi

if ! grep -q "cypress:" docker-compose.yml; then
echo "$cypress_service" >> docker-compose.yml
echo "Cypress service added successfully."
Expand All @@ -38,6 +54,18 @@ EOF
fi
}

function add_network_to_services() {
echo "Injecting custom network into existing services in docker-compose.yml..."

if grep -q "services:" docker-compose.yml; then
sed -i '/services:/a \ networks:\n - app-network' docker-compose.yml
echo "Custom network injected into services."
else
echo "Error: No services section found in docker-compose.yml."
exit 1
fi
}

function run_docker_compose_up() {
if [ -z "$CYPRESS_WORKDIR" ] || [ -z "$CYPRESS_CONFIG" ]; then
echo "Error: CYPRESS_WORKDIR and CYPRESS_CONFIG must be set."
Expand All @@ -52,15 +80,27 @@ function run_docker_compose_up() {
echo "Running docker-compose up..."
echo "CYPRESS_WORKDIR=$CYPRESS_WORKDIR"
echo "CYPRESS_CONFIG=$CYPRESS_CONFIG"
docker ps

# Start Apache and PHP services
docker compose up --build -d apache php

# Wait for Apache to become healthy
echo "Waiting for Apache service to be healthy..."
while ! docker inspect --format '{{.State.Health.Status}}' telecash-module-apache-1 | grep -q "healthy"; do
echo "Waiting for apache to be healthy..."
sleep 5
done
echo "Apache is healthy."

# Test connectivity from Cypress to Apache
echo "Curl-ing Apache from Cypress container"
if ! docker exec -it telecash-module-cypress-1 curl -I http://telecash-module-apache-1; then
echo "Error: Unable to reach Apache from Cypress container."
exit 1
fi

# Start Cypress
docker compose up cypress
docker exec -it telecash-module-cypress-1 curl http://oxideshop.local
docker exec -it telecash-module-cypress-1 curl http://localhost.local
docker exec -it telecash-module-cypress-1 curl http://telecash-module-apache-1
curl http://oxideshop.local
curl http://localhost.local
}

# Set environment variables
Expand All @@ -79,4 +119,5 @@ if [ ! -d "$CYPRESS_WORKDIR" ]; then
fi

add_cypress_service
add_network_to_services
run_docker_compose_up

0 comments on commit eaa5142

Please sign in to comment.