Skip to content

Commit

Permalink
add integration test for yarn workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Mar 28, 2019
1 parent 022ce3f commit 533df13
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 0 deletions.
24 changes: 24 additions & 0 deletions integration-tests/yarn-workspaces/add-postinstall-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require("fs")

function addPostinstall(packageJsonPath) {
const json = JSON.parse(fs.readFileSync(packageJsonPath))
fs.writeFileSync(
packageJsonPath,
JSON.stringify(
{
...json,
scripts: {
...json.scripts,
postinstall: "yarn patch-package",
},
},
null,
" ",
),
)
}

Array.prototype.slice
.call(process.argv, 2)
.filter(x => !x.match(/node_modules/))
.map(addPostinstall)
19 changes: 19 additions & 0 deletions integration-tests/yarn-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "yarn-workspaces",
"version": "1.0.0",
"private": true,
"description": "integration test for patch-package",
"main": "index.js",
"author": "",
"license": "ISC",
"workspaces": {
"packages": [
"packages/*"
]
},
"dependencies": {
"postinstall-postinstall": "^2.0.0",
"replace": "^1.1.0",
"rimraf": "^2.6.3"
}
}
13 changes: 13 additions & 0 deletions integration-tests/yarn-workspaces/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "a",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"patch-package": "../../node_modules/.bin/patch-package"
},
"dependencies": {
"left-pad": "^1.3.0",
"postinstall-postinstall": "^2.0.0"
}
}
13 changes: 13 additions & 0 deletions integration-tests/yarn-workspaces/packages/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "b",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"patch-package": "../../node_modules/.bin/patch-package"
},
"dependencies": {
"left-pad": "1.2.0",
"postinstall-postinstall": "^2.0.0"
}
}
51 changes: 51 additions & 0 deletions integration-tests/yarn-workspaces/yarn-workspaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# make sure errors stop the script
set -e

echo "tarball $1"
echo "add patch-package to root"
yarn add $1 --ignore-workspace-root-check

echo "set up postinstall scripts"
node ./add-postinstall-commands.js package.json packages/a/package.json packages/b/package.json

echo "modify hoisted left-pad"
npx replace leftPad patch-package node_modules/left-pad/index.js

echo "create patch file"
npx patch-package left-pad

echo "modify unhoisted left-pad"
cd packages/a
npx replace leftPad patch-package node_modules/left-pad/index.js

echo "create patch file"
npx patch-package left-pad

echo "go back to root"
cd ../../

echo "delete all node modules"
rimraf **/node_modules

echo "execute yarn from root"
yarn

echo "hoisted left-pad was patched"
grep patch-package node_modules/left-pad/index.js

echo "unhoisted left-pad was patched"
grep patch-package packages/a/node_modules/left-pad/index.js

echo "delete all node modules"
rimraf **/node_modules

echo "execute yarn from a"
cd packages/a
yarn
cd ../../

echo "hoisted left-pad was patched"
grep patch-package node_modules/left-pad/index.js

echo "unhoisted left-pad was patched"
grep patch-package packages/a/node_modules/left-pad/index.js
5 changes: 5 additions & 0 deletions integration-tests/yarn-workspaces/yarn-workspaces.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { runIntegrationTest } from "../runIntegrationTest"
runIntegrationTest({
projectName: "yarn-workspaces",
shouldProduceSnapshots: false,
})
Loading

0 comments on commit 533df13

Please sign in to comment.