Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): setup package manager consistently for example/integration tests #6681

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 7 additions & 21 deletions turborepo-tests/helpers/examples_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ set -eo pipefail

exampleName=$1
pkgManager=$2
pkgManagerWithVersion=$3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this $3 but not seeing it used anywhere? Won't block on it but in case you want to axe it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s passed into setup_package_manager script on line 38!


# Copy the example dir over to the test dir that prysk puts you in
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
MONOREPO_ROOT_DIR="$SCRIPT_DIR/../.."
TURBOREPO_TESTS_DIR="$SCRIPT_DIR/.."
EXAMPLE_DIR="$MONOREPO_ROOT_DIR/examples/$exampleName"

TARGET_DIR="$(pwd)"
Expand All @@ -30,19 +32,10 @@ if [ "$TURBO_TAG" == "canary" ]; then
mv package.json.new package.json
fi

# Update package manager
if [ "$3" != "" ]; then
# Use jq to write a new file with a .packageManager field set and then
# overwrite original package.json.
jq --arg pm "$3" '.packageManager = $pm' "$TARGET_DIR/package.json" > "$TARGET_DIR/package.json.new"
mv "$TARGET_DIR/package.json.new" "$TARGET_DIR/package.json"

# We just created a new file. On Windows, we need to convert it to Unix line endings
# so the hashes will be stable with what's expected in our test cases.
if [[ "$OSTYPE" == "msys" ]]; then
dos2unix --quiet "$TARGET_DIR/package.json"
fi
fi
# Delete .git directory if it's there, we'll set up a new git repo
[ ! -d .git ] || rm -rf .git
"${TURBOREPO_TESTS_DIR}/helpers/setup_git.sh" "${TARGET_DIR}"
"${TURBOREPO_TESTS_DIR}/helpers/setup_package_manager.sh" "${TARGET_DIR}" "$pkgManagerWithVersion"

# Enable corepack so that when we set the packageManager in package.json it actually makes a diference.
if [ "$PRYSK_TEMP" == "" ]; then
Expand All @@ -54,18 +47,11 @@ else
COREPACK_INSTALL_DIR_CMD="--install-directory=${COREPACK_INSTALL_DIR}"
fi
corepack enable "${COREPACK_INSTALL_DIR_CMD}"

# Delete .git directory if it's there, we'll set up a new git repo
[ ! -d .git ] || rm -rf .git
"${TURBOREPO_TESTS_DIR}/helpers/install_deps.sh" "$pkgManager"

if [ "${OSTYPE}" == "msys" ]; then
EXT=".exe"
else
EXT=""
fi
export TURBO_BINARY_PATH=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}

"$MONOREPO_ROOT_DIR/turborepo-tests/helpers/setup_git.sh" "${TARGET_DIR}"

# Install dependencies after git is setup
"${SCRIPT_DIR}/install_deps.sh" "$pkgManager"
18 changes: 1 addition & 17 deletions turborepo-tests/helpers/setup_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,7 @@ TURBOREPO_INTEGRATION_TESTS_DIR="${TURBOREPO_TESTS_DIR}/integration/tests"
cp -a "${TURBOREPO_INTEGRATION_TESTS_DIR}/$FIXTURE/." "${TARGET_DIR}/"

"${TURBOREPO_TESTS_DIR}/helpers/setup_git.sh" ${TARGET_DIR}

# Update package manager if one was provided
if [ "$PACKAGE_MANAGER" != "" ]; then
# Use jq to write a new file with a .packageManager field set and then
# Overwrite original package.json. For some reason the command above won't send its output
# directly to the original file.
jq --arg pm "$PACKAGE_MANAGER" '.packageManager = $pm' "$TARGET_DIR/package.json" > "$TARGET_DIR/package.json.new"
mv "$TARGET_DIR/package.json.new" "$TARGET_DIR/package.json"

# We just created a new file. On Windows, we need to convert it to Unix line endings
# so the hashes will be stable with what's expected in our test cases.
if [[ "$OSTYPE" == "msys" ]]; then
dos2unix --quiet "$TARGET_DIR/package.json"
fi

git commit -am "Updated package manager to $PACKAGE_MANAGER" --quiet
fi
"${TURBOREPO_TESTS_DIR}/helpers/setup_package_manager.sh" ${TARGET_DIR} "$PACKAGE_MANAGER"

# Install dependencies with the given package manager
PACKAGE_MANAGER_NAME="npm"
Expand Down
21 changes: 21 additions & 0 deletions turborepo-tests/helpers/setup_package_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

dir=$1
pkgManager=$2

# Update package manager if one was provided
if [ "$pkgManager" != "" ]; then
# Use jq to write a new file with a .packageManager field set and then
# Overwrite original package.json. For some reason the command above won't send its output
# directly to the original file.
jq --arg pm "$pkgManager" '.packageManager = $pm' "$dir/package.json" > "$dir/package.json.new"
mv "$dir/package.json.new" "$dir/package.json"

# We just created a new file. On Windows, we need to convert it to Unix line endings
# so the hashes will be stable with what's expected in our test cases.
if [[ "$OSTYPE" == "msys" ]]; then
dos2unix --quiet "$dir/package.json"
fi

git commit -am "Updated package manager to $pkgManager" --quiet
fi