Skip to content

Commit

Permalink
chore(tests): cleanup setup scripts (#6700)
Browse files Browse the repository at this point in the history
This commit makes various changes to the test setup scripts to
make examples and integration test setup as similar as possible.
  • Loading branch information
mehulkar committed Dec 6, 2023
1 parent 2c2d578 commit d8c9ab2
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion turborepo-tests/example-npm-non-monorepo/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh non-monorepo npm
$ . ${TESTDIR}/../helpers/setup_example_test.sh non-monorepo npm@8.19.4

# run twice and make sure it works
$ npx turbo build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-npm-with-npm/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh with-npm npm
$ . ${TESTDIR}/../helpers/setup_example_test.sh with-npm npm@8.19.4

# run twice and make sure it works
$ npm run build lint -- --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-pnpm-basic/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh basic pnpm
$ . ${TESTDIR}/../helpers/setup_example_test.sh basic pnpm@8.9.0

# run twice and make sure it works
$ pnpm run build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-pnpm-gatsby/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh with-gatsby pnpm
$ . ${TESTDIR}/../helpers/setup_example_test.sh with-gatsby pnpm@8.9.0

# run twice and make sure it works
$ pnpm run build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-pnpm-kitchen-sink/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh kitchen-sink pnpm
$ . ${TESTDIR}/../helpers/setup_example_test.sh kitchen-sink pnpm@8.9.0

# run twice and make sure it works
$ pnpm run build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-pnpm-with-svelte/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh with-svelte pnpm
$ . ${TESTDIR}/../helpers/setup_example_test.sh with-svelte pnpm@8.9.0

# run twice and make sure it works
$ pnpm run build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-yarn-non-monorepo/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh non-monorepo yarn yarn@1.22.19
$ . ${TESTDIR}/../helpers/setup_example_test.sh non-monorepo yarn@1.22.19

# run twice and make sure it works
$ yarn turbo build lint --output-logs=errors-only
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/example-yarn-with-yarn/test.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/../helpers/examples_setup.sh with-yarn yarn
$ . ${TESTDIR}/../helpers/setup_example_test.sh with-yarn yarn@1.22.19

# run twice and make sure it works
$ yarn turbo build lint --output-logs=errors-only
Expand Down
14 changes: 7 additions & 7 deletions turborepo-tests/helpers/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
set -eo pipefail

# TODO: Should we default to pnpm here?
PACKAGE_MANAGER=${1-npm}

# If a lock file already exists, we will exit. Some fixtures already have the lock
# file. The caller is responsible for deleting this before calling this script.
# TODO: we should make the fixtures consistent in either having or not having lockfiles.
if [[ -f "package-lock.json" || -f "pnpm-lock.yaml" || -f "yarn.lock" ]]; then
exit 0
PACKAGE_MANAGER="npm"
# Check if "@" is present in the argument and remove it if so
if [[ $1 != "" && $1 == *'@'* ]]; then
PACKAGE_MANAGER=${1%%@*}
elif [[ $1 != "" ]]; then
PACKAGE_MANAGER=$1
fi


if [ "$PACKAGE_MANAGER" == "npm" ]; then
npm install > /dev/null 2>&1
if [[ "$OSTYPE" == "msys" ]]; then
Expand Down
7 changes: 2 additions & 5 deletions turborepo-tests/helpers/setup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env bash

THIS_DIR=$(dirname "${BASH_SOURCE[0]}")
ROOT_DIR="${THIS_DIR}/../.."
MONOREPO_ROOT_DIR="${THIS_DIR}/../.."

if [[ "${OSTYPE}" == "msys" ]]; then
EXT=".exe"
else
EXT=""
fi

TURBO=${ROOT_DIR}/target/debug/turbo${EXT}

VERSION=${ROOT_DIR}/version.txt
TMPDIR=$(mktemp -d)
TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash

set -eo pipefail

FIXTURE_NAME=$1
pkgManager=$2
pkgManagerWithVersion=$3
PACKAGE_MANAGER=$2 # e.g. yarn@1.22.17

THIS_DIR=$(dirname "${BASH_SOURCE[0]}")
MONOREPO_ROOT_DIR="$THIS_DIR/../.."
Expand All @@ -13,17 +12,9 @@ TURBOREPO_TESTS_DIR="${MONOREPO_ROOT_DIR}/turborepo-tests"
TARGET_DIR="$(pwd)"

"${TURBOREPO_TESTS_DIR}/helpers/copy_fixture.sh" "${TARGET_DIR}" "${FIXTURE_NAME}" "${MONOREPO_ROOT_DIR}/examples"

# cleanup lockfiles so we can install from scratch
[ ! -f yarn.lock ] || mv yarn.lock yarn.lock.bak
[ ! -f pnpm-lock.yaml ] || mv pnpm-lock.yaml pnpm-lock.yaml.bak
[ ! -f package-lock.json ] || mv package-lock.json package-lock.json.bak

# 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"
"${TURBOREPO_TESTS_DIR}/helpers/install_deps.sh" "$pkgManager"
"${TURBOREPO_TESTS_DIR}/helpers/setup_package_manager.sh" "${TARGET_DIR}" "$PACKAGE_MANAGER"
"${TURBOREPO_TESTS_DIR}/helpers/install_deps.sh" "$PACKAGE_MANAGER"

# Set the TURBO_BINARY_PATH env var. The examples themselves invoke the locally installed turbo,
# but turbo has an internal feature that will look for this environment variable and use it if it's set.
Expand All @@ -35,3 +26,10 @@ else
EXT=""
fi
export TURBO_BINARY_PATH=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}

# Undo the set -eo pipefail at the top of this script
# This script is called with a leading ".", which means that it does not run
# in a new child process, so the set -eo pipefail would affect the calling script.
# Some of our tests actually assert non-zero exit codes, and we don't want to
# abort the test in those cases. So we undo the set -eo pipefail here.
set +eo pipefail
28 changes: 13 additions & 15 deletions turborepo-tests/helpers/setup_integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
#!/usr/bin/env bash

set -eo pipefail

FIXTURE_NAME="${1-basic_monorepo}"
PACKAGE_MANAGER="$2"

# TOOD: what is this for?
TMPDIR=$(mktemp -d)

THIS_DIR=$(dirname "${BASH_SOURCE[0]}")
MONOREPO_ROOT_DIR="$THIS_DIR/../.."
TURBOREPO_TESTS_DIR="${MONOREPO_ROOT_DIR}/turborepo-tests"

TARGET_DIR="$(pwd)"

"${TURBOREPO_TESTS_DIR}/helpers/copy_fixture.sh" "${TARGET_DIR}" "${FIXTURE_NAME}" "${TURBOREPO_TESTS_DIR}/integration/fixtures"
"${TURBOREPO_TESTS_DIR}/helpers/setup_git.sh" ${TARGET_DIR}
"${TURBOREPO_TESTS_DIR}/helpers/setup_package_manager.sh" ${TARGET_DIR} "$PACKAGE_MANAGER"

# Install dependencies with the given package manager
PACKAGE_MANAGER_NAME="npm"
if [ "$PACKAGE_MANAGER" != "" ]; then
PACKAGE_MANAGER_NAME=$(echo "$PACKAGE_MANAGER" | sed 's/@.*//')
fi

"${TURBOREPO_TESTS_DIR}/helpers/install_deps.sh" "$PACKAGE_MANAGER_NAME"
"${TURBOREPO_TESTS_DIR}/helpers/setup_git.sh" "${TARGET_DIR}"
"${TURBOREPO_TESTS_DIR}/helpers/setup_package_manager.sh" "${TARGET_DIR}" "$PACKAGE_MANAGER"
"${TURBOREPO_TESTS_DIR}/helpers/install_deps.sh" "$PACKAGE_MANAGER"

# Set TURBO env var, it is used by tests to run the binary
if [[ "${OSTYPE}" == "msys" ]]; then
Expand All @@ -31,5 +23,11 @@ else
EXT=""
fi

TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}
VERSION=${MONOREPO_ROOT_DIR}/version.txt
export TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}

# Undo the set -eo pipefail at the top of this script
# This script is called with a leading ".", which means that it does not run
# in a new child process, so the set -eo pipefail would affect the calling script.
# Some of our tests actually assert non-zero exit codes, and we don't want to
# abort the test in those cases. So we undo the set -eo pipefail here.
set +eo pipefail
4 changes: 3 additions & 1 deletion turborepo-tests/helpers/setup_package_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ if [ "$pkgManager" != "" ]; then
dos2unix --quiet "$dir/package.json"
fi

git commit -am "Updated package manager to $pkgManager" --quiet
if [[ $(git status --porcelain) ]]; then
git commit -am "Updated package manager to $pkgManager" --quiet
fi
fi

# If we're in a prysk test, set the corepack install directory to the prysk temp directory.
Expand Down
1 change: 1 addition & 0 deletions turborepo-tests/integration/tests/command-version.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Setup
$ . ${TESTDIR}/../../helpers/setup.sh
$ VERSION=${MONOREPO_ROOT_DIR}/version.txt

Test version matches that of version.txt
$ diff --strip-trailing-cr <(head -n 1 ${VERSION}) <(${TURBO} --version)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep pnpm@7.25.1

Make sure that the internal util package is part of the prune output
$ ${TURBO} prune docs
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/integration/tests/prune/docker.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep pnpm@7.25.1

$ ${TURBO} prune web --docker
Generating pruned monorepo for web in .*out (re)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep pnpm@7.25.1

Make sure that the internal util package is part of the prune output
$ ${TURBO} prune web
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/integration/tests/prune/out-dir.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep pnpm@7.25.1

Test that absolute paths can be passed as out-dir
$ TMPFILE=$(mktemp -d)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh monorepo_with_root_dep pnpm@7.25.1

Make sure that the internal util package is part of the prune output
$ ${TURBO} prune docs
Expand Down

0 comments on commit d8c9ab2

Please sign in to comment.