1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-10 12:34:22 +00:00

refactor: simplify Puppeteer cache cleanup to match browser cache pattern

- Replace 48-line custom function with one-line safe_clean call
- Remove unnecessary interactive confirmation (consistent with other browser caches)
- Simplify tests to verify Puppeteer cache is in clean_browsers output
- Net: -93 lines of code for same functionality
This commit is contained in:
Tw93
2026-01-23 09:56:14 +08:00
parent 5a8d766667
commit 1ad7d7e79b
2 changed files with 1 additions and 93 deletions

View File

@@ -110,7 +110,6 @@ EOF
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
safe_clean() { echo "$2"; }
clean_browsers
EOF
@@ -118,53 +117,9 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Safari cache"* ]]
[[ "$output" == *"Firefox cache"* ]]
}
@test "clean_puppeteer_cache cleans when cache exists in non-interactive mode" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
echo "test" > "$HOME/.cache/puppeteer/chrome-1234.zip"
safe_clean() { echo "$2"; }
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Puppeteer browser cache"* ]]
}
@test "clean_puppeteer_cache skips when cache does not exist" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
safe_clean() { echo "$2"; }
rm -rf "$HOME/.cache/puppeteer"
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ -z "${output//[[:space:]]/}" ]]
}
@test "clean_puppeteer_cache respects DRY_RUN mode" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=true bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
echo "test" > "$HOME/.cache/puppeteer/chrome-1234.zip"
note_activity() { :; }
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Puppeteer browser cache"* ]]
[[ "$output" == *"dry"* ]]
}
@test "clean_application_support_logs skips when no access" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail