cloudflare/vinext

Public

mirrored from https://github.com/cloudflare/vinextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.0.9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/smoke-test.sh

149lines · modecode

1#!/usr/bin/env bash
2set -euo pipefail
3
4# Smoke test deployed examples.
5#
6# Usage:
7# ./scripts/smoke-test.sh # test production URLs
8# ./scripts/smoke-test.sh --preview pr-42 # test PR preview URLs
9#
10# Checks every deployed example returns HTTP 200 with HTML content.
11# Exits non-zero if any check fails.
12
13DOMAIN="vinext.workers.dev"
14PREVIEW_ALIAS=""
15
16while [[ $# -gt 0 ]]; do
17 case "$1" in
18 --preview)
19 if [[ -z "${2:-}" ]]; then
20 echo "Error: --preview requires an argument (e.g. --preview pr-42)" >&2
21 exit 1
22 fi
23 PREVIEW_ALIAS="$2"
24 shift 2
25 ;;
26 *)
27 echo "Unknown option: $1" >&2
28 exit 1
29 ;;
30 esac
31done
32
33# Each entry: worker-name path expected-text
34# expected-text is a simple string that must appear in the response body.
35CHECKS=(
36 "app-router-cloudflare / vinext"
37 "pages-router-cloudflare / vinext"
38 "app-router-playground / Playground"
39 "realworld-api-rest / vinext"
40 "nextra-docs-template / Introduction"
41 "nextra-docs-template /about About"
42 "benchmarks / Benchmark"
43 "hackernews / Hacker News"
44)
45
46# Content-correctness checks for dynamic routes.
47# Verify that pages with dynamic params render the RIGHT data — not
48# stale/cached data from a different param value.
49# Format: "worker-name path must-contain must-not-contain"
50# Both strings are matched case-insensitively against the response body.
51CONTENT_CHECKS=(
52 # Nested layouts: each section must show its own products
53 'app-router-playground /layouts/electronics alt="Phone" alt="Basketball"'
54 'app-router-playground /layouts/sports alt="Basketball" alt="Phone"'
55 'app-router-playground /layouts/clothing alt="Top" alt="Phone"'
56 # Route groups: subcategory pages must show the correct items
57 'app-router-playground /route-groups/clothing/shoes alt="Shoes" alt="Shorts"'
58)
59
60tmpfile=$(mktemp)
61trap "rm -f '$tmpfile'" EXIT
62
63passed=0
64failed=0
65errors=()
66
67for check in "${CHECKS[@]}"; do
68 read -r worker path expected <<< "$check"
69
70 if [[ -n "$PREVIEW_ALIAS" ]]; then
71 url="https://${PREVIEW_ALIAS}-${worker}.${DOMAIN}${path}"
72 else
73 url="https://${worker}.${DOMAIN}${path}"
74 fi
75
76 # Fetch with a 10s timeout, follow redirects
77 status=$(curl -s -o "$tmpfile" -w "%{http_code}" -L --max-time 10 "$url" 2>/dev/null || echo "000")
78 body=$(cat "$tmpfile" 2>/dev/null || echo "")
79
80 if [[ "$status" != "200" ]]; then
81 echo "FAIL ${worker}${path} (HTTP ${status})"
82 errors+=("${worker}${path} returned HTTP ${status}")
83 failed=$((failed + 1))
84 continue
85 fi
86
87 if [[ -n "$expected" ]] && ! echo "$body" | grep -qiF "$expected"; then
88 echo "FAIL ${worker}${path} (missing '${expected}' in body)"
89 errors+=("${worker}${path} missing expected text '${expected}'")
90 failed=$((failed + 1))
91 continue
92 fi
93
94 echo " OK ${worker}${path}"
95 passed=$((passed + 1))
96done
97
98# ---------------------------------------------------------------------------
99# Content-correctness checks: right data for the right dynamic route
100# ---------------------------------------------------------------------------
101
102for check in "${CONTENT_CHECKS[@]}"; do
103 read -r worker path must_contain must_not_contain <<< "$check"
104
105 if [[ -n "$PREVIEW_ALIAS" ]]; then
106 url="https://${PREVIEW_ALIAS}-${worker}.${DOMAIN}${path}"
107 else
108 url="https://${worker}.${DOMAIN}${path}"
109 fi
110
111 status=$(curl -s -o "$tmpfile" -w "%{http_code}" -L --max-time 10 "$url" 2>/dev/null || echo "000")
112 body=$(cat "$tmpfile" 2>/dev/null || echo "")
113
114 if [[ "$status" != "200" ]]; then
115 echo "FAIL ${worker}${path} (HTTP ${status})"
116 errors+=("${worker}${path} returned HTTP ${status}")
117 failed=$((failed + 1))
118 continue
119 fi
120
121 if ! echo "$body" | grep -qiF "$must_contain"; then
122 echo "FAIL ${worker}${path} (missing '${must_contain}')"
123 errors+=("${worker}${path} missing '${must_contain}' — wrong content rendered")
124 failed=$((failed + 1))
125 continue
126 fi
127
128 if echo "$body" | grep -qiF "$must_not_contain"; then
129 echo "FAIL ${worker}${path} (found '${must_not_contain}' — wrong section data)"
130 errors+=("${worker}${path} contains '${must_not_contain}' — data from wrong dynamic param")
131 failed=$((failed + 1))
132 continue
133 fi
134
135 echo " OK ${worker}${path} (content correct)"
136 passed=$((passed + 1))
137done
138
139echo ""
140echo "${passed} passed, ${failed} failed"
141
142if [[ $failed -gt 0 ]]; then
143 echo ""
144 echo "Failures:"
145 for err in "${errors[@]}"; do
146 echo " - $err"
147 done
148 exit 1
149fi
150