-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e.sh
More file actions
125 lines (107 loc) · 6.57 KB
/
test-e2e.sh
File metadata and controls
125 lines (107 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
#
# xweb CLI End-to-End Test Script — core functionality
#
# Prerequisites:
# - xweb installed: npm run build && npm link
# - Internet access required (search and fetch make real HTTP requests)
# - Optional: configure a search API key for better search quality:
# ~/.config/xweb/default.json (brave/tavily/serper api_key)
# Without API key, search falls back to built-in simple provider (no key needed).
#
# Usage: bash test-e2e.sh
#
set -uo pipefail
source "$(dirname "$0")/scripts/e2e-lib.sh"
XWEB="xweb"
setup_e2e
# ── Pre-flight ────────────────────────────────────────────────
section "Pre-flight"
require_bin $XWEB "run npm run build"
if curl -sf --max-time 5 "https://example.com" >/dev/null 2>&1; then
pass "internet reachable"
else
fail "no internet access"; exit 1
fi
# ══════════════════════════════════════════════════════════════
# 1. search — basic
# ══════════════════════════════════════════════════════════════
section "1. search — basic"
run_cmd $XWEB search "bash scripting tutorial"
assert_exit0
assert_nonempty
# ══════════════════════════════════════════════════════════════
# 2. search --json
# ══════════════════════════════════════════════════════════════
section "2. search --json"
run_cmd $XWEB search "linux command line" --json
assert_exit0
assert_json_array
assert_contains '"url"'
# ══════════════════════════════════════════════════════════════
# 3. search --limit
# ══════════════════════════════════════════════════════════════
section "3. search --limit"
run_cmd $XWEB search "docker tutorial" --limit 2 --json
assert_exit0
assert_json_array_length_lte "$OUT" 2
# ══════════════════════════════════════════════════════════════
# 4. fetch — markdown (default)
# ══════════════════════════════════════════════════════════════
section "4. fetch — markdown"
run_cmd $XWEB fetch "https://example.com"
assert_exit0
assert_nonempty
assert_contains "^---"
# ══════════════════════════════════════════════════════════════
# 5. fetch --format json
# ══════════════════════════════════════════════════════════════
section "5. fetch --format json"
run_cmd $XWEB fetch "https://example.com" --format json
assert_exit0
assert_json_field "$OUT" "title"
assert_json_field "$OUT" "source"
assert_json_field "$OUT" "content"
# ══════════════════════════════════════════════════════════════
# 6. fetch --format text
# ══════════════════════════════════════════════════════════════
section "6. fetch --format text"
run_cmd $XWEB fetch "https://example.com" --format text
assert_exit0
assert_nonempty
# ══════════════════════════════════════════════════════════════
# 7. fetch --raw
# ══════════════════════════════════════════════════════════════
section "7. fetch --raw"
run_cmd $XWEB fetch "https://example.com" --raw
assert_exit0
assert_nonempty
assert_contains "^---"
# ══════════════════════════════════════════════════════════════
# 8. fetch --selector
# ══════════════════════════════════════════════════════════════
section "8. fetch --selector"
run_cmd $XWEB fetch "https://example.com" --selector "body"
assert_exit0
assert_nonempty
# ══════════════════════════════════════════════════════════════
# 9. explore
# ══════════════════════════════════════════════════════════════
section "9. explore"
run_cmd $XWEB explore "https://example.com"
assert_exit0
assert_nonempty
# ══════════════════════════════════════════════════════════════
# 10. explore --json
# ══════════════════════════════════════════════════════════════
section "10. explore --json"
run_cmd $XWEB explore "https://example.com" --json
assert_exit0
assert_json_array
# ══════════════════════════════════════════════════════════════
# 11. fetch — invalid URL exits non-zero
# ══════════════════════════════════════════════════════════════
section "11. fetch — invalid URL"
run_cmd $XWEB fetch "not-a-url"
assert_nonzero_exit
summary_and_exit