Skip to content

Commit

Permalink
chore(tests): setup package manager consistently for example/integrat…
Browse files Browse the repository at this point in the history
…ion tests (#6681)
  • Loading branch information
mehulkar committed Dec 3, 2023
1 parent 79bdf77 commit 61ea2be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
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 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

0 comments on commit 61ea2be

Please sign in to comment.