Skip to content

Commit f956f95

Browse files
committed
patch sequence appending and updating
1 parent 2ac6424 commit f956f95

File tree

13 files changed

+795
-115
lines changed

13 files changed

+795
-115
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test append-patches: 00: basic patch file 1`] = `
4+
"SNAPSHOT: basic patch file
5+
left-pad+1.3.0.patch
6+
END SNAPSHOT"
7+
`;
8+
9+
exports[`Test append-patches: 01: after appending a patch file 1`] = `
10+
"SNAPSHOT: after appending a patch file
11+
left-pad+1.3.0+001+initial.patch
12+
left-pad+1.3.0+002+MillionDollars.patch
13+
END SNAPSHOT"
14+
`;
15+
16+
exports[`Test append-patches: 02: the second patch file should go from patch-package to a million dollars 1`] = `
17+
"SNAPSHOT: the second patch file should go from patch-package to a million dollars
18+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
19+
index a409e14..73d2a7c 100644
20+
--- a/node_modules/left-pad/index.js
21+
+++ b/node_modules/left-pad/index.js
22+
@@ -3,7 +3,7 @@
23+
* and/or modify it under the terms of the Do What The Fuck You Want
24+
* To Public License, Version 2, as published by Sam Hocevar. See
25+
* http://www.wtfpl.net/ for more details. */
26+
-'use patch-package';
27+
+'use a million dollars';
28+
module.exports = leftPad;
29+
30+
var cache = [
31+
END SNAPSHOT"
32+
`;
33+
34+
exports[`Test append-patches: 03: creating a first patch file with --append 1`] = `
35+
"SNAPSHOT: creating a first patch file with --append
36+
left-pad+1.3.0+001+FirstPatch.patch
37+
END SNAPSHOT"
38+
`;
39+
40+
exports[`Test append-patches: 04: the squashed patch file should go from use strict to a million dollars 1`] = `
41+
"SNAPSHOT: the squashed patch file should go from use strict to a million dollars
42+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
43+
index e90aec3..73d2a7c 100644
44+
--- a/node_modules/left-pad/index.js
45+
+++ b/node_modules/left-pad/index.js
46+
@@ -3,7 +3,7 @@
47+
* and/or modify it under the terms of the Do What The Fuck You Want
48+
* To Public License, Version 2, as published by Sam Hocevar. See
49+
* http://www.wtfpl.net/ for more details. */
50+
-'use strict';
51+
+'use a million dollars';
52+
module.exports = leftPad;
53+
54+
var cache = [
55+
END SNAPSHOT"
56+
`;
57+
58+
exports[`Test append-patches: 05: after appending a billion dollars 1`] = `
59+
"SNAPSHOT: after appending a billion dollars
60+
left-pad+1.3.0+001+FirstPatch.patch
61+
left-pad+1.3.0+002+BillionDollars.patch
62+
END SNAPSHOT"
63+
`;
64+
65+
exports[`Test append-patches: 06: after updating the appended patch file to a TRILLION dollars 1`] = `
66+
"SNAPSHOT: after updating the appended patch file to a TRILLION dollars
67+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
68+
index 73d2a7c..f53ea10 100644
69+
--- a/node_modules/left-pad/index.js
70+
+++ b/node_modules/left-pad/index.js
71+
@@ -3,7 +3,7 @@
72+
* and/or modify it under the terms of the Do What The Fuck You Want
73+
* To Public License, Version 2, as published by Sam Hocevar. See
74+
* http://www.wtfpl.net/ for more details. */
75+
-'use a million dollars';
76+
+'use a trillion dollars';
77+
module.exports = leftPad;
78+
79+
var cache = [
80+
END SNAPSHOT"
81+
`;
82+
83+
exports[`Test append-patches: 07: patch-package fails when a patch in the sequence is invalid 1`] = `
84+
"SNAPSHOT: patch-package fails when a patch in the sequence is invalid
85+
Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad
86+
END SNAPSHOT"
87+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
npm install
5+
6+
echo "add patch-package"
7+
npm add $1
8+
alias patch-package=./node_modules/.bin/patch-package
9+
10+
function replace() {
11+
npx replace "$1" "$2" node_modules/left-pad/index.js
12+
}
13+
14+
echo "making an initial patch file does not add a sequence number to the file by default"
15+
replace 'use strict' 'use patch-package'
16+
17+
patch-package left-pad
18+
19+
echo "SNAPSHOT: basic patch file"
20+
ls patches
21+
echo "END SNAPSHOT"
22+
23+
echo "using --apend creates a patch file with a sequence number and updates the original patch file"
24+
25+
replace 'use patch-package' 'use a million dollars'
26+
27+
patch-package left-pad --append 'MillionDollars'
28+
29+
echo "SNAPSHOT: after appending a patch file"
30+
ls patches
31+
echo "END SNAPSHOT"
32+
33+
echo "SNAPSHOT: the second patch file should go from patch-package to a million dollars"
34+
cat patches/left-pad*MillionDollars.patch
35+
echo "END SNAPSHOT"
36+
37+
echo "we can squash the patches together by deleting the patch files"
38+
rm patches/left-pad*patch
39+
40+
patch-package left-pad --append 'FirstPatch'
41+
42+
echo "SNAPSHOT: creating a first patch file with --append"
43+
ls patches
44+
echo "END SNAPSHOT"
45+
46+
echo "SNAPSHOT: the squashed patch file should go from use strict to a million dollars"
47+
cat patches/left-pad*FirstPatch.patch
48+
echo "END SNAPSHOT"
49+
50+
echo "i can update an appended patch file"
51+
52+
replace 'use a million dollars' 'use a billion dollars'
53+
54+
patch-package left-pad --append 'BillionDollars'
55+
56+
echo "SNAPSHOT: after appending a billion dollars"
57+
ls patches
58+
echo "END SNAPSHOT"
59+
60+
replace 'use a billion dollars' 'use a trillion dollars'
61+
patch-package left-pad
62+
63+
echo "SNAPSHOT: after updating the appended patch file to a TRILLION dollars"
64+
cat patches/left-pad*BillionDollars.patch
65+
echo "END SNAPSHOT"
66+
67+
echo "if one of the patches in the sequence is invalid, the sequence is not applied"
68+
npx replace 'use strict' 'use bananas' patches/*FirstPatch.patch
69+
70+
(>&2 echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid")
71+
if patch-package left-pad --append 'Bananas' ; then
72+
exit 1
73+
fi
74+
(>&2 echo "END SNAPSHOT")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({
3+
projectName: "append-patches",
4+
shouldProduceSnapshots: true,
5+
})

0 commit comments

Comments
 (0)