@@ -3,87 +3,100 @@ setup() {
33 export npm_config_yes=true
44}
55
6+ retry_run () {
7+ for attempt in 1 2 3; do
8+ run " $@ "
9+ (( status == 0 )) && return 0
10+ sleep 1
11+ done
12+ return " $status "
13+ }
14+
615@test " outputs the HTML with Star Wars products" {
716 run npx node lego.mjs
817 [[ " $output " == * " Millennium Falcon" * ]]
918}
1019
1120@test " counts the number of F1 Academy teams" {
1221 run npx --package=cheerio node f1academy_teams.mjs
13- (( status == 0 ))
14- [[ -n " $output " ]]
22+ [[ " $output " == " 6" ]]
1523}
1624
1725@test " counts the number of F1 Academy drivers" {
1826 run npx --package=cheerio node f1academy_drivers.mjs
19- (( status == 0 ))
20- [[ -n " $output " ]]
27+ [[ " $output " == " 18" ]]
2128}
2229
2330@test " lists African countries" {
2431 run npx --package=cheerio node wikipedia_countries.mjs
25- (( status == 0 ))
26- [[ -n " $output " ]]
32+ [[ " $output " == * $' Comoros \n Democratic Republic of the Congo \n ' * ]]
33+ [[ $( echo " $output " | wc -l ) -gt 5 ]]
2734}
2835
2936@test " lists African countries with a single selector" {
3037 run npx --package=cheerio node wikipedia_countries_single_selector.mjs
31- (( status == 0 ))
32- [[ -n " $output " ]]
38+ [[ " $output " == * $' Comoros \n Democratic Republic of the Congo \n ' * ]]
39+ [[ $( echo " $output " | wc -l ) -gt 5 ]]
3340}
3441
3542@test " lists Guardian F1 article titles" {
3643 run npx --package=cheerio node guardian_f1_titles.mjs
37- (( status == 0 ))
38- [[ -n " $output " ]]
44+ [[ " $output " == * ' F1 ' * ]]
45+ [[ $( echo " $output " | wc -l ) -gt 5 ]]
3946}
4047
4148@test " prints warehouse stock counts" {
4249 run npx --package=cheerio node warehouse_units.mjs
43- (( status == 0 ))
44- [[ -n " $output " ]]
50+ [[ " $output " == * $' JBL Flip 4 Waterproof Portable Bluetooth Speaker | 672\n ' * ]]
51+ [[ " $output " == * $' Sony XBR-950G BRAVIA 4K HDR Ultra HD TV | 77\n ' * ]]
52+ [[ $( echo " $output " | wc -l) -gt 5 ]]
4553}
4654
4755@test " prints warehouse stock counts using regex" {
4856 run npx --package=cheerio node warehouse_units_regex.mjs
49- (( status == 0 ))
50- [[ -n " $output " ]]
57+ [[ " $output " == * $' JBL Flip 4 Waterproof Portable Bluetooth Speaker | 672\n ' * ]]
58+ [[ " $output " == * $' Sony XBR-950G BRAVIA 4K HDR Ultra HD TV | 77\n ' * ]]
59+ [[ $( echo " $output " | wc -l) -gt 5 ]]
5160}
5261
5362@test " prints Guardian F1 titles with publish dates" {
5463 run npx --package=cheerio node guardian_publish_dates.mjs
55- (( status == 0 ))
56- [[ -n " $output " ]]
64+ [[ " $output " == * ' F1 ' * ]]
65+ [[ " $output " == * ' | Sun ' * ]] # has info about date (articles published on Sunday are very likely)
66+ [[ $( echo " $output " | wc -l) -gt 5 ]]
5767}
5868
5969@test " filters products from JSON" {
6070 run npx node process_products_json.mjs
61- (( status == 0 ))
62- [[ -n " $output " ]]
71+ [[ " $output " == " { title: 'Premium Speakers', minPrice: 75000, price: 75000 }" ]]
6372}
6473
6574@test " lists Wikipedia country links" {
6675 run npx --package=cheerio node wikipedia_country_links.mjs
67- (( status == 0 ))
68- [[ -n " $output " ]]
76+ [[ " $output " == * $' https://en.wikipedia.org/wiki/Algeria\n https://en.wikipedia.org/wiki/Angola\n ' * ]]
77+ [[ " $output " == * $' https://en.wikipedia.org/wiki/R%C3%A9union\n ' * ]]
78+ [[ $( echo " $output " | wc -l) -gt 5 ]]
6979}
7080
7181@test " lists Guardian F1 article links" {
7282 run npx --package=cheerio node guardian_f1_links.mjs
73- (( status == 0 ))
74- [[ -n " $output " ]]
83+ [[ " $output " == * ' https://www.theguardian.com/sport/ ' * ]]
84+ [[ $( echo " $output " | wc -l ) -gt 5 ]]
7585}
7686
7787@test " prints Wikipedia calling codes" {
7888 run npx --package=cheerio node wikipedia_calling_codes.mjs
79- (( status == 0 ))
80- [[ -n " $output " ]]
89+ [[ " $output " == * $' https://en.wikipedia.org/wiki/Comoros +269\n ' * ]]
90+ [[ " $output " == * $' https://en.wikipedia.org/wiki/Sahrawi_Arab_Democratic_Republic null\n ' * ]]
91+ [[ $( echo " $output " | wc -l) -gt 5 ]]
8192}
8293
8394@test " lists Guardian F1 authors" {
8495 run npx --package=cheerio node guardian_f1_authors.mjs
85- (( status == 0 ))
86- [[ -n " $output " ]]
96+ [[ " $output " == * ' F1 ' * ]]
97+ [[ " $output " == * ' Giles Richards: ' * ]] # writes most of them (we'll have to change this if they fire'him)
98+ [[ " $output " == * ' Guardian sport: ' * || " $output " == * ' PM Media: ' * ]]
99+ [[ $( echo " $output " | wc -l) -gt 5 ]]
87100}
88101
89102@test " lists npm LLM packages" {
@@ -94,18 +107,19 @@ setup() {
94107
95108@test " finds the shortest CNN sports article" {
96109 run npx --package=cheerio node cnn_sports_shortest_article.mjs
97- (( status == 0 ))
98- [[ -n " $output " ]]
110+ [[ " $output " == ' https://edition.cnn.com/' * ]]
99111}
100112
101113@test " scrapes F1 Academy driver details with Crawlee" {
102114 run npx --package=crawlee node crawlee_f1_drivers.mjs
115+ (( status == 0 ))
103116 [[ -n " $output " || -f dataset.json ]]
104117 rm -f dataset.json
105118}
106119
107120@test " scrapes Netflix ratings with Crawlee" {
108121 run npx --package=crawlee node crawlee_netflix_ratings.mjs
122+ (( status == 0 ))
109123 [[ -n " $output " || -f dataset.json ]]
110124 rm -f dataset.json
111125}
0 commit comments