Skip to content

Commit

Permalink
test: improve e2e tests to detect success from scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ahochsteger committed Dec 26, 2024
1 parent 7a58487 commit 5187774
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"e2e": "npm run e2e:init-run-all",
"e2e:login": "scripts/clasp.sh examples login",
"e2e:logs": "scripts/clasp.sh examples logs",
"e2e:run": "scripts/clasp.sh examples run-with-logs",
"e2e:init-all": "scripts/clasp.sh examples run-with-logs initAllTests 120",
"e2e:init-run-all": "scripts/clasp.sh examples run-with-logs initAndRunAllTests 120",
"e2e:run-all": "scripts/clasp.sh examples run-with-logs runAllTests 120",
"e2e:run": "scripts/clasp.sh examples run",
"e2e:init-all": "scripts/clasp.sh examples run initAllTests",
"e2e:init-run-all": "scripts/clasp.sh examples run-test initAndRunAllTests",
"e2e:run-all": "scripts/clasp.sh examples run-test runAllTests",
"inspect:eslint-config": "npx eslint --inspect-config",
"lint": "npx concurrently 'npm:lint:*(!lint:fix)'",
"lint:code": "scripts/lint-code.sh",
Expand Down
34 changes: 30 additions & 4 deletions scripts/clasp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ function checkGuardedAction() {
local guardedEnv="main"
# Check if running on a valid environment
if [[ "${GITHUB_ACTIONS:-}" != "true" ]] && [[ "${DEPLOYMENT_ENV:-}" == "${guardedEnv}" ]]; then
echo "ATTENTION: You're going to perform the guarded action '${action}' on the environment '${guardedEnv}'!"
read -r -p "Press CTRL+C to exit or ENTER to continue: "
else
echo "NOTE: Allowing guarded action '${action}' on the environment '${guardedEnv}'."
echo "ATTENTION: You're going to perform the guarded action '${action}' on the environment '${guardedEnv}'!" 1>&2
read -r -p "Press CTRL+C to exit or ENTER to continue: " 1>&2
fi
}

Expand Down Expand Up @@ -267,6 +265,34 @@ case "${cmd}" in
sleep "${CLASP_LOG_WAIT_SECONDS}"
runClasp logs "${functionName}" "${logTimeSeconds}"
;;
run-test)
functionName="${1:?}"
checkGuardedAction "${cmd}"
checkRunAuthFile
# Create named pipes
mkfifo stdout_pipe full_pipe
# Run the command with redirections in the background
runClaspWithRunAuth run "${functionName}" > >(tee build/full.log | tee full_pipe) 2>&1 > >(tee build/stdout.log | tee stdout_pipe >&2)
# Read from the pipes
out=$(cat stdout_pipe)
full=$(cat full_pipe)
# Remove the named pipes
rm stdout_pipe full_pipe
# Evaluate test output:
status=$(
echo "${out}" \
| grep -E -v '^Running in dev mode.$' \
| gojq -r .status \
|| echo "failure"
)
if [[ "${status}" != "success" ]]; then
echo "Error running tests (status: ${status}):"
echo "${full}"
exit 1
else
echo "Status: ${status}"
fi
;;
push)
checkGuardedAction "${cmd}"
runClasp push --force
Expand Down

0 comments on commit 5187774

Please sign in to comment.