Skip to content

Commit 0e087bd

Browse files
committed
add tests for error colation
1 parent c6851b7 commit 0e087bd

10 files changed

+194
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test collate-errors: left-pad, lodash, and zfs apply 1`] = `
4+
"SNAPSHOT: left-pad, lodash, and zfs apply
5+
patch-package 0.0.0
6+
Applying patches...
7+
8+
9+
10+
END SNAPSHOT"
11+
`;
12+
13+
exports[`Test collate-errors: underscore does not apply, left-pad warns 1`] = `
14+
"SNAPSHOT: underscore does not apply, left-pad warns
15+
16+
Warning: patch-package detected a patch file version mismatch
17+
18+
Don't worry! This is probably fine. The patch was still applied
19+
successfully. Here's the deets:
20+
21+
Patch file created for
22+
23+
24+
25+
applied to
26+
27+
28+
29+
At path
30+
31+
node_modules/left-pad
32+
33+
This warning is just to give you a heads-up. There is a small chance of
34+
breakage even though the patch was applied successfully. Make sure the package
35+
still behaves like you expect (you wrote tests, right?) and then run
36+
37+
patch-package left-pad
38+
39+
to update the version in the patch file name and make this warning go away.
40+
41+
42+
**ERROR** Failed to apply patch for package underscore at path
43+
44+
node_modules/underscore
45+
46+
This error was caused because underscore has changed since you
47+
made the patch file for it. This introduced conflicts with your patch,
48+
just like a merge conflict in Git when separate incompatible changes are
49+
made to the same piece of code.
50+
51+
Maybe this means your patch file is no longer necessary, in which case
52+
hooray! Just delete it!
53+
54+
Otherwise, you need to generate a new patch file.
55+
56+
To generate a new one, just repeat the steps you made to generate the first
57+
one.
58+
59+
i.e. manually make the appropriate file changes, then run
60+
61+
patch-package underscore
62+
63+
Info:
64+
Patch file: patches/underscore+1.0.3.patch
65+
Patch was made for version: 1.0.3
66+
Installed version: 1.12.0
67+
68+
---
69+
patch-package finished with 1 warning(s), 1 error(s).
70+
END SNAPSHOT"
71+
`;
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+
alias patch-package=./node_modules/.bin/patch-package
7+
8+
echo "SNAPSHOT: left-pad, lodash, and zfs apply"
9+
(>&2 echo "SNAPSHOT: underscore does not apply, left-pad warns")
10+
if patch-package;
11+
then
12+
exit 1
13+
fi
14+
(>&2 echo "END SNAPSHOT")
15+
echo "END SNAPSHOT"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({
3+
projectName: "collate-errors",
4+
shouldProduceSnapshots: true,
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "collate-errors",
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.1.2",
10+
"lodash": "^4.17.21",
11+
"underscore": "^1.12.0",
12+
"zfs": "^1.3.0"
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
2+
index 6b56df3..3433636 100644
3+
--- a/node_modules/left-pad/index.js
4+
+++ b/node_modules/left-pad/index.js
5+
@@ -1,6 +1,9 @@
6+
'use strict';
7+
module.exports = leftPad;
8+
9+
+
10+
+// patch-package
11+
+
12+
var cache = [
13+
'',
14+
' ',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/node_modules/lodash/_arrayFilter.js b/node_modules/lodash/_arrayFilter.js
2+
index 75ea254..444241d 100644
3+
--- a/node_modules/lodash/_arrayFilter.js
4+
+++ b/node_modules/lodash/_arrayFilter.js
5+
@@ -2,7 +2,7 @@
6+
* A specialized version of `_.filter` for arrays without support for
7+
* iteratee shorthands.
8+
*
9+
- * @private
10+
+ * @patchPackage
11+
* @param {Array} [array] The array to iterate over.
12+
* @param {Function} predicate The function invoked per iteration.
13+
* @returns {Array} Returns the new filtered array.
14+
diff --git a/node_modules/lodash/ceil.js b/node_modules/lodash/ceil.js
15+
index 56c8722..b4a5e1f 100644
16+
--- a/node_modules/lodash/ceil.js
17+
+++ b/node_modules/lodash/ceil.js
18+
@@ -23,4 +23,6 @@ var createRound = require('./_createRound');
19+
*/
20+
var ceil = createRound('ceil');
21+
22+
+// patch-package
23+
+
24+
module.exports = ceil;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/underscore/README b/node_modules/underscore/README
2+
index 333b13f..dc192cf 100644
3+
--- a/node_modules/underscore/README
4+
+++ b/node_modules/underscore/README
5+
@@ -16,7 +16,7 @@ in JavaScript objects. It's the tie to go along with jQuery's tux.
6+
For Docs, License, Tests, and pre-packed downloads, see:
7+
http://documentcloud.github.com/underscore/
8+
9+
-Many thanks to our contributors:
10+
+Many thanks to our wonderful contributors:
11+
12+
Dmitry Baranovskiy
13+
Tim Caswell
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/node_modules/zfs/lib/main.js b/node_modules/zfs/lib/main.js
2+
index ce5f7dd..0d6432b 100644
3+
--- a/node_modules/zfs/lib/main.js
4+
+++ b/node_modules/zfs/lib/main.js
5+
@@ -13,6 +13,7 @@ exports.mount = zfs.mount;
6+
exports.unmount = zfs.unmount;
7+
exports.send = zfs.send;
8+
exports.receive = zfs.receive;
9+
+exports.patchPackage = yes;
10+
11+
exports.zfs = {
12+
set: zfs.set,
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
6+
version "1.1.2"
7+
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.2.tgz#b46d4b36116fafb6f2814c30ecf3247bdfd842f7"
8+
integrity sha1-tG1LNhFvr7bygUww7PMke9/YQvc=
9+
10+
lodash@^4.17.21:
11+
version "4.17.21"
12+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
13+
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
14+
15+
underscore@^1.12.0:
16+
version "1.12.0"
17+
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.12.0.tgz#4814940551fc80587cef7840d1ebb0f16453be97"
18+
integrity sha512-21rQzss/XPMjolTiIezSu3JAjgagXKROtNrYFEOWK109qY1Uv2tVjPTZ1ci2HgvQDA16gHYSthQIJfB+XId/rQ==
19+
20+
zfs@^1.3.0:
21+
version "1.3.0"
22+
resolved "https://registry.yarnpkg.com/zfs/-/zfs-1.3.0.tgz#aa5e2e5469da762273e16361ec9d7822e44b4ae4"
23+
integrity sha1-ql4uVGnadiJz4WNh7J14IuRLSuQ=

src/applyPatches.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ export function applyPatchesForApp({
167167
path,
168168
}),
169169
)
170-
} else {
171-
console.log(
172-
`${chalk.bold(pathSpecifier)}@${version} ${chalk.green("✔")}`,
173-
)
174170
}
171+
console.log(
172+
`${chalk.bold(pathSpecifier)}@${version} ${chalk.green("✔")}`,
173+
)
175174
} else if (installedPackageVersion === version) {
176175
// completely failed to apply patch
177176
// TODO: propagate useful error messages from patch application

0 commit comments

Comments
 (0)