Skip to content

Commit ce8d47e

Browse files
committed
Stabilize rewatch integration tests
Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 73e3edd commit ce8d47e

23 files changed

Lines changed: 229 additions & 96 deletions

‎rewatch/AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,5 @@ When clippy suggests refactoring that could impact performance, consider the tra
217217
## CI Gotchas
218218

219219
- **`sleep` is fragile** — Prefer polling (e.g., `wait_for_file`) over fixed sleeps. CI runners are slower than local machines.
220-
- **`exit_watcher` is async** — It only signals the watcher to stop (removes the lock file), it doesn't wait for the process to exit. Avoid triggering config-change events before exiting, as the watcher may start a concurrent rebuild.
220+
- **Wait for watcher shutdown with `exit_watcher`** — It removes the lock file and waits for the recorded watcher process to exit. Check its return status before continuing when later mutations could race with the watcher.
221221
- **`sed -i` differs across platforms** — macOS requires `sed -i '' ...`, Linux does not. Use the `replace` / `normalize_paths` helpers from `rewatch/tests/utils.sh` instead of raw `sed`.

‎rewatch/tests/clean/01-clean-single-project.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ other_project_compiled_files=$(find packages/new-namespace -type f -name '*.mjs'
4242
if [ "$other_project_compiled_files" -gt 0 ];
4343
then
4444
success "Didn't clean other project files"
45-
git restore .
45+
restore_tracked_files .
4646
else
4747
error "Expected files from new-namespace not to be cleaned"
4848
exit 1

‎rewatch/tests/clean/02-clean-dev-dependencies.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ project_compiled_files=$(find packages/pure-dev -type f -name '*.mjs' | wc -l |
3131
if [ "$project_compiled_files" -eq 0 ];
3232
then
3333
success "pure-dev cleaned"
34-
git restore .
34+
restore_tracked_files .
3535
else
3636
error "Expected 0 .mjs files in pure-dev after clean, got $project_compiled_files"
3737
printf "%s\n" "$error_output"

‎rewatch/tests/clean/03-clean-node-modules.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ compiler_assets=$(find node_modules/rescript-nodejs/lib/ocaml -type f -name '*.*
3131
if [ $compiler_assets -eq 0 ];
3232
then
3333
success "compiler assets from node_modules cleaned"
34-
git restore .
34+
restore_tracked_files .
3535
else
3636
error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets"
3737
printf "%s\n" "$error_output"

‎rewatch/tests/clean/04-clean-rebuild-no-compiler-update.sh‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ else
1818
exit 1
1919
fi
2020

21-
# Rebuild with snapshot output
22-
snapshot_file=../tests/snapshots/clean-rebuild.txt
23-
rewatch build &> $snapshot_file
21+
# Rebuild with captured output. This test checks one lifecycle message; writing
22+
# into a tracked snapshot made the fixture dirty whenever work counts changed.
23+
output_file=$(mktemp "${TMPDIR:-/tmp}/rewatch-clean-rebuild.XXXXXX")
24+
trap 'rm -f "$output_file"' EXIT
25+
rewatch build &> "$output_file"
2426
build_status=$?
25-
normalize_paths $snapshot_file
2627
if [ $build_status -eq 0 ];
2728
then
2829
success "Repo Built"
2930
else
3031
error "Error Building Repo"
31-
cat $snapshot_file >&2
32+
cat "$output_file" >&2
3233
exit 1
3334
fi
3435

3536
# Verify the undesired message is NOT present
36-
if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then
37+
if grep -q "Cleaned previous build due to compiler update" "$output_file"; then
3738
error "Unexpected compiler-update clean message present in rebuild logs"
38-
cat $snapshot_file >&2
39+
cat "$output_file" >&2
3940
exit 1
4041
else
4142
success "No compiler-update clean message present after explicit clean"

‎rewatch/tests/compile/08-remove-file.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rewatch build &> /dev/null
1111
rm packages/dep02/src/Dep02.res
1212
rewatch build &> ../tests/snapshots/remove-file.txt
1313
normalize_paths ../tests/snapshots/remove-file.txt
14-
git checkout -- packages/dep02/src/Dep02.res
14+
restore_tracked_files packages/dep02/src/Dep02.res
1515

1616
rewatch build &> /dev/null
1717

‎rewatch/tests/compile/09-dependency-cycle.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rewatch build &> /dev/null
1111
echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res
1212
rewatch build &> ../tests/snapshots/dependency-cycle.txt
1313
normalize_paths ../tests/snapshots/dependency-cycle.txt
14-
git checkout -- packages/new-namespace/src/NS_alias.res
14+
restore_tracked_files packages/new-namespace/src/NS_alias.res
1515

1616
rewatch build &> /dev/null
1717

‎rewatch/tests/compile/11-dev-dependency-non-dev-source.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rewatch build &> /dev/null
1313
echo 'open WebAPI' >> packages/with-dev-deps/src/FileToTest.res
1414
rewatch build &> ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt
1515
normalize_paths ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt
16-
git checkout -- packages/with-dev-deps/src/FileToTest.res
16+
restore_tracked_files packages/with-dev-deps/src/FileToTest.res
1717

1818
rewatch build &> /dev/null
1919

‎rewatch/tests/compile/13-no-infinite-loop-with-cycle.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bold "Test: It should not loop when clean building with a cycle"
77

88
rewatch clean &> /dev/null
99
echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res
10-
git checkout -- packages/new-namespace/src/NS_alias.res
10+
restore_tracked_files packages/new-namespace/src/NS_alias.res
1111
rewatch build &> /dev/null
1212

1313
success "No infinite loop detected"

‎rewatch/tests/compile/17-prod-flag.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ then
1717
success "Build without --prod correctly failed with nonexistent dev-dependency"
1818
else
1919
error "Build without --prod should have failed with nonexistent dev-dependency"
20-
git checkout -- rescript.json
20+
restore_tracked_files rescript.json
2121
exit 1
2222
fi
2323

@@ -27,12 +27,12 @@ then
2727
success "Build with --prod succeeded despite nonexistent dev-dependency"
2828
else
2929
error "Build with --prod should have succeeded by skipping dev-dependencies"
30-
git checkout -- rescript.json
30+
restore_tracked_files rescript.json
3131
exit 1
3232
fi
3333

3434
rewatch clean &> /dev/null
35-
git checkout -- rescript.json
35+
restore_tracked_files rescript.json
3636

3737
# Test 2: --prod should skip dev source files
3838
rewatch clean &> /dev/null

0 commit comments

Comments
 (0)