diff --git a/azure-pipelines-automated-testing.yml b/azure-pipelines-automated-testing.yml index 3a34e8be..2bbd6868 100644 --- a/azure-pipelines-automated-testing.yml +++ b/azure-pipelines-automated-testing.yml @@ -73,7 +73,7 @@ stages: tags: $(imageTag) arguments: '--no-cache --pull' - - script: | + - bash: | branch_name=$(Build.SourceBranch) #TODO: Change back to $(System.PullRequest.SourceBranch) echo "Retrieved branch name: '$branch_name'" jira_card_number="${branch_name##*/}" @@ -89,9 +89,17 @@ stages: -e CI=true \ -e NODE_ENV=$(NODE_ENV) \ $(dockerImageName):$(imageTag) \ - npx concurrently -k -n "server,playwright"\ - "sed -i \"s|^process\.env\.VUE_APP_CONSUMER_CF_DISTRO = .*|process\.env\.VUE_APP_CONSUMER_CF_DISTRO='https://digitalapi.test.safelite.io'|\" \"./vue.config.js\" && echo \"Updated config file to use TEST APIs\" && npm run serve -- --port=8080"\ - "npx wait-on http://localhost:8080 && npm run test:playwright -- --shard=$(shardNumber)/$(totalShards) --reporter=list,blob --grep \"@$jira_card_number\"") + bash -c "num_tests=$(npx playwright test --list --grep \"@$jira_card_number\") + num_tests=${num_tests#*Total: } + num_tests=${num_tests%% test*} + if [[ $num_tests -lt $(shardNumber) ]]; then + echo 'There are fewer tests than shards. Skipping this shard.' + else + npx concurrently -k -n \"server,playwright\" + \"sed -i \\\"s|^process\.env\.VUE_APP_CONSUMER_CF_DISTRO = .*|process\.env\.VUE_APP_CONSUMER_CF_DISTRO='https://digitalapi.test.safelite.io'|\\\" \\\"./vue.config.js\\\" && echo \\\"Updated config file to use TEST APIs\\\" && npm run serve -- --port=8080\" + \"npx wait-on http://localhost:8080 && npm run test:playwright -- --shard=$(shardNumber)/$(totalShards) --reporter=list,blob --grep \\\"@$jira_card_number\\\"\" + fi + ") # Start container and stream logs echo "Starting tests for shard $(shardNumber)..." @@ -103,7 +111,11 @@ stages: # Copy test results from container echo "Copying test results..." - docker cp $container_id:/app/blob-report/. $(System.DefaultWorkingDirectory)/blob-reports/shard-$(shardNumber)/ + if docker exec "$container_id" test -e "/app/blob-report"; then + docker cp $container_id:/app/blob-report/. $(System.DefaultWorkingDirectory)/blob-reports/shard-$(shardNumber)/ + else + echo "Test results file not found." + fi # Remove container echo "Cleaning up container..."