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 13, 2025
1 parent f9bab43 commit a9f4980
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions .github/oxid-esales/cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ function start_services() {
httpd:latest bash -c 'echo "ServerName oxideshop.local" >> /usr/local/apache2/conf/httpd.conf && httpd-foreground'
}

function wait_for_application() {
echo "Waiting for application at http://oxideshop.local to be ready..."
for i in {1..30}; do
if curl -s http://oxideshop.local >/dev/null; then
echo "Application is ready!"
return 0
fi
echo "Waiting for application..."
sleep 5
done
echo -e "${RED}Application did not become ready within the expected time.${NC}"
exit 1
}

function setup_cypress() {
echo "Setting up Cypress container..."
docker run -d --name cypress-container \
Expand All @@ -36,49 +50,41 @@ function setup_cypress() {
-e CYPRESS_WORKDIR=/var/www \
-e CYPRESS_CONFIG=/var/www/cypress.config.js \
cypress/included:latest

if ! docker ps | grep -q cypress-container; then
echo -e "${RED}Cypress container failed to start.${NC}"
debug_container cypress-container
exit 1
fi
}

function debug_cypress_container() {
echo -e "${RED}Debugging Cypress container...${NC}"
function debug_container() {
local container_name=$1
echo -e "${RED}Debugging container: $container_name${NC}"

# Display logs of the stopped container
echo "Container logs:"
docker logs cypress-container

# Display container state and exit code
echo "Container state and exit code:"
docker inspect cypress-container --format='{{json .State}}'
}
docker logs $container_name || echo "No logs available for container $container_name."

function wait_for_application() {
echo "Waiting for application at http://oxideshop.local to be ready..."
until docker exec cypress-container curl -s http://oxideshop.local >/dev/null; do
sleep 2
done
echo "Application is ready!"
echo "Container state:"
docker inspect $container_name --format='{{json .State}}'
}


function run_cypress_tests_and_stream_logs() {
echo "Running Cypress tests and streaming logs to GitHub Actions console..."

# Run Cypress tests with detailed logging
docker exec cypress-container npx cypress run --browser chrome --headless --config-file /var/www/cypress.config.js --reporter spec 2>&1 | tee cypress-test-output.log

# Display the full log
echo -e "${RED}Cypress test logs:${NC}"
cat cypress-test-output.log
# Run Cypress tests and stream logs to GitHub Actions console
docker exec cypress-container npx cypress run --browser chrome --headless --config-file /var/www/cypress.config.js 2>&1 | tee cypress-test-output.log

# Check for success
if ! grep -q "All specs passed!" cypress-test-output.log; then
echo -e "${RED}Cypress tests failed. Check the logs above for details.${NC}"
echo -e "${RED}Cypress tests failed. Debugging details below:${NC}"
debug_container cypress-container
exit 1
fi

echo -e "${GREEN}All Cypress tests passed successfully!${NC}"
}


function cleanup() {
echo "Cleaning up..."
docker rm -f cypress-container telecash-module-apache-1 || echo "Containers already removed."
Expand All @@ -88,7 +94,7 @@ function cleanup() {
# Main script execution
create_network
start_services
setup_cypress
wait_for_application
setup_cypress
run_cypress_tests_and_stream_logs
cleanup

0 comments on commit a9f4980

Please sign in to comment.