From 1a1454328b646a6e4d7500d34ad83ef56587cf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 17 Jan 2020 07:55:29 -0500 Subject: [PATCH] chore: replace yarn-upgrade by bump-babel-dependencies in e2e tests (#11021) * chore: pin yarn version in e2e vue tests * fix: replace yarn-upgrade by bump-babel-dependencies * chore: update e2e-cra test --- .../integration-tests/e2e-create-react-app.sh | 6 ++-- scripts/integration-tests/e2e-vue-cli.sh | 8 ++--- .../utils/bump-babel-dependencies.js | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 scripts/integration-tests/utils/bump-babel-dependencies.js diff --git a/scripts/integration-tests/e2e-create-react-app.sh b/scripts/integration-tests/e2e-create-react-app.sh index 1c956f240c..8be49ae899 100755 --- a/scripts/integration-tests/e2e-create-react-app.sh +++ b/scripts/integration-tests/e2e-create-react-app.sh @@ -23,9 +23,9 @@ cd tmp/create-react-app || exit startLocalRegistry "$PWD"/../../verdaccio-config.yml yarn install -# "yarn upgrade --scope @babel --latest" doesn't seem to work. -# a means "all", while \n is the enter needed to confirm the selection. -printf "a\n" | yarn upgrade-interactive --scope @babel --latest +node "$PWD"/../../utils/bump-babel-dependencies.js +yarn lerna exec -- node "$PWD"/../../utils/bump-babel-dependencies.js +yarn install # Test CI=true yarn test diff --git a/scripts/integration-tests/e2e-vue-cli.sh b/scripts/integration-tests/e2e-vue-cli.sh index 018f7fb132..b43ed96db9 100755 --- a/scripts/integration-tests/e2e-vue-cli.sh +++ b/scripts/integration-tests/e2e-vue-cli.sh @@ -23,11 +23,9 @@ cd tmp/vue-cli || exit startLocalRegistry "$PWD"/../../verdaccio-config.yml yarn install -# Workaround https://github.com/yarnpkg/yarn/issues/7797 -yarn add --dev -W @babel/core -# "yarn upgrade --scope @babel --latest" doesn't seem to work. -# a means "all", while \n is the enter needed to confirm the selection. -printf "a\n" | yarn upgrade-interactive --scope @babel --latest +node "$PWD"/../../utils/bump-babel-dependencies.js +yarn lerna exec -- node "$PWD"/../../utils/bump-babel-dependencies.js +yarn install # Test CI=true yarn test -p babel,babel-preset-app diff --git a/scripts/integration-tests/utils/bump-babel-dependencies.js b/scripts/integration-tests/utils/bump-babel-dependencies.js new file mode 100644 index 0000000000..03863f5888 --- /dev/null +++ b/scripts/integration-tests/utils/bump-babel-dependencies.js @@ -0,0 +1,29 @@ +const fs = require("fs"); +const path = require("path"); +const cwd = process.cwd(); +const packageJSONPath = path.resolve(cwd, "./package.json"); +const content = JSON.parse(fs.readFileSync(packageJSONPath)); + +let bumped = false; +function bumpBabelDependency(dependencies) { + for (const dep of Object.keys(dependencies)) { + if (dep.startsWith("@babel/")) { + dependencies[dep] = "latest"; + bumped = true; + } + } +} + +if ("peerDependencies" in content) { + bumpBabelDependency(content.peerDependencies); +} +if ("devDependencies" in content) { + bumpBabelDependency(content.devDependencies); +} +if ("dependencies" in content) { + bumpBabelDependency(content.dependencies); +} + +if (bumped) { + fs.writeFileSync(packageJSONPath, JSON.stringify(content, undefined, 2)); +}