diff --git a/test/__snapshots__/prefix/bump-phpunit.sh b/test/__snapshots__/prefix/bump-phpunit.sh new file mode 100644 index 0000000..ab12652 --- /dev/null +++ b/test/__snapshots__/prefix/bump-phpunit.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# This script is a part of the ideasonpurpose/docker-phpunit-watch project +# https://github.com/ideasonpurpose/docker-phpunit-watch +# +# Version: 1.6.18 +# +# For now, manually update the PHPUnit version in phpunit-version.json before running +# +# This script does a few things: +# - Updates the PHPUnit version in Dockerfile +# - Updates the PHPUnit version in README.md +# +# The phpunit-version.json file should be commited to Git. The push-to-dockerhub +# GitHub Action uses this file to generate tag names for the Docker Image. + +# style helpers +RESET="\033[0m" +BOLD="\033[1m" +RED="\033[31m" +GREEN="\033[32m" +GOLD="\033[33m" +BLUE="\033[34m" +MAGENTA="\033[35m" +CYAN="\033[36m" + +PHPUNIT_LATEST=$(jq -r '.phpunit' /app/phpunit-version.json) + +echo -e "✏️ Updating ${GOLD}Dockerfile${RESET} to ${CYAN}phpunit-${PHPUNIT_LATEST}.phar${RESET}" +sed -i "s/phpunit.de\/phpunit-.*phar/phpunit.de\/phpunit-${PHPUNIT_LATEST}.phar/" /app/Dockerfile + +echo -e "✏️ Updating ${GOLD}README.md${RESET} to ${CYAN}v${PHPUNIT_LATEST}${RESET}" +sed -E -i "s/^<\!-- PHPUNIT_VERSION -->- PHPUnit.+$/<\!-- PHPUNIT_VERSION -->- PHPUnit ${PHPUNIT_LATEST}/" /app/README.md diff --git a/test/snapshots.test.js b/test/snapshots.test.js index 05c99a3..a550491 100644 --- a/test/snapshots.test.js +++ b/test/snapshots.test.js @@ -24,6 +24,7 @@ describe("Snapshot Tests:", () => { const newVersion = "1.414.213"; testFiles.forEach((file) => { + // console.log(file); test(path.basename(file), () => { const src = fs.readFileSync(file).toString(); @@ -39,3 +40,19 @@ describe("Snapshot Tests:", () => { }); }); }); + +describe("Shell script re-wrapping with prefix", () => { + const newVersion = "1.6.18"; + + /** + * This is testing a problem discovered with https://github.com/ideasonpurpose/docker-phpunit-watch + * where the bump-phpunit.sh script was being re-wrapped when the version was updated. + */ + test("re-wrapped shell script", async () => { + const result = await updateFile("./test/snapshots/prefix/bump-phpunit.sh", newVersion, {dryRun: true, prefixes: ['hello']}); + console.log(result); + expect(result?.data).toMatchFileSnapshot( + "./__snapshots__/prefix/bump-phpunit.sh" + ); + }); +}); diff --git a/test/snapshots/prefix/bump-phpunit.sh b/test/snapshots/prefix/bump-phpunit.sh new file mode 100644 index 0000000..c22e8b2 --- /dev/null +++ b/test/snapshots/prefix/bump-phpunit.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# This script is a part of the ideasonpurpose/docker-phpunit-watch project +# https://github.com/ideasonpurpose/docker-phpunit-watch +# +# Version: 0.9.4 +# +# For now, manually update the PHPUnit version in phpunit-version.json before running +# +# This script does a few things: +# - Updates the PHPUnit version in Dockerfile +# - Updates the PHPUnit version in README.md +# +# The phpunit-version.json file should be commited to Git. The push-to-dockerhub +# GitHub Action uses this file to generate tag names for the Docker Image. + +# style helpers +RESET="\033[0m" +BOLD="\033[1m" +RED="\033[31m" +GREEN="\033[32m" +GOLD="\033[33m" +BLUE="\033[34m" +MAGENTA="\033[35m" +CYAN="\033[36m" + +PHPUNIT_LATEST=$(jq -r '.phpunit' /app/phpunit-version.json) + +echo -e "✏️ Updating ${GOLD}Dockerfile${RESET} to ${CYAN}phpunit-${PHPUNIT_LATEST}.phar${RESET}" +sed -i "s/phpunit.de\/phpunit-.*phar/phpunit.de\/phpunit-${PHPUNIT_LATEST}.phar/" /app/Dockerfile + +echo -e "✏️ Updating ${GOLD}README.md${RESET} to ${CYAN}v${PHPUNIT_LATEST}${RESET}" +sed -E -i "s/^<\!-- PHPUNIT_VERSION -->- PHPUnit.+$/<\!-- PHPUNIT_VERSION -->- PHPUnit ${PHPUNIT_LATEST}/" /app/README.md