Skip to content

Commit 36949bd

Browse files
committed
test(packageresolution): add lockfile version support integration tests
1 parent a4f9444 commit 36949bd

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test lockfile: check patch with lockfile 1 1`] = `
4+
"SNAPSHOT: check patch with lockfile 1
5+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
6+
index e90aec3..7f8fdaa 100644
7+
--- a/node_modules/left-pad/index.js
8+
+++ b/node_modules/left-pad/index.js
9+
@@ -22,9 +22,9 @@ var cache = [
10+
function leftPad (str, len, ch) {
11+
// convert \`str\` to a \`string\`
12+
str = str + '';
13+
- // \`len\` is the \`pad\`'s length now
14+
+ // \`len\` is the \`npm\`'s length now
15+
len = len - str.length;
16+
- // doesn't need to pad
17+
+ // doesn't need to npm
18+
if (len <= 0) return str;
19+
// \`ch\` defaults to \`' '\`
20+
if (!ch && ch !== 0) ch = ' ';
21+
@@ -32,12 +32,12 @@ function leftPad (str, len, ch) {
22+
ch = ch + '';
23+
// cache common use cases
24+
if (ch === ' ' && len < 10) return cache[len] + str;
25+
- // \`pad\` starts with an empty string
26+
- var pad = '';
27+
+ // \`npm\` starts with an empty string
28+
+ var npm = '';
29+
// loop
30+
while (true) {
31+
- // add \`ch\` to \`pad\` if \`len\` is odd
32+
- if (len & 1) pad += ch;
33+
+ // add \`ch\` to \`npm\` if \`len\` is odd
34+
+ if (len & 1) npm += ch;
35+
// divide \`len\` by 2, ditch the remainder
36+
len >>= 1;
37+
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
38+
@@ -47,6 +47,6 @@ function leftPad (str, len, ch) {
39+
// \`len\` is 0, exit the loop
40+
else break;
41+
}
42+
- // pad \`str\`!
43+
- return pad + str;
44+
+ // npm \`str\`!
45+
+ return npm + str;
46+
}
47+
END SNAPSHOT"
48+
`;
49+
50+
exports[`Test lockfile: check patch with lockfile 2 1`] = `
51+
"SNAPSHOT: check patch with lockfile 2
52+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
53+
index e90aec3..7f8fdaa 100644
54+
--- a/node_modules/left-pad/index.js
55+
+++ b/node_modules/left-pad/index.js
56+
@@ -22,9 +22,9 @@ var cache = [
57+
function leftPad (str, len, ch) {
58+
// convert \`str\` to a \`string\`
59+
str = str + '';
60+
- // \`len\` is the \`pad\`'s length now
61+
+ // \`len\` is the \`npm\`'s length now
62+
len = len - str.length;
63+
- // doesn't need to pad
64+
+ // doesn't need to npm
65+
if (len <= 0) return str;
66+
// \`ch\` defaults to \`' '\`
67+
if (!ch && ch !== 0) ch = ' ';
68+
@@ -32,12 +32,12 @@ function leftPad (str, len, ch) {
69+
ch = ch + '';
70+
// cache common use cases
71+
if (ch === ' ' && len < 10) return cache[len] + str;
72+
- // \`pad\` starts with an empty string
73+
- var pad = '';
74+
+ // \`npm\` starts with an empty string
75+
+ var npm = '';
76+
// loop
77+
while (true) {
78+
- // add \`ch\` to \`pad\` if \`len\` is odd
79+
- if (len & 1) pad += ch;
80+
+ // add \`ch\` to \`npm\` if \`len\` is odd
81+
+ if (len & 1) npm += ch;
82+
// divide \`len\` by 2, ditch the remainder
83+
len >>= 1;
84+
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
85+
@@ -47,6 +47,6 @@ function leftPad (str, len, ch) {
86+
// \`len\` is 0, exit the loop
87+
else break;
88+
}
89+
- // pad \`str\`!
90+
- return pad + str;
91+
+ // npm \`str\`!
92+
+ return npm + str;
93+
}
94+
END SNAPSHOT"
95+
`;
96+
97+
exports[`Test lockfile: check patch with lockfile 3 1`] = `
98+
"SNAPSHOT: check patch with lockfile 3
99+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
100+
index e90aec3..7f8fdaa 100644
101+
--- a/node_modules/left-pad/index.js
102+
+++ b/node_modules/left-pad/index.js
103+
@@ -22,9 +22,9 @@ var cache = [
104+
function leftPad (str, len, ch) {
105+
// convert \`str\` to a \`string\`
106+
str = str + '';
107+
- // \`len\` is the \`pad\`'s length now
108+
+ // \`len\` is the \`npm\`'s length now
109+
len = len - str.length;
110+
- // doesn't need to pad
111+
+ // doesn't need to npm
112+
if (len <= 0) return str;
113+
// \`ch\` defaults to \`' '\`
114+
if (!ch && ch !== 0) ch = ' ';
115+
@@ -32,12 +32,12 @@ function leftPad (str, len, ch) {
116+
ch = ch + '';
117+
// cache common use cases
118+
if (ch === ' ' && len < 10) return cache[len] + str;
119+
- // \`pad\` starts with an empty string
120+
- var pad = '';
121+
+ // \`npm\` starts with an empty string
122+
+ var npm = '';
123+
// loop
124+
while (true) {
125+
- // add \`ch\` to \`pad\` if \`len\` is odd
126+
- if (len & 1) pad += ch;
127+
+ // add \`ch\` to \`npm\` if \`len\` is odd
128+
+ if (len & 1) npm += ch;
129+
// divide \`len\` by 2, ditch the remainder
130+
len >>= 1;
131+
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
132+
@@ -47,6 +47,6 @@ function leftPad (str, len, ch) {
133+
// \`len\` is 0, exit the loop
134+
else break;
135+
}
136+
- // pad \`str\`!
137+
- return pad + str;
138+
+ // npm \`str\`!
139+
+ return npm + str;
140+
}
141+
END SNAPSHOT"
142+
`;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
npm i $1
6+
alias patch-package=./node_modules/.bin/patch-package
7+
8+
function testLockFile() {
9+
echo "Version test $1"
10+
npm i --lockfile-version $1
11+
12+
echo "cleanup patches"
13+
npx rimraf patches
14+
15+
echo "replace pad with yarn in left-pad/index.js"
16+
npx replace pad npm node_modules/left-pad/index.js
17+
18+
echo "patch-package should run"
19+
patch-package left-pad
20+
21+
echo "SNAPSHOT: check patch with lockfile $1"
22+
cat patches/left-pad+1.3.0.patch
23+
echo "END SNAPSHOT"
24+
}
25+
26+
echo "test lockfile v1"
27+
testLockFile 1
28+
29+
echo "test lockfile v2"
30+
testLockFile 2
31+
32+
echo "test lockfile v3"
33+
testLockFile 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
runIntegrationTest({ projectName: "lockfile", shouldProduceSnapshots: true })
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "lockfile",
3+
"version": "1.0.0",
4+
"description": "integration test for patch-package",
5+
"main": "index.js",
6+
"author": "anas10",
7+
"license": "ISC",
8+
"dependencies": {
9+
"left-pad": "1.3.0"
10+
}
11+
}

integration-tests/lockfile/yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"left-pad@^1.1.3":
6+
"integrity" "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA=="
7+
"resolved" "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz"
8+
"version" "1.3.0"

0 commit comments

Comments
 (0)