Skip to content

Commit 2bd70af

Browse files
authored
Split rewatch tests (#8208)
1 parent 3f0b49a commit 2bd70af

44 files changed

Lines changed: 918 additions & 610 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rewatch/tests/clean.sh

Lines changed: 0 additions & 157 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
cd $(dirname $0)
3+
source "../utils.sh"
4+
cd ../../testrepo
5+
6+
bold "Test: It should clean a single project"
7+
8+
# First we build the entire monorepo
9+
error_output=$(rewatch build 2>&1)
10+
if [ $? -eq 0 ];
11+
then
12+
success "Built monorepo"
13+
else
14+
error "Error building monorepo"
15+
printf "%s\n" "$error_output" >&2
16+
exit 1
17+
fi
18+
19+
# Then we clean a single project
20+
error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" clean 2>&1)
21+
clean_status=$?
22+
if [ $clean_status -ne 0 ];
23+
then
24+
error "Error cleaning current project file-casing"
25+
printf "%s\n" "$error_output" >&2
26+
exit 1
27+
fi
28+
29+
# Count compiled files in the cleaned project
30+
project_compiled_files=$(find packages/file-casing -type f -name '*.mjs' | wc -l | tr -d '[:space:]')
31+
if [ "$project_compiled_files" -eq 0 ];
32+
then
33+
success "file-casing cleaned"
34+
else
35+
error "Expected 0 .mjs files in file-casing after clean, got $project_compiled_files"
36+
printf "%s\n" "$error_output"
37+
exit 1
38+
fi
39+
40+
# Ensure other project files were not cleaned
41+
other_project_compiled_files=$(find packages/new-namespace -type f -name '*.mjs' | wc -l | tr -d '[:space:]')
42+
if [ "$other_project_compiled_files" -gt 0 ];
43+
then
44+
success "Didn't clean other project files"
45+
git restore .
46+
else
47+
error "Expected files from new-namespace not to be cleaned"
48+
exit 1
49+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
cd $(dirname $0)
3+
source "../utils.sh"
4+
cd ../../testrepo
5+
6+
bold "Test: Should clean dev-dependencies of monorepo"
7+
8+
# First we build the entire monorepo
9+
error_output=$(rewatch build 2>&1)
10+
if [ $? -eq 0 ];
11+
then
12+
success "Built monorepo"
13+
else
14+
error "Error building monorepo"
15+
printf "%s\n" "$error_output" >&2
16+
exit 1
17+
fi
18+
19+
# Clean entire monorepo
20+
error_output=$(rewatch clean 2>&1)
21+
clean_status=$?
22+
if [ $clean_status -ne 0 ];
23+
then
24+
error "Error cleaning monorepo"
25+
printf "%s\n" "$error_output" >&2
26+
exit 1
27+
fi
28+
29+
# Count compiled files in dev-dependency project "pure-dev"
30+
project_compiled_files=$(find packages/pure-dev -type f -name '*.mjs' | wc -l | tr -d '[:space:]')
31+
if [ "$project_compiled_files" -eq 0 ];
32+
then
33+
success "pure-dev cleaned"
34+
git restore .
35+
else
36+
error "Expected 0 .mjs files in pure-dev after clean, got $project_compiled_files"
37+
printf "%s\n" "$error_output"
38+
exit 1
39+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
cd $(dirname $0)
3+
source "../utils.sh"
4+
cd ../../testrepo
5+
6+
bold "Test: It should clean dependencies from node_modules"
7+
8+
# Build a package with external dependencies
9+
error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" build 2>&1)
10+
if [ $? -eq 0 ];
11+
then
12+
success "Built with-dev-deps"
13+
else
14+
error "Error building with-dev-deps"
15+
printf "%s\n" "$error_output" >&2
16+
exit 1
17+
fi
18+
19+
# Then we clean a single project
20+
error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" clean 2>&1)
21+
clean_status=$?
22+
if [ $clean_status -ne 0 ];
23+
then
24+
error "Error cleaning with-dev-deps"
25+
printf "%s\n" "$error_output" >&2
26+
exit 1
27+
fi
28+
29+
# Count compiled files in the cleaned project
30+
compiler_assets=$(find node_modules/rescript-nodejs/lib/ocaml -type f -name '*.*' | wc -l | tr -d '[:space:]')
31+
if [ $compiler_assets -eq 0 ];
32+
then
33+
success "compiler assets from node_modules cleaned"
34+
git restore .
35+
else
36+
error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets"
37+
printf "%s\n" "$error_output"
38+
exit 1
39+
fi
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
cd $(dirname $0)
3+
source "../utils.sh"
4+
cd ../../testrepo
5+
6+
# If we clean a package, we should not see a "Cleaned previous build due to compiler update" message.
7+
# Clean the whole repo and rebuild, then ensure the compiler-update clean message is absent
8+
bold "Test: Clean repo then rebuild should not log compiler update clean"
9+
10+
# Clean repo
11+
error_output=$(rewatch clean 2>&1)
12+
if [ $? -eq 0 ];
13+
then
14+
success "Repo Cleaned"
15+
else
16+
error "Error Cleaning Repo"
17+
printf "%s\n" "$error_output" >&2
18+
exit 1
19+
fi
20+
21+
# Rebuild with snapshot output
22+
snapshot_file=../tests/snapshots/clean-rebuild.txt
23+
rewatch build &> $snapshot_file
24+
build_status=$?
25+
normalize_paths $snapshot_file
26+
if [ $build_status -eq 0 ];
27+
then
28+
success "Repo Built"
29+
else
30+
error "Error Building Repo"
31+
cat $snapshot_file >&2
32+
exit 1
33+
fi
34+
35+
# Verify the undesired message is NOT present
36+
if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then
37+
error "Unexpected compiler-update clean message present in rebuild logs"
38+
cat $snapshot_file >&2
39+
exit 1
40+
else
41+
success "No compiler-update clean message present after explicit clean"
42+
fi

0 commit comments

Comments
 (0)