Skip to content

Commit 82d8fc4

Browse files
committed
add tests for new makePatch error handling
1 parent ce03f34 commit 82d8fc4

File tree

11 files changed

+536
-1
lines changed

11 files changed

+536
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test no-symbolic-links: patch-package fails to create a patch when there are symbolic links 1`] = `
4+
"SNAPSHOT: patch-package fails to create a patch when there are symbolic links
5+
6+
⛔️ ERROR
7+
8+
Your changes involve creating symlinks. patch-package does not yet support
9+
symlinks.
10+
11+
️Please use --include and/or --exclude to narrow the scope of your patch if
12+
this was unintentional.
13+
14+
error Command failed with exit code 1.
15+
END SNAPSHOT"
16+
`;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
yarn add $1
6+
7+
echo "make symbolic link"
8+
ln -s package.json node_modules/left-pad/package.parent.json
9+
10+
(>&2 echo "SNAPSHOT: patch-package fails to create a patch when there are symbolic links")
11+
if yarn patch-package left-pad
12+
then
13+
exit 1
14+
fi
15+
(>&2 echo "END SNAPSHOT")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({
3+
projectName: "no-symbolic-links",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "no-symbolic-links",
3+
"version": "1.0.0",
4+
"description": "integration test for patch-package",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "ISC",
8+
"dependencies": {
9+
"left-pad": "1.3.0"
10+
}
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test unexpected-patch-creation-failure: patch-package fails to parse a patch it created 1`] = `
4+
"SNAPSHOT: patch-package fails to parse a patch it created
5+
6+
⛔️ ERROR
7+
8+
patch-package was unable to read the patch-file made by git. This should not
9+
happen.
10+
11+
A diagnostic file was written to
12+
13+
/private/var/folders/kp/4q6sxzl17jq2p_d8pccptx7w0000gq/T/tmp-7498Qc45vBM0jh11/patch-package-error.json.gz
14+
15+
Please attach it to a github issue
16+
17+
https://github.com/ds300/patch-package/issues/new?title=New+patch+parse+failed&body=Please+attach+the+diagnostic+file+by+dragging+it+into+here+🙏
18+
19+
Note that this diagnostic file will contain code from the package you were
20+
attempting to patch.
21+
22+
23+
error Command failed with exit code 1.
24+
END SNAPSHOT"
25+
`;
26+
27+
exports[`Test unexpected-patch-creation-failure: the json file 1`] = `
28+
"SNAPSHOT: the json file
29+
{\\"error\\":{\\"message\\":\\"parse_1.blarseBlatchBlile is not a function\\",\\"stack\\":\\"TypeError: parse_1.blarseBlatchBlile is not a function\\\\n at Object.makePatch (/private/var/folders/kp/4q6sxzl17jq2p_d8pccptx7w0000gq/T/tmp-7498Qc45vBM0jh11/node_modules/patch-package/dist/makePatch.js:112:21)\\\\n at /private/var/folders/kp/4q6sxzl17jq2p_d8pccptx7w0000gq/T/tmp-7498Qc45vBM0jh11/node_modules/patch-package/dist/index.js:48:25\\\\n at Array.forEach (<anonymous>)\\\\n at Object.<anonymous> (/private/var/folders/kp/4q6sxzl17jq2p_d8pccptx7w0000gq/T/tmp-7498Qc45vBM0jh11/node_modules/patch-package/dist/index.js:47:22)\\\\n at Module._compile (internal/modules/cjs/loader.js:689:30)\\\\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\\\\n at Module.load (internal/modules/cjs/loader.js:599:32)\\\\n at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\\\\n at Function.Module._load (internal/modules/cjs/loader.js:530:3)\\\\n at Module.require (internal/modules/cjs/loader.js:637:17)\\"},\\"patch\\":\\"diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js\\\\nindex e90aec3..f2b8b0a 100644\\\\n--- a/node_modules/left-pad/index.js\\\\n+++ b/node_modules/left-pad/index.js\\\\n@@ -4,7 +4,7 @@\\\\n * To Public License, Version 2, as published by Sam Hocevar. See\\\\n * http://www.wtfpl.net/ for more details. */\\\\n 'use strict';\\\\n-module.exports = leftPad;\\\\n+module.exports = patchPackage;\\\\n \\\\n var cache = [\\\\n '',\\\\n@@ -19,7 +19,7 @@ var cache = [\\\\n ' '\\\\n ];\\\\n \\\\n-function leftPad (str, len, ch) {\\\\n+function patchPackage (str, len, ch) {\\\\n // convert \`str\` to a \`string\`\\\\n str = str + '';\\\\n // \`len\` is the \`pad\`'s length now\\\\n\\"}END SNAPSHOT"
30+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "unexpected-patch-creation-failure",
3+
"version": "1.0.0",
4+
"description": "integration test for patch-package",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "ISC",
8+
"dependencies": {
9+
"left-pad": "1.3.0",
10+
"replace": "^1.1.0"
11+
}
12+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
yarn add $1
6+
7+
echo "modify left-pad"
8+
npx replace leftPad patchPackage node_modules/left-pad/index.js
9+
10+
echo "force patch-package to fail"
11+
npx replace 'parsePatchFile\(' 'blarseBlatchBlile(' node_modules/patch-package/dist/makePatch.js
12+
13+
echo "there is no error log file"
14+
if ls ./patch-package-error.json.gz
15+
then
16+
exit 1
17+
fi
18+
19+
(>&2 echo "SNAPSHOT: patch-package fails to parse a patch it created")
20+
if yarn patch-package left-pad
21+
then
22+
exit 1
23+
fi
24+
(>&2 echo "END SNAPSHOT")
25+
26+
echo "there is now an error log file"
27+
ls ./patch-package-error.json.gz
28+
29+
echo "and it can be unzipped"
30+
gzip -d ./patch-package-error.json.gz
31+
32+
echo "SNAPSHOT: the json file"
33+
cat ./patch-package-error.json
34+
echo "END SNAPSHOT"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({
3+
projectName: "unexpected-patch-creation-failure",
4+
shouldProduceSnapshots: true,
5+
})

0 commit comments

Comments
 (0)