Skip to content

Commit 3d220dd

Browse files
committed
Add command to update test case snapshots
1 parent b6fe5b3 commit 3d220dd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

bin/update-test-case-snapshots.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Updates snapshots used for testing Optimization Detective
3+
# Move actual.html files on top of an expected.html file in directories that also contain buffer.html files.
4+
5+
set -e
6+
7+
cd "$(git rev-parse --show-toplevel)"
8+
9+
count=0
10+
11+
while IFS= read -r -d '' actual_file; do
12+
dir_path=$(dirname "$actual_file")
13+
buffer_file="$dir_path/buffer.html"
14+
if [ ! -e "$buffer_file" ]; then
15+
continue
16+
fi
17+
expected_file="$dir_path/expected.html"
18+
19+
count=$((count + 1))
20+
21+
mv "$actual_file" "$expected_file"
22+
echo "Updated $expected_file"
23+
done < <(find plugins -name 'actual.html' -path '*/test-cases/*' -print0)
24+
25+
echo "Performed $count snapshot update(s)"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"test-php-multisite:view-transitions": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:view-transitions",
8282
"test-php-multisite:web-worker-offloading": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:web-worker-offloading",
8383
"test-php-multisite:webp-uploads": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:webp-uploads",
84+
"update-test-case-snapshots": "bin/update-test-case-snapshots.sh",
8485
"wp-env": "wp-env",
8586
"prepare": "husky"
8687
}

0 commit comments

Comments
 (0)