Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Jul 14, 2023
1 parent df30019 commit d68b6af
Show file tree
Hide file tree
Showing 47 changed files with 296 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ 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
patch-package 0.0.0
• Creating temporary folder
• Installing left-pad@1.3.0 with npm
• Diffing your files with clean files
Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad
END SNAPSHOT"
`;

exports[`Test append-patches: 08: --append is not compatible with --create-issue 1`] = `
"SNAPSHOT: --append is not compatible with --create-issue
patch-package 0.0.0
--create-issue is not compatible with --append.
END SNAPSHOT"
`;
8 changes: 4 additions & 4 deletions integration-tests/append-patches/append-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ 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")
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")
echo "END SNAPSHOT"

(>&2 echo "SNAPSHOT: --append is not compatible with --create-issue")
echo "SNAPSHOT: --append is not compatible with --create-issue"
if patch-package left-pad --append 'Bananas' --create-issue ; then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ END SNAPSHOT"
exports[`Test apply-multiple-patches: 01: patch-package stores a state file to list the patches that have been applied 1`] = `
"SNAPSHOT: patch-package stores a state file to list the patches that have been applied
{
\\"isRebasing\\": false,
\\"patches\\": [
{
\\"didApply\\": true,
Expand All @@ -30,62 +31,80 @@ exports[`Test apply-multiple-patches: 01: patch-package stores a state file to l
\\"patchFilename\\": \\"left-pad+1.3.0+004+goodbye.patch\\"
}
],
\\"version\\": 0
\\"version\\": 1
}END SNAPSHOT"
`;

exports[`Test apply-multiple-patches: 02: patch-package only applies the first patch if the second of three is invalid 1`] = `
exports[`Test apply-multiple-patches: 02: patch-package fails when a patch in the sequence is invalid 1`] = `
"SNAPSHOT: patch-package fails when a patch in the sequence is invalid
patch-package 0.0.0
Applying patches...
left-pad@1.3.0 (1 hello) ✔
⛔ ERROR
Failed to apply patch file left-pad+1.3.0+002+broken.patch.
If this patch file is no longer useful, delete it and run
patch-package
Otherwise you should open node_modules/left-pad, manually apply the changes from the patch file, and run
patch-package left-pad
to update the patch file.
END SNAPSHOT"
`;

exports[`Test apply-multiple-patches: 03: patch-package only applies the first patch if the second of three is invalid 1`] = `
"SNAPSHOT: patch-package only applies the first patch if the second of three is invalid
patch-package 0.0.0
Applying patches...
left-pad@1.3.0 (1 hello) ✔
⛔ ERROR
Failed to apply patch file left-pad+1.3.0+002+broken.patch.
If this patch file is no longer useful, delete it and run
patch-package
Otherwise you should open node_modules/left-pad, manually apply the changes from the patch file, and run
patch-package left-pad
to update the patch file.
END SNAPSHOT"
`;

exports[`Test apply-multiple-patches: 03: patch-package stores a state file of only the first patch if there was an error 1`] = `
exports[`Test apply-multiple-patches: 04: patch-package stores a state file of only the first patch if there was an error 1`] = `
"SNAPSHOT: patch-package stores a state file of only the first patch if there was an error
{
\\"isRebasing\\": true,
\\"patches\\": [
{
\\"didApply\\": true,
\\"patchContentHash\\": \\"404c604ed830db6a0605f86cb9165ced136848f70986b23bf877bcf38968c1c9\\",
\\"patchFilename\\": \\"left-pad+1.3.0+001+hello.patch\\"
},
{
\\"didApply\\": false,
\\"patchContentHash\\": \\"9c5c141e2578b4178fd57dd7726488c2f7eab32e23a7848701da29dcb371b9f2\\",
\\"patchFilename\\": \\"left-pad+1.3.0+002+broken.patch\\"
}
],
\\"version\\": 0
\\"version\\": 1
}END SNAPSHOT"
`;

exports[`Test apply-multiple-patches: 04: patch-package fails when a patch in the sequence is invalid 1`] = `
"SNAPSHOT: patch-package fails when a patch in the sequence is invalid
**ERROR** Failed to apply patch for package left-pad at path
node_modules/left-pad
This error was caused because patch-package cannot apply the following patch file:
patches/left-pad+1.3.0+002+broken.patch
Try removing node_modules and trying again. If that doesn't work, maybe there was
an accidental change made to the patch file? Try recreating it by manually
editing the appropriate files and running:
patch-package left-pad
If that doesn't work, then it's a bug in patch-package, so please submit a bug
report. Thanks!
https://github.com/ds300/patch-package/issues
---
patch-package finished with 1 error(s).
END SNAPSHOT"
`;

exports[`Test apply-multiple-patches: 05: patch-package fails when a patch file is removed 1`] = `
"SNAPSHOT: patch-package fails when a patch file is removed
patch-package 0.0.0
Applying patches...
Error: The patches for left-pad have changed. You should reinstall your node_modules folder to make sure the package is up to date
END SNAPSHOT"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ cp *broken.patch patches/

rm -rf node_modules
npm install
(>&2 echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid")
echo "SNAPSHOT: patch-package fails when a patch in the sequence is invalid"
if patch-package
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"


echo "SNAPSHOT: patch-package only applies the first patch if the second of three is invalid"
Expand All @@ -47,9 +47,9 @@ echo "END SNAPSHOT"


rm patches/*hello.patch
(>&2 echo "SNAPSHOT: patch-package fails when a patch file is removed")
echo "SNAPSHOT: patch-package fails when a patch file is removed"
if patch-package
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`Test broken-patch-file: 00: patch-package fails when patch file is invalid 1`] = `
"SNAPSHOT: patch-package fails when patch file is invalid
patch-package 0.0.0
Applying patches...
**ERROR** Failed to apply patch for package left-pad at path
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/broken-patch-file/broken-patch-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ echo "add patch-package"
yarn add $1
alias patch-package=./node_modules/.bin/patch-package

(>&2 echo "SNAPSHOT: patch-package fails when patch file is invalid")
echo "SNAPSHOT: patch-package fails when patch file is invalid"
if patch-package
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

exports[`Test collate-errors: 00: left-pad, lodash, and zfs apply 1`] = `
"SNAPSHOT: left-pad, lodash, and zfs apply
SNAPSHOT: underscore does not apply, left-pad warns
patch-package 0.0.0
Applying patches...
left-pad@1.1.1 ✔
lodash@4.17.21 ✔
zfs@1.3.0 ✔
END SNAPSHOT"
`;

exports[`Test collate-errors: 01: underscore does not apply, left-pad warns 1`] = `
"SNAPSHOT: underscore does not apply, left-pad warns
Warning: patch-package detected a patch file version mismatch
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/collate-errors/collate-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ yarn add $1
alias patch-package=./node_modules/.bin/patch-package

echo "SNAPSHOT: left-pad, lodash, and zfs apply"
(>&2 echo "SNAPSHOT: underscore does not apply, left-pad warns")
echo "SNAPSHOT: underscore does not apply, left-pad warns"
if patch-package;
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"
echo "END SNAPSHOT"
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ Skipping dev-only slash@3.0.0 ✔
END SNAPSHOT"
`;

exports[`Test dev-only-patches: 01: fake-package should be skipped 1`] = `
"SNAPSHOT: fake-package should be skipped
exports[`Test dev-only-patches: 01: patch-package fails to find fake-package 1`] = `
"SNAPSHOT: patch-package fails to find fake-package
patch-package 0.0.0
Applying patches...
Skipping dev-only fake-package@3.0.0 ✔
left-pad@1.3.0 ✔
Skipping dev-only slash@3.0.0 ✔
END SNAPSHOT"
`;

exports[`Test dev-only-patches: 02: patch-package fails to find fake-package 1`] = `
"SNAPSHOT: patch-package fails to find fake-package
Error: Patch file found for package fake-package which is not present at node_modules/fake-package
If this package is a dev dependency, rename the patch file to
Expand All @@ -31,3 +25,13 @@ Error: Patch file found for package fake-package which is not present at node_mo
patch-package finished with 1 error(s).
END SNAPSHOT"
`;

exports[`Test dev-only-patches: 02: fake-package should be skipped 1`] = `
"SNAPSHOT: fake-package should be skipped
patch-package 0.0.0
Applying patches...
Skipping dev-only fake-package@3.0.0 ✔
left-pad@1.3.0 ✔
Skipping dev-only slash@3.0.0 ✔
END SNAPSHOT"
`;
4 changes: 2 additions & 2 deletions integration-tests/dev-only-patches/dev-only-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ echo "END SNAPSHOT"
echo "create fake-package+3.0.0.patch"
cp patches/slash+3.0.0.patch patches/fake-package+3.0.0.patch

(>&2 echo "SNAPSHOT: patch-package fails to find fake-package")
echo "SNAPSHOT: patch-package fails to find fake-package"
if patch-package
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"

echo "rename fake-package patch file to .dev.patch"
mv patches/fake-package+3.0.0.patch patches/fake-package+3.0.0.dev.patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`Test error-on-fail: 00: at dev time patch-package fails but returns 0 1`] = `
"SNAPSHOT: at dev time patch-package fails but returns 0
patch-package 0.0.0
Applying patches...
**ERROR** Failed to apply patch for package left-pad at path
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/error-on-fail/error-on-fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ alias patch-package=./node_modules/.bin/patch-package
export NODE_ENV="development"
export CI="true"

(>&2 echo "SNAPSHOT: at dev time patch-package fails but returns 0")
echo "SNAPSHOT: at dev time patch-package fails but returns 0"
if ! patch-package;
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"

echo "adding --error-on-fail forces patch-package to return 1 at dev time"
if patch-package --error-on-fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`Test error-on-warn: 00: at dev time patch-package warns but returns 0 1`] = `
"SNAPSHOT: at dev time patch-package warns but returns 0
patch-package 0.0.0
Applying patches...
left-pad@1.1.2 ✔
Warning: patch-package detected a patch file version mismatch
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/error-on-warn/error-on-warn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ alias patch-package=./node_modules/.bin/patch-package
export NODE_ENV="development"
export CI=""

(>&2 echo "SNAPSHOT: at dev time patch-package warns but returns 0")
echo "SNAPSHOT: at dev time patch-package warns but returns 0"
if ! patch-package;
then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"

echo "adding --error-on-warn forces patch-package to return 1 at dev time"
if patch-package --error-on-warn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`Test fails-when-no-package: 00: no package present failure 1`] = `
"SNAPSHOT: no package present failure
patch-package 0.0.0
Applying patches...
Error: Patch file found for package left-pad which is not present at node_modules/left-pad
---
patch-package finished with 1 error(s).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ echo "add patch-package"
yarn add $1
alias patch-package=./node_modules/.bin/patch-package

(>&2 echo "SNAPSHOT: no package present failure")
echo "SNAPSHOT: no package present failure"
if patch-package; then
exit 1
fi
(>&2 echo "END SNAPSHOT")
echo "END SNAPSHOT"
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test ignore-whitespace: 00: line a changed 1`] = `
exports[`Test ignore-whitespace: 00: empty changeset when adding whitespace 1`] = `
"SNAPSHOT: empty changeset when adding whitespace
patch-package 0.0.0
• Creating temporary folder
• Installing alphabet@1.0.0 with yarn
• Diffing your files with clean files
⁉️ Not creating patch file for package 'alphabet'
⁉️ There don't appear to be any changes.
END SNAPSHOT"
`;

exports[`Test ignore-whitespace: 01: line a changed 1`] = `
"SNAPSHOT: line a changed
diff --git a/node_modules/alphabet/index.js b/node_modules/alphabet/index.js
index 7811d3b..454414b 100644
Expand All @@ -14,10 +25,3 @@ index 7811d3b..454414b 100644
// d
END SNAPSHOT"
`;

exports[`Test ignore-whitespace: 01: empty changeset when adding whitespace 1`] = `
"SNAPSHOT: empty changeset when adding whitespace
⁉️ Not creating patch file for package 'alphabet'
⁉️ There don't appear to be any changes.
END SNAPSHOT"
`;
Loading

0 comments on commit d68b6af

Please sign in to comment.