Skip to content

Commit 2d26419

Browse files
author
David Sheldrick
committed
move 'happy-path' tests to new stuff
1 parent b5554df commit 2d26419

File tree

16 files changed

+501
-235
lines changed

16 files changed

+501
-235
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test happy-path-npm: making patch 1`] = `
4+
"SNAPSHOT: making patch
5+
☑ Creating temporary folder
6+
☑ Building clean node_modules with npm
7+
☑ Diffing your files with clean files
8+
✔ Created file patches/left-pad+1.1.3.patch
9+
END SNAPSHOT"
10+
`;
11+
12+
exports[`Test happy-path-npm: the patch looks like this 1`] = `
13+
"SNAPSHOT: the patch looks like this
14+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
15+
index 26f73ff..d4cc4af 100644
16+
--- a/node_modules/left-pad/index.js
17+
+++ b/node_modules/left-pad/index.js
18+
@@ -22,9 +22,9 @@ var cache = [
19+
function leftPad (str, len, ch) {
20+
// convert \`str\` to \`string\`
21+
str = str + '';
22+
- // \`len\` is the \`pad\`'s length now
23+
+ // \`len\` is the \`npm\`'s length now
24+
len = len - str.length;
25+
- // doesn't need to pad
26+
+ // doesn't need to npm
27+
if (len <= 0) return str;
28+
// \`ch\` defaults to \`' '\`
29+
if (!ch && ch !== 0) ch = ' ';
30+
@@ -32,12 +32,12 @@ function leftPad (str, len, ch) {
31+
ch = ch + '';
32+
// cache common use cases
33+
if (ch === ' ' && len < 10) return cache[len] + str;
34+
- // \`pad\` starts with an empty string
35+
- var pad = '';
36+
+ // \`npm\` starts with an empty string
37+
+ var npm = '';
38+
// loop
39+
while (true) {
40+
- // add \`ch\` to \`pad\` if \`len\` is odd
41+
- if (len & 1) pad += ch;
42+
+ // add \`ch\` to \`npm\` if \`len\` is odd
43+
+ if (len & 1) npm += ch;
44+
// divide \`len\` by 2, ditch the remainder
45+
len >>= 1;
46+
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
47+
@@ -47,6 +47,6 @@ function leftPad (str, len, ch) {
48+
// \`len\` is 0, exit the loop
49+
else break;
50+
}
51+
- // pad \`str\`!
52+
- return pad + str;
53+
+ // npm \`str\`!
54+
+ return npm + str;
55+
}
56+
END SNAPSHOT"
57+
`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("fs").writeFileSync(
2+
"./package.json",
3+
JSON.stringify({
4+
...require("./package.json"),
5+
scripts: {
6+
postinstall: "patch-package",
7+
},
8+
}),
9+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
npm i
5+
6+
echo "add patch-package"
7+
npm i $1
8+
9+
echo "Add left-pad"
10+
npm i left-pad@1.1.3
11+
12+
echo "replace pad with yarn in left-pad/index.js"
13+
replace pad npm node_modules/left-pad/index.js
14+
15+
echo "SNAPSHOT: making patch"
16+
patch-package left-pad
17+
echo "END SNAPSHOT"
18+
19+
echo "SNAPSHOT: the patch looks like this"
20+
cat patches/left-pad+1.1.3.patch
21+
echo "END SNAPSHOT"
22+
23+
echo "reinstall node_modules"
24+
rimraf node_modules
25+
npm i
26+
27+
echo "patch-package didn't run"
28+
if grep npm node_modules/left-pad/index.js ; then
29+
exit 1
30+
fi
31+
32+
echo "add patch-package to postinstall hook"
33+
node ./add-postinstall.js
34+
35+
echo "reinstall node_modules"
36+
rimraf node_modules
37+
npm i
38+
39+
echo "patch-package did run"
40+
grep npm node_modules/left-pad/index.js
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("happy-path-npm")

integration-tests/happy-path-npm/package-lock.json

Lines changed: 147 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "happy-path-npm",
3+
"version": "1.0.0",
4+
"description": "integration test for patch-package",
5+
"main": "index.js",
6+
"author": "",
7+
"license": "ISC",
8+
"dependencies": {
9+
"replace": "^1.0.0",
10+
"rimraf": "^2.6.2"
11+
}
12+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test happy-path-yarn: making patch 1`] = `
4+
"SNAPSHOT: making patch
5+
☑ Creating temporary folder
6+
☑ Building clean node_modules with yarn
7+
☑ Diffing your files with clean files
8+
✔ Created file patches/left-pad+1.1.3.patch
9+
END SNAPSHOT"
10+
`;
11+
12+
exports[`Test happy-path-yarn: the patch looks like this 1`] = `
13+
"SNAPSHOT: the patch looks like this
14+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
15+
index 26f73ff..b083802 100644
16+
--- a/node_modules/left-pad/index.js
17+
+++ b/node_modules/left-pad/index.js
18+
@@ -22,9 +22,9 @@ var cache = [
19+
function leftPad (str, len, ch) {
20+
// convert \`str\` to \`string\`
21+
str = str + '';
22+
- // \`len\` is the \`pad\`'s length now
23+
+ // \`len\` is the \`yarn\`'s length now
24+
len = len - str.length;
25+
- // doesn't need to pad
26+
+ // doesn't need to yarn
27+
if (len <= 0) return str;
28+
// \`ch\` defaults to \`' '\`
29+
if (!ch && ch !== 0) ch = ' ';
30+
@@ -32,12 +32,12 @@ function leftPad (str, len, ch) {
31+
ch = ch + '';
32+
// cache common use cases
33+
if (ch === ' ' && len < 10) return cache[len] + str;
34+
- // \`pad\` starts with an empty string
35+
- var pad = '';
36+
+ // \`yarn\` starts with an empty string
37+
+ var yarn = '';
38+
// loop
39+
while (true) {
40+
- // add \`ch\` to \`pad\` if \`len\` is odd
41+
- if (len & 1) pad += ch;
42+
+ // add \`ch\` to \`yarn\` if \`len\` is odd
43+
+ if (len & 1) yarn += ch;
44+
// divide \`len\` by 2, ditch the remainder
45+
len >>= 1;
46+
// \\"double\\" the \`ch\` so this operation count grows logarithmically on \`len\`
47+
@@ -47,6 +47,6 @@ function leftPad (str, len, ch) {
48+
// \`len\` is 0, exit the loop
49+
else break;
50+
}
51+
- // pad \`str\`!
52+
- return pad + str;
53+
+ // yarn \`str\`!
54+
+ return yarn + str;
55+
}
56+
END SNAPSHOT"
57+
`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("fs").writeFileSync(
2+
"./package.json",
3+
JSON.stringify({
4+
...require("./package.json"),
5+
scripts: {
6+
postinstall: "patch-package",
7+
},
8+
}),
9+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
yarn add $1
6+
7+
echo "Add left-pad"
8+
yarn add left-pad@1.1.3
9+
10+
echo "replace pad with yarn in left-pad/index.js"
11+
replace pad yarn node_modules/left-pad/index.js
12+
13+
echo "SNAPSHOT: making patch"
14+
patch-package left-pad
15+
echo "END SNAPSHOT"
16+
17+
echo "SNAPSHOT: the patch looks like this"
18+
cat patches/left-pad+1.1.3.patch
19+
echo "END SNAPSHOT"
20+
21+
echo "reinstall node_modules"
22+
rimraf node_modules
23+
yarn
24+
25+
echo "patch-package didn't run"
26+
if grep yarn node_modules/left-pad/index.js ; then
27+
exit 1
28+
fi
29+
30+
echo "add patch-package to postinstall hook"
31+
node ./add-postinstall.js
32+
33+
echo "reinstall node_modules"
34+
rimraf node_modules
35+
yarn
36+
37+
echo "patch-package did run"
38+
grep yarn node_modules/left-pad/index.js
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("happy-path-yarn")

0 commit comments

Comments
 (0)