Skip to content

Commit

Permalink
patch sequence appending and updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Jul 12, 2023
1 parent 2ac6424 commit f956f95
Show file tree
Hide file tree
Showing 13 changed files with 795 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test append-patches: 00: basic patch file 1`] = `
"SNAPSHOT: basic patch file
left-pad+1.3.0.patch
END SNAPSHOT"
`;

exports[`Test append-patches: 01: after appending a patch file 1`] = `
"SNAPSHOT: after appending a patch file
left-pad+1.3.0+001+initial.patch
left-pad+1.3.0+002+MillionDollars.patch
END SNAPSHOT"
`;

exports[`Test append-patches: 02: the second patch file should go from patch-package to a million dollars 1`] = `
"SNAPSHOT: the second patch file should go from patch-package to a million dollars
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index a409e14..73d2a7c 100644
--- a/node_modules/left-pad/index.js
+++ b/node_modules/left-pad/index.js
@@ -3,7 +3,7 @@
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use patch-package';
+'use a million dollars';
module.exports = leftPad;
var cache = [
END SNAPSHOT"
`;

exports[`Test append-patches: 03: creating a first patch file with --append 1`] = `
"SNAPSHOT: creating a first patch file with --append
left-pad+1.3.0+001+FirstPatch.patch
END SNAPSHOT"
`;

exports[`Test append-patches: 04: the squashed patch file should go from use strict to a million dollars 1`] = `
"SNAPSHOT: the squashed patch file should go from use strict to a million dollars
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index e90aec3..73d2a7c 100644
--- a/node_modules/left-pad/index.js
+++ b/node_modules/left-pad/index.js
@@ -3,7 +3,7 @@
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use strict';
+'use a million dollars';
module.exports = leftPad;
var cache = [
END SNAPSHOT"
`;

exports[`Test append-patches: 05: after appending a billion dollars 1`] = `
"SNAPSHOT: after appending a billion dollars
left-pad+1.3.0+001+FirstPatch.patch
left-pad+1.3.0+002+BillionDollars.patch
END SNAPSHOT"
`;

exports[`Test append-patches: 06: after updating the appended patch file to a TRILLION dollars 1`] = `
"SNAPSHOT: after updating the appended patch file to a TRILLION dollars
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
index 73d2a7c..f53ea10 100644
--- a/node_modules/left-pad/index.js
+++ b/node_modules/left-pad/index.js
@@ -3,7 +3,7 @@
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details. */
-'use a million dollars';
+'use a trillion dollars';
module.exports = leftPad;
var cache = [
END SNAPSHOT"
`;

exports[`Test append-patches: 07: patch-package fails when a patch in the sequence is invalid 1`] = `
"SNAPSHOT: patch-package fails when a patch in the sequence is invalid
Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad
END SNAPSHOT"
`;
74 changes: 74 additions & 0 deletions integration-tests/append-patches/append-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# make sure errors stop the script
set -e

npm install

echo "add patch-package"
npm add $1
alias patch-package=./node_modules/.bin/patch-package

function replace() {
npx replace "$1" "$2" node_modules/left-pad/index.js
}

echo "making an initial patch file does not add a sequence number to the file by default"
replace 'use strict' 'use patch-package'

patch-package left-pad

echo "SNAPSHOT: basic patch file"
ls patches
echo "END SNAPSHOT"

echo "using --apend creates a patch file with a sequence number and updates the original patch file"

replace 'use patch-package' 'use a million dollars'

patch-package left-pad --append 'MillionDollars'

echo "SNAPSHOT: after appending a patch file"
ls patches
echo "END SNAPSHOT"

echo "SNAPSHOT: the second patch file should go from patch-package to a million dollars"
cat patches/left-pad*MillionDollars.patch
echo "END SNAPSHOT"

echo "we can squash the patches together by deleting the patch files"
rm patches/left-pad*patch

patch-package left-pad --append 'FirstPatch'

echo "SNAPSHOT: creating a first patch file with --append"
ls patches
echo "END SNAPSHOT"

echo "SNAPSHOT: the squashed patch file should go from use strict to a million dollars"
cat patches/left-pad*FirstPatch.patch
echo "END SNAPSHOT"

echo "i can update an appended patch file"

replace 'use a million dollars' 'use a billion dollars'

patch-package left-pad --append 'BillionDollars'

echo "SNAPSHOT: after appending a billion dollars"
ls patches
echo "END SNAPSHOT"

replace 'use a billion dollars' 'use a trillion dollars'
patch-package left-pad

echo "SNAPSHOT: after updating the appended patch file to a TRILLION dollars"
cat patches/left-pad*BillionDollars.patch
echo "END SNAPSHOT"

echo "if one of the patches in the sequence is invalid, the sequence is not applied"
npx replace 'use strict' 'use bananas' patches/*FirstPatch.patch

(>&2 echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid")
if patch-package left-pad --append 'Bananas' ; then
exit 1
fi
(>&2 echo "END SNAPSHOT")
5 changes: 5 additions & 0 deletions integration-tests/append-patches/append-patches.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { runIntegrationTest } from "../runIntegrationTest"
runIntegrationTest({
projectName: "append-patches",
shouldProduceSnapshots: true,
})
Loading

0 comments on commit f956f95

Please sign in to comment.