blob: 306b2f7e8a0d0deb5e6cd4c990498c22cc269f3b [file] [log] [blame]
#!/usr/bin/env bash
set -u -e -o pipefail
TESTS_ROOT_DIR=$(cd $(dirname "$0"); pwd)
TYPESCRIPT_ROOT_DIR=$(cd $TESTS_ROOT_DIR/../../..; pwd)
KARMA_ROOT_DIR=$(cd $TESTS_ROOT_DIR/../../../internal/karma; pwd)
echo ""
echo "#################################################################################"
echo "Running all npm package e2e tests under $TESTS_ROOT_DIR"
echo ""
echo "To run a specific test run this script with '--test <test_name>' where <test_name>"
echo "is the name of the test folder to run"
echo ""
echo "Run this script with '--update-lock-files' to update yarn.lock files instead of running tests"
echo ""
# Generate the npm packages @bazel/typescript and @bazel/karma npm packages and
# determine their absolute paths in bazel-bin
cd $TYPESCRIPT_ROOT_DIR
BAZEL=$(pwd)/node_modules/.bin/bazel
if [[ ! -f $BAZEL ]] ; then
echo "Bazel not found under $BAZEL"
exit 1
fi
$BAZEL build //:npm_package
BAZEL_BIN_TYPESCRIPT=$($BAZEL info bazel-bin)
BAZEL_TYPESCRIPT_NPM_PACKAGE=$BAZEL_BIN_TYPESCRIPT/npm_package
cd $KARMA_ROOT_DIR
$BAZEL build //:npm_package
BAZEL_BIN_KARMA=$($BAZEL info bazel-bin)
BAZEL_KARMA_NPM_PACKAGE=$BAZEL_BIN_KARMA/npm_package
echo "@bazel/typescript: $BAZEL_TYPESCRIPT_NPM_PACKAGE"
echo "@bazel/karma: $BAZEL_KARMA_NPM_PACKAGE"
# Now run all e2e tests
cd $TESTS_ROOT_DIR
for testDir in $(ls) ; do
[[ -d "$testDir" ]] || continue
(
cd $testDir
echo ""
echo "#################################################################################"
echo "Running npm package e2e test $(pwd)"
echo ""
if [[ ! -f "package-template.json" ]] ; then
echo "No package-template.json file found in $testDir"
exit 1
fi
# Generate package.json subsituting variables
# BAZEL_TYPESCRIPT_NPM_PACKAGE and BAZEL_KARMA_NPM_PACKAGE
ESCAPED_TYPESCRIPT=$(echo $BAZEL_TYPESCRIPT_NPM_PACKAGE | sed 's/\//\\\//g')
ESCAPED_KARMA=$(echo $BAZEL_KARMA_NPM_PACKAGE | sed 's/\//\\\//g')
sed -e "s/\${BAZEL_TYPESCRIPT_NPM_PACKAGE}/$ESCAPED_TYPESCRIPT/" -e "s/\${BAZEL_KARMA_NPM_PACKAGE}/$ESCAPED_KARMA/" package-template.json > package.json
if [[ $# -ge 1 && $1 = "--update-lock-files" ]] ; then
# Update yarn.lock files
echo "Running yarn install to update lock file"
yarn install
else
if [[ $# -ge 2 && $1 = "--test" && $2 != $testDir ]] ; then
# Skip this test
echo "Skipping test that was not specified in --test argument"
else
# Some tests like ts_auto_deps depend on node_modules
yarn install
# Run tests
yarn test
fi
fi
)
done