From e89fcea02c18993150ef04539bd2fe6b70fef29f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 17 Jan 2023 08:32:05 -0800 Subject: [PATCH] fix: Make metadata tests more resilient. (#6771) * fix: Make metadata tests more resilient. * fix: improve control flow and clarify xargs purpose. --- scripts/gulpfiles/test_tasks.js | 16 +++++++++++----- tests/scripts/check_metadata.sh | 8 ++++---- tests/scripts/update_metadata.sh | 10 ++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/gulpfiles/test_tasks.js b/scripts/gulpfiles/test_tasks.js index b26e23084..f13168670 100644 --- a/scripts/gulpfiles/test_tasks.js +++ b/scripts/gulpfiles/test_tasks.js @@ -165,17 +165,23 @@ function compareSize(file, expected) { const stat = fs.statSync(name); const size = stat.size; + if (!compare) { + const message = `Failed: Previous size of ${name} is undefined.`; + console.log(`${BOLD_RED}${message}${ANSI_RESET}`); + return 1; + } + if (size > compare) { const message = `Failed: ` + `Size of ${name} has grown more than 10%. ${size} vs ${expected}`; console.log(`${BOLD_RED}${message}${ANSI_RESET}`); return 1; - } else { - const message = - `Size of ${name} at ${size} compared to previous ${expected}`; - console.log(`${BOLD_GREEN}${message}${ANSI_RESET}`); - return 0; } + + const message = + `Size of ${name} at ${size} compared to previous ${expected}`; + console.log(`${BOLD_GREEN}${message}${ANSI_RESET}`); + return 0; } /** diff --git a/tests/scripts/check_metadata.sh b/tests/scripts/check_metadata.sh index 35dd8232e..7df0b1b8d 100755 --- a/tests/scripts/check_metadata.sh +++ b/tests/scripts/check_metadata.sh @@ -33,7 +33,7 @@ readonly RELEASE_DIR='dist' # Q3 2022 8.0.0 1040413 (mid-quarter typescript conversion) # Q4 2022 8.0.0 870104 # Q4 2022 9.1.1 903357 -readonly BLOCKLY_SIZE_EXPECTED= 903357 +readonly BLOCKLY_SIZE_EXPECTED=903357 # Size of blocks_compressed.js # Q2 2019 2.20190722.0 75618 @@ -52,7 +52,7 @@ readonly BLOCKLY_SIZE_EXPECTED= 903357 # Q3 2022 8.0.0 102176 (mid-quarter typescript conversion) # Q4 2022 8.0.0 102213 # Q4 2022 9.1.1 102190 -readonly BLOCKS_SIZE_EXPECTED= 102190 +readonly BLOCKS_SIZE_EXPECTED=102190 # Size of blockly_compressed.js.gz # Q2 2019 2.20190722.0 180925 @@ -72,7 +72,7 @@ readonly BLOCKS_SIZE_EXPECTED= 102190 # Q3 2022 8.0.0 185766 (mid-quarter typescript conversion) # Q4 2022 8.0.0 175140 # Q4 2022 9.1.1 179306 -readonly BLOCKLY_GZ_SIZE_EXPECTED= 179306 +readonly BLOCKLY_GZ_SIZE_EXPECTED=179306 # Size of blocks_compressed.js.gz # Q2 2019 2.20190722.0 14552 @@ -91,7 +91,7 @@ readonly BLOCKLY_GZ_SIZE_EXPECTED= 179306 # Q3 2022 8.0.0 17016 (mid-quarter typescript conversion) # Q4 2022 8.0.0 17188 # Q4 2022 9.1.1 17182 -readonly BLOCKS_GZ_SIZE_EXPECTED= 17182 +readonly BLOCKS_GZ_SIZE_EXPECTED=17182 # ANSI colors readonly BOLD_GREEN='\033[1;32m' diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index 516409a54..e923b664f 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -12,10 +12,12 @@ readonly RELEASE_DIR='dist' gzip -k "${RELEASE_DIR}/blockly_compressed.js" gzip -k "${RELEASE_DIR}/blocks_compressed.js" -blockly_size=$(wc -c < "${RELEASE_DIR}/blockly_compressed.js") -blocks_size=$(wc -c < "${RELEASE_DIR}/blocks_compressed.js") -blockly_gz_size=$(wc -c < "${RELEASE_DIR}/blockly_compressed.js.gz") -blocks_gz_size=$(wc -c < "${RELEASE_DIR}/blocks_compressed.js.gz") +# wc prefixes the file size with whitespace; xargs strips that and the -n flag to +# echo removes the newline. +blockly_size=$(wc -c < "${RELEASE_DIR}/blockly_compressed.js" | xargs echo -n) +blocks_size=$(wc -c < "${RELEASE_DIR}/blocks_compressed.js" | xargs echo -n) +blockly_gz_size=$(wc -c < "${RELEASE_DIR}/blockly_compressed.js.gz" | xargs echo -n) +blocks_gz_size=$(wc -c < "${RELEASE_DIR}/blocks_compressed.js.gz" | xargs echo -n) quarters=(1 1 1 2 2 2 3 3 3 4 4 4) month=$(date +%-m) quarter=$(echo Q${quarters[$month - 1]} $(date +%Y))