bundla 0.8.0

Bundle HTML, CSS, and JS/TS: prod build with minification and hashed filenames by default, dev build with sourcemaps, composable watch and serve
Documentation
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
// The CLI always builds with serving (`-s`), so its tests need the feature
#![cfg(feature = "serve")]

use std::{
    fs,
    io::{BufRead, BufReader},
    path::Path,
    process::{ChildStdout, Command, Output, Stdio},
    thread,
    time::{Duration, Instant},
};

use tempfile::tempdir;

fn bin() -> Command {
    Command::new(env!("CARGO_BIN_EXE_bundla"))
}

fn run(args: &[&str]) -> Output {
    bin().args(args).output().unwrap()
}

#[test]
fn help_exits_zero() {
    let out = run(&["--help"]);
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("bundle src into dist"), "got: {stdout}");
}

#[test]
fn version_exits_zero() {
    let out = run(&["--version"]);
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains(env!("CARGO_PKG_VERSION")), "got: {stdout}");
}

#[test]
fn help_documents_random_port_default() {
    let out = run(&["--help"]);
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("random free port"), "got: {stdout}");
}

#[test]
fn invalid_port_rejected() {
    let out = run(&["-s", "--port", "99999"]);
    assert_eq!(out.status.code(), Some(2), "clap parse errors exit 2");
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("invalid value") || stderr.contains("error:"),
        "got: {stderr}"
    );
}

#[test]
fn help_documents_minify_targets() {
    let out = run(&["--help"]);
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("--minify <TARGETS>"), "got: {stdout}");
    assert!(stdout.contains("css, js, html"), "got: {stdout}");
}

#[test]
fn help_documents_watch_filter() {
    let out = run(&["--help"]);
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("--filter <SUFFIXES>"), "got: {stdout}");
}

#[test]
fn invalid_minify_target_rejected() {
    let out = run(&["--minify", "js,htlm"]);
    assert_eq!(out.status.code(), Some(2), "clap parse errors exit 2");
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(stderr.contains("unknown minify target"), "got: {stderr}");
    assert!(stderr.contains("css, js, html"), "got: {stderr}");
}

// `--minify css,js`: css/js keep the prod treatment (hashed, minified), the
// html is left untouched so template tags between attributes survive the
// upstream minify-html start-tag bug
#[test]
fn minify_targets_leave_html_untouched() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(src.join("styles")).unwrap();
    fs::write(
        src.join("index.html"),
        r#"<html><head><link rel="stylesheet" href="./styles/main.css" /></head><body><input {% if x %}checked{% endif %}></body></html>"#,
    )
    .unwrap();
    fs::write(src.join("styles/main.css"), "body { color: black; }\n").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let out = run(&["--minify", "css,js", "--src", &src_arg, "--dist", &dist_arg]);

    assert!(
        out.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    let css = hashed_css_name(&dist.join("styles"));
    assert!(css.starts_with("main-"), "got: {css}");

    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains("{% if x %}checked{% endif %}"), "got: {html}");
    assert!(html.contains(&css), "got: {html}");
}

// Server-only flags are rejected at parse time without --serve
#[test]
fn server_flags_require_serve() {
    for flag in [
        vec!["--open"],
        vec!["--header", "X-Engine: bundla"],
        vec!["--port", "9000"],
        vec!["--ip", "0.0.0.0"],
        vec!["--index", "home.html"],
    ] {
        let out = run(&flag);
        assert_eq!(
            out.status.code(),
            Some(2),
            "clap requires errors exit 2: {flag:?}"
        );
        let stderr = String::from_utf8_lossy(&out.stderr);
        assert!(
            stderr.contains("required arguments were not provided"),
            "got: {stderr}"
        );
        assert!(stderr.contains("--serve"), "got: {stderr}");
    }
}

// `--filter` only makes sense while watching
#[test]
fn filter_requires_watch() {
    let out = run(&["--filter", "html"]);
    assert_eq!(out.status.code(), Some(2), "clap requires errors exit 2");
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(stderr.contains("--watch"), "got: {stderr}");
}

// Invalid filter values fail at runtime, inside `webadev::watch`
#[test]
fn invalid_filter_rejected_at_runtime() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(&src).unwrap();
    fs::write(src.join("index.html"), "<html></html>").unwrap();
    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dir.path().join("out").to_string_lossy().to_string();

    let out = run(&[
        "-w", "--filter", ".html", "--src", &src_arg, "--dist", &dist_arg,
    ]);
    assert_eq!(out.status.code(), Some(1));
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(stderr.contains("failed to watch"), "got: {stderr}");
    assert!(
        stderr.contains("must not start with a dot"),
        "got: {stderr}"
    );
}

// Poll until `path` exists and contains `needle`, or give up on timeout
fn wait_contains(path: &Path, needle: &str, timeout: Duration) -> bool {
    let start = Instant::now();
    while start.elapsed() < timeout {
        if let Ok(text) = fs::read_to_string(path)
            && text.contains(needle)
        {
            return true;
        }
        thread::sleep(Duration::from_millis(100));
    }
    false
}

// Read child stdout lines until the `serving <url>` line
fn serving_url(stdout: ChildStdout) -> String {
    for line in BufReader::new(stdout).lines() {
        let line = line.unwrap();
        if let Some(url) = line.strip_prefix("serving ") {
            return url.to_string();
        }
    }
    panic!("child exited before printing its serving url");
}

// The single hashed css file under `styles`
fn hashed_css_name(styles: &Path) -> String {
    fs::read_dir(styles)
        .unwrap()
        .map(|e| e.unwrap().file_name().to_string_lossy().to_string())
        .find(|n| n.ends_with(".css"))
        .expect("a css output in styles")
}

fn fixture(dir: &Path) {
    let src = dir.join("src");
    fs::create_dir_all(src.join("styles")).unwrap();
    fs::write(
        src.join("index.html"),
        r#"<html><head><link rel="stylesheet" href="./styles/main.css" /></head><body>v1</body></html>"#,
    )
    .unwrap();
    fs::write(src.join("styles/main.css"), "body { color: black; }\n").unwrap();
}

// Bare `bundla`: prod build, hashed filenames, then exit
#[test]
fn bare_builds_prod() {
    let dir = tempdir().unwrap();
    fixture(dir.path());
    let dist = dir.path().join("out");

    let src_arg = dir.path().join("src").to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let out = run(&["--src", &src_arg, "--dist", &dist_arg]);

    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("bundled"), "got: {stdout}");

    // prod profile: hashed css, no sourcemap
    let css = hashed_css_name(&dist.join("styles"));
    assert!(css.starts_with("main-"), "got: {css}");
    assert!(!dist.join("styles/main.css.map").exists());
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains(&css), "got: {html}");
}

// `-d`: dev build, unhashed filenames with sourcemaps, then exit
#[test]
fn dev_builds_dev() {
    let dir = tempdir().unwrap();
    fixture(dir.path());
    let dist = dir.path().join("out");

    let src_arg = dir.path().join("src").to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let out = run(&["-d", "--src", &src_arg, "--dist", &dist_arg]);

    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("bundled"), "got: {stdout}");

    // dev profile: unhashed css + sourcemap
    assert_eq!(hashed_css_name(&dist.join("styles")), "main.css");
    assert!(dist.join("styles/main.css.map").is_file());
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains("./styles/main.css"), "got: {html}");
}

// `--base`: root-relative references under it are bundled and rewritten
// with the base prefix
#[test]
fn base_builds_root_relative_refs() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(src.join("styles")).unwrap();
    fs::write(
        src.join("index.html"),
        r#"<html><head><link rel="stylesheet" href="/app/styles/main.css" /></head><body>v1</body></html>"#,
    )
    .unwrap();
    fs::write(src.join("styles/main.css"), "body { color: black; }\n").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let out = run(&["--base", "/app", "--src", &src_arg, "--dist", &dist_arg]);

    assert!(out.status.success());
    let css = hashed_css_name(&dist.join("styles"));
    assert!(css.starts_with("main-"), "got: {css}");
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains(&format!("/app/styles/{css}")), "got: {html}");
}

// `--base` must start with `/`
#[test]
fn base_rejects_relative_values() {
    let out = run(&["--base", "app"]);
    assert_eq!(out.status.code(), Some(2));
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(stderr.contains("must start with `/`"), "got: {stderr}");
}

#[test]
fn base_rejects_empty_value() {
    let out = run(&["--base", ""]);
    assert_eq!(out.status.code(), Some(2));
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(stderr.contains("must not be empty"), "got: {stderr}");
}

#[test]
fn base_rejects_invalid_values() {
    for value in ["//app", "/app//x", "/app/../x", "/app/*"] {
        let out = run(&["--base", value]);
        assert_eq!(out.status.code(), Some(2), "value: {value:?}");
        let stderr = String::from_utf8_lossy(&out.stderr);
        assert!(
            stderr.contains("invalid value") || stderr.contains("error:"),
            "value: {value:?}, got: {stderr}"
        );
    }
}

// `--base /app/` is normalized to `/app` for the build and the server
#[test]
fn base_normalizes_trailing_slash() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(src.join("styles")).unwrap();
    fs::write(
        src.join("index.html"),
        r#"<html><head><link rel="stylesheet" href="/app/styles/main.css" /></head><body>v1</body></html>"#,
    )
    .unwrap();
    fs::write(src.join("styles/main.css"), "body { color: black; }\n").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let out = run(&["--base", "/app/", "--src", &src_arg, "--dist", &dist_arg]);

    assert!(out.status.success());
    let css = hashed_css_name(&dist.join("styles"));
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains(&format!("/app/styles/{css}")), "got: {html}");
}

// Headless, end to end: `-dw` builds on startup, rebuilds on change,
// and writes clean files (no reload script injection)
#[test]
fn dev_watch_rebuilds_without_injection() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(&src).unwrap();
    fs::write(src.join("index.html"), "<html><body>v1</body></html>").unwrap();
    let dist = dir.path().join("out");
    let out_html = dist.join("index.html");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args(["-dw", "--src", &src_arg, "--dist", &dist_arg])
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    assert!(
        wait_contains(&out_html, "v1", Duration::from_secs(60)),
        "initial build missing"
    );

    fs::write(src.join("index.html"), "<html><body>v2</body></html>").unwrap();
    assert!(
        wait_contains(&out_html, "v2", Duration::from_secs(60)),
        "build after change missing"
    );

    // nothing injected into the written files: no reload script
    let html = fs::read_to_string(&out_html).unwrap();
    assert!(!html.contains("EventSource"), "got: {html}");
    assert!(!html.contains("livereload"), "got: {html}");
    assert_eq!(html.matches("<script").count(), 0, "got: {html}");

    child.kill().unwrap();
    child.wait().unwrap();
}

// `-w --filter html`: a .txt edit is ignored, an .html edit rebuilds
#[test]
fn watch_filter_ignores_other_extensions() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(&src).unwrap();
    fs::write(src.join("index.html"), "<html><body>v1</body></html>").unwrap();
    fs::write(src.join("data.txt"), "v1").unwrap();
    let dist = dir.path().join("out");
    let out_html = dist.join("index.html");
    let out_txt = dist.join("data.txt");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args([
            "-dw", "--filter", "html", "--src", &src_arg, "--dist", &dist_arg,
        ])
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    assert!(
        wait_contains(&out_html, "v1", Duration::from_secs(60)),
        "initial build missing"
    );
    assert!(
        wait_contains(&out_txt, "v1", Duration::from_secs(60)),
        "initial static copy missing"
    );

    fs::write(src.join("data.txt"), "v2").unwrap();
    thread::sleep(Duration::from_millis(1000));
    assert_eq!(
        fs::read_to_string(&out_txt).unwrap(),
        "v1",
        "a filtered-out change must not build"
    );

    fs::write(src.join("index.html"), "<html><body>v2</body></html>").unwrap();
    assert!(
        wait_contains(&out_html, "v2", Duration::from_secs(60)),
        "build after change missing"
    );

    child.kill().unwrap();
    child.wait().unwrap();
}

// `-w` keeps hashing while rebuilding headless
#[test]
fn watch_hashes_on_rebuild() {
    let dir = tempdir().unwrap();
    fixture(dir.path());
    let dist = dir.path().join("out");
    let styles_dir = dist.join("styles");
    let src = dir.path().join("src");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args(["-w", "--src", &src_arg, "--dist", &dist_arg])
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    assert!(
        wait_contains(&dist.join("index.html"), "v1", Duration::from_secs(60)),
        "initial build missing"
    );
    let first_css = hashed_css_name(&styles_dir);
    assert!(first_css.starts_with("main-"), "got: {first_css}");

    // css edit: the content hash must change
    fs::write(src.join("styles/main.css"), "body { color: red; }\n").unwrap();
    let start = Instant::now();
    while start.elapsed() < Duration::from_secs(60) && hashed_css_name(&styles_dir) == first_css {
        thread::sleep(Duration::from_millis(100));
    }
    assert_ne!(
        hashed_css_name(&styles_dir),
        first_css,
        "build after css change missing"
    );

    // nothing injected into the written files: no reload script
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(!html.contains("EventSource"), "got: {html}");
    assert!(!html.contains("livereload"), "got: {html}");
    assert_eq!(html.matches("<script").count(), 0, "got: {html}");

    child.kill().unwrap();
    child.wait().unwrap();
}

// `-s`: build once, then serve the output statically
#[tokio::test]
async fn serve_builds_then_serves() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(&src).unwrap();
    fs::write(src.join("index.html"), "<html><body>v1</body></html>").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args(["-s", "--src", &src_arg, "--dist", &dist_arg])
        .stdout(Stdio::piped())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    let url = serving_url(child.stdout.take().unwrap());

    // the build ran before the server started, and the files stay clean
    let on_disk = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(on_disk.contains("v1"));
    assert!(!on_disk.contains("livereload"), "got: {on_disk}");

    let body = reqwest::get(&url).await.unwrap().text().await.unwrap();
    assert!(body.contains("v1"), "got: {body}");

    child.kill().unwrap();
    child.wait().unwrap();
}

// `-s --base /app`: the build is rewritten under the prefix, and the
// built-in server honors it (redirect + page + hashed asset)
#[tokio::test]
async fn serve_honors_base() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(src.join("styles")).unwrap();
    fs::write(
        src.join("index.html"),
        r#"<html><head><link rel="stylesheet" href="/app/styles/main.css" /></head><body>v1</body></html>"#,
    )
    .unwrap();
    fs::write(src.join("styles/main.css"), "body { color: black; }\n").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args([
            "-s", "--base", "/app", "--src", &src_arg, "--dist", &dist_arg,
        ])
        .stdout(Stdio::piped())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    let url = serving_url(child.stdout.take().unwrap());
    assert!(url.ends_with("/app"), "got: {url}");

    // the written page is clean and rewritten under the base
    let css = hashed_css_name(&dist.join("styles"));
    let html = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(html.contains(&format!("/app/styles/{css}")), "got: {html}");
    assert!(!html.contains("livereload"), "got: {html}");

    // `/app` redirects to `/app/` so relative URLs resolve under the base
    let client = reqwest::Client::builder()
        .redirect(reqwest::redirect::Policy::none())
        .build()
        .unwrap();
    let redirect = client.get(&url).send().await.unwrap();
    assert_eq!(redirect.status(), 308);
    assert_eq!(
        redirect
            .headers()
            .get("location")
            .unwrap()
            .to_str()
            .unwrap(),
        "/app/"
    );

    // the page and the hashed asset are served under the base
    let body = reqwest::get(format!("{url}/"))
        .await
        .unwrap()
        .text()
        .await
        .unwrap();
    assert!(body.contains("v1"), "got: {body}");
    assert!(body.contains(&format!("/app/styles/{css}")), "got: {body}");

    let asset = reqwest::get(format!("{url}/styles/{css}")).await.unwrap();
    assert_eq!(asset.status(), 200);
    assert!(!asset.text().await.unwrap().is_empty());

    // outside the base is not served
    let root = url.strip_suffix("/app").unwrap();
    assert_eq!(
        reqwest::get(format!("{root}/")).await.unwrap().status(),
        404
    );

    child.kill().unwrap();
    child.wait().unwrap();
}

// `-dws` end to end: watch + serve with live reload — the reload script
// is injected into HTTP responses, never written to the output files
#[tokio::test]
async fn watch_serve_reloads_on_change() {
    let dir = tempdir().unwrap();
    let src = dir.path().join("src");
    fs::create_dir_all(&src).unwrap();
    fs::write(src.join("index.html"), "<html><body>v1</body></html>").unwrap();
    let dist = dir.path().join("out");

    let src_arg = src.to_string_lossy().to_string();
    let dist_arg = dist.to_string_lossy().to_string();
    let mut child = bin()
        .args(["-dws", "--src", &src_arg, "--dist", &dist_arg])
        .stdout(Stdio::piped())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();

    let url = serving_url(child.stdout.take().unwrap());

    // the reload script is served over HTTP…
    let body = reqwest::get(&url).await.unwrap().text().await.unwrap();
    assert!(body.contains("v1"), "got: {body}");
    assert!(body.contains("livereload"), "got: {body}");

    fs::write(src.join("index.html"), "<html><body>v2</body></html>").unwrap();

    // …the change triggers a build, and the server serves the fresh page
    let reloaded = tokio::time::timeout(Duration::from_secs(10), async {
        loop {
            let body = reqwest::get(&url).await.unwrap().text().await.unwrap();
            if body.contains("v2") {
                return;
            }
            tokio::time::sleep(Duration::from_millis(50)).await;
        }
    })
    .await;
    assert!(reloaded.is_ok(), "page not rebuilt and served after change");

    // …but never into the written files
    let on_disk = fs::read_to_string(dist.join("index.html")).unwrap();
    assert!(!on_disk.contains("livereload"), "got: {on_disk}");

    child.kill().unwrap();
    child.wait().unwrap();
}