Skip to content

Commit 6f6c81f

Browse files
committed
add integration test for patch-parse-failure
1 parent 48c419f commit 6f6c81f

29 files changed

+150
-26
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
22

3-
runIntegrationTest("adding-and-deleting-files", false)
3+
runIntegrationTest({
4+
projectName: "adding-and-deleting-files",
5+
shouldProduceSnapshots: false,
6+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("broken-patch-file", true)
2+
runIntegrationTest({
3+
projectName: "broken-patch-file",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("custom-patch-dir", false)
2+
runIntegrationTest({
3+
projectName: "custom-patch-dir",
4+
shouldProduceSnapshots: false,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("custom-resolutions", false)
2+
runIntegrationTest({
3+
projectName: "custom-resolutions",
4+
shouldProduceSnapshots: false,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("delete-old-patch-files", false)
2+
runIntegrationTest({
3+
projectName: "delete-old-patch-files",
4+
shouldProduceSnapshots: false,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
22

3-
runIntegrationTest("delete-scripts")
3+
runIntegrationTest({
4+
projectName: "delete-scripts",
5+
shouldProduceSnapshots: true,
6+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("file-mode-changes", true)
2+
runIntegrationTest({
3+
projectName: "file-mode-changes",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("happy-path-npm")
2+
runIntegrationTest({
3+
projectName: "happy-path-npm",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("happy-path-yarn")
2+
runIntegrationTest({
3+
projectName: "happy-path-yarn",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
22

3-
runIntegrationTest("ignore-whitespace")
3+
runIntegrationTest({
4+
projectName: "ignore-whitespace",
5+
shouldProduceSnapshots: true,
6+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
22

3-
runIntegrationTest("include-exclude-paths")
3+
runIntegrationTest({
4+
projectName: "include-exclude-paths",
5+
shouldProduceSnapshots: true,
6+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("include-exclude-regex-relativity", false)
2+
runIntegrationTest({
3+
projectName: "include-exclude-regex-relativity",
4+
shouldProduceSnapshots: false,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("nested-packages", true)
2+
runIntegrationTest({
3+
projectName: "nested-packages",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("nested-scoped-packages", true)
2+
runIntegrationTest({
3+
projectName: "nested-scoped-packages",
4+
shouldProduceSnapshots: true,
5+
})

integration-tests/newIntegrationTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ yarn add $1
4848
fs.writeFileSync(
4949
path.join(testDir, `${testName}.test.ts`),
5050
`import { runIntegrationTest } from "../runIntegrationTest"
51-
runIntegrationTest("${testName}", false)
51+
runIntegrationTest({projectName: "${testName}", shouldProduceSnapshots: false})
5252
`,
5353
)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("package-gets-updated", true)
2+
runIntegrationTest({
3+
projectName: "package-gets-updated",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Test patch-parse-failure: patch parse failure message 1`] = `
4+
"SNAPSHOT: patch parse failure message
5+
6+
**ERROR** Failed to apply patch for package left-pad
7+
8+
This happened because the patch file patches/left-pad+1.3.0.patch could not be parsed.
9+
10+
If you just upgraded patch-package, you can try running:
11+
12+
patch -p1 -i patches/left-pad+1.3.0.patch
13+
npx patch-package left-pad
14+
15+
Otherwise, try manually creating the patch file again.
16+
17+
If the problem persists, please submit a bug report:
18+
19+
https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E
20+
21+
22+
error Command failed with exit code 1.
23+
END SNAPSHOT"
24+
`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "patch-parse-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+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
yarn add $1
6+
7+
(>&2 echo "SNAPSHOT: patch parse failure message")
8+
if yarn patch-package; then
9+
exit 1
10+
fi
11+
(>&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: "patch-parse-failure",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/node_modules/left-pad/index.js b/node_modules/left-pad/index.js
2+
index e90aec3..bfca6c5 100644
3+
--- a/node_modules/left-pad/index.js
4+
+++ b/node_modules/left-pad/index.js
5+
@@ -33,7 +33,6 @@ function leftPad (str, len, ch) {
6+
// cache common use cases
7+
if (ch === ' ' && len < 10) return cache[len] + str;
8+
// `pad` starts with an empty string
9+
- var pad = '';
10+
while (true) {
11+
// add `ch` to `pad` if `len` is odd
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.3.0:
6+
version "1.3.0"
7+
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
8+
integrity sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
22

3-
runIntegrationTest("reverse-option", false)
3+
runIntegrationTest({
4+
projectName: "reverse-option",
5+
shouldProduceSnapshots: false,
6+
})

integration-tests/runIntegrationTest.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ export const patchPackageTarballPath = resolve(
1010
.filter(nm => nm.match(/^patch-package\.test\.\d+\.tgz$/))[0],
1111
)
1212

13-
export function runIntegrationTest(
14-
projectName: string,
15-
shouldProduceSnapshots: boolean = true,
16-
) {
13+
export function runIntegrationTest({
14+
projectName,
15+
shouldProduceSnapshots,
16+
}: {
17+
projectName: string
18+
shouldProduceSnapshots: boolean
19+
}) {
1720
describe(`Test ${projectName}:`, () => {
1821
const tmpDir = tmp.dirSync({ unsafeCleanup: true })
1922
fs.copySync(join(__dirname, projectName), tmpDir.name, {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("scoped-package")
2+
runIntegrationTest({
3+
projectName: "scoped-package",
4+
shouldProduceSnapshots: true,
5+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import { runIntegrationTest } from "../runIntegrationTest"
2-
runIntegrationTest("shrinkwrap", true)
2+
runIntegrationTest({ projectName: "shrinkwrap", shouldProduceSnapshots: true })

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build": "tsc --project tsconfig.build.json",
1919
"new-integration-test": "ts-node integration-tests/newIntegrationTest.ts",
2020
"clean": "rimraf dist patch-package.test*.tgz",
21-
"format": "prettier --no-semi --write --trailing-comma=all src{/**,}/*.ts",
21+
"format": "prettier --no-semi --write --trailing-comma=all src{/**,}/*.ts integration-tests{/**,}/*.ts property-based-tests{/**,}/*.ts",
2222
"prepack": "rimraf dist/**/*.test.js",
2323
"test": "./run-tests.sh --runInBand"
2424
},

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["./property-based-tests"]
3+
"exclude": ["./property-based-tests", "./integration-tests"]
44
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"noEmitOnError": false,
1313
"inlineSources": true
1414
},
15-
"include": ["typings/**/*.d.ts", "src/**/*.ts", "property-based-tests/**/*"],
15+
"include": ["typings/**/*.d.ts", "src/**/*.ts", "property-based-tests/**/*", "integration-tests/**/*"],
1616
"compileOnSave": true
1717
}

0 commit comments

Comments
 (0)