From 6806d2efb49ed8060d3a4984f92934fe2d65cf15 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 29 Sep 2021 23:55:34 -0700 Subject: [PATCH 1/3] add ability for integration tests to use linked `@sentry/x` packages --- .../nextjs/test/integration_test_utils.sh | 45 +++++++++++++++++++ packages/nextjs/test/run-integration-tests.sh | 9 +++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 packages/nextjs/test/integration_test_utils.sh diff --git a/packages/nextjs/test/integration_test_utils.sh b/packages/nextjs/test/integration_test_utils.sh new file mode 100644 index 000000000000..1bfd140739e2 --- /dev/null +++ b/packages/nextjs/test/integration_test_utils.sh @@ -0,0 +1,45 @@ +function link_package() { + local package_abs_path=$1 + local package_name=$2 + local current_dir=$(pwd) + + echo "Setting up @sentry/${package_name} for linking" + cd $package_abs_path + yarn link + + cd $current_dir + echo "Linking @sentry/$package_name" + yarn link "@sentry/$package_name" + +} + +# Note: CLI_REPO and WEBPACK_PLUGIN_REPO in the functions below should be set to the absolute path of each local repo + +function linkcli() { + if [[ $LINK_CLI ]]; then + if [[ $CLI_REPO ]]; then + link_package $CLI_REPO "cli" + else + echo "Can't link @sentry/cli because CLI_REPO is not set." + fi + fi +} + +function linkplugin() { + if [[ $LINK_PLUGIN ]]; then + if [[ $WEBPACK_PLUGIN_REPO ]]; then + link_package $WEBPACK_PLUGIN_REPO "webpack-plugin" + + # the webpack plugin depends on `@sentry/cli`, so if we're using a linked version of the cli package, the plugin + # needs to link to it, too + if [[ $LINK_CLI ]]; then + local current_dir=$(pwd) + cd $WEBPACK_PLUGIN_REPO + link_package $CLI_REPO "cli" + cd $current_dir + fi + else + echo "Can't link @sentry/wepack-plugin because WEBPACK_PLUGIN_REPO is not set." + fi + fi +} diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh index e98e2602201e..f5c937b28643 100755 --- a/packages/nextjs/test/run-integration-tests.sh +++ b/packages/nextjs/test/run-integration-tests.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +source test/integration_test_utils.sh + set -e START_TIME=$(date -R) @@ -55,6 +57,10 @@ for NEXTJS_VERSION in 10 11; do sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json fi yarn --no-lockfile --silent >/dev/null 2>&1 + # if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless + # LINK_CLI, CLI_REPO, LINK_PLUGIN, and WEBPACK_PLUGIN_REPO (or just the first two if only `@sentry/cli` is being + # linked) are set) + linkcli && linkplugin mv -f package.json.bak package.json 2>/dev/null || true for RUN_WEBPACK_5 in false true; do @@ -72,9 +78,10 @@ for NEXTJS_VERSION in 10 11; do echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..." yarn build | grep "Using webpack" + # if the user hasn't passed any args, use the default one, which restricts each test to only outputting success and + # failure messages args=$* if [[ ! $args ]]; then - # restrict each test to only output success and failure messages args="--silent" fi From 694170c899f8b93d06346c3e6840df1d5bae9a9c Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 30 Sep 2021 22:19:35 -0700 Subject: [PATCH 2/3] implement code review suggestions --- packages/nextjs/test/integration_test_utils.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/test/integration_test_utils.sh b/packages/nextjs/test/integration_test_utils.sh index 1bfd140739e2..e64ddbc9ffb2 100644 --- a/packages/nextjs/test/integration_test_utils.sh +++ b/packages/nextjs/test/integration_test_utils.sh @@ -1,13 +1,12 @@ function link_package() { local package_abs_path=$1 local package_name=$2 - local current_dir=$(pwd) echo "Setting up @sentry/${package_name} for linking" - cd $package_abs_path + pushd $package_abs_path yarn link + popd - cd $current_dir echo "Linking @sentry/$package_name" yarn link "@sentry/$package_name" @@ -33,10 +32,9 @@ function linkplugin() { # the webpack plugin depends on `@sentry/cli`, so if we're using a linked version of the cli package, the plugin # needs to link to it, too if [[ $LINK_CLI ]]; then - local current_dir=$(pwd) - cd $WEBPACK_PLUGIN_REPO - link_package $CLI_REPO "cli" - cd $current_dir + pushd $WEBPACK_PLUGIN_REPO + link_cli + popd fi else echo "Can't link @sentry/wepack-plugin because WEBPACK_PLUGIN_REPO is not set." From f0a8abad6e1f78789791d8c5f6a080788d35ea78 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 30 Sep 2021 22:51:25 -0700 Subject: [PATCH 3/3] simplify linking functions --- .../nextjs/test/integration_test_utils.sh | 48 +++++++++++-------- packages/nextjs/test/run-integration-tests.sh | 3 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/packages/nextjs/test/integration_test_utils.sh b/packages/nextjs/test/integration_test_utils.sh index e64ddbc9ffb2..48d76685f234 100644 --- a/packages/nextjs/test/integration_test_utils.sh +++ b/packages/nextjs/test/integration_test_utils.sh @@ -12,32 +12,40 @@ function link_package() { } -# Note: CLI_REPO and WEBPACK_PLUGIN_REPO in the functions below should be set to the absolute path of each local repo +# Note: LINKED_CLI_REPO and LINKED_PLUGIN_REPO in the functions below should be set to the absolute path of each local repo function linkcli() { - if [[ $LINK_CLI ]]; then - if [[ $CLI_REPO ]]; then - link_package $CLI_REPO "cli" - else - echo "Can't link @sentry/cli because CLI_REPO is not set." - fi + if [[ ! $LINKED_CLI_REPO ]]; then + return + fi + + # check to make sure the repo directory exists + if [[ -d $LINKED_CLI_REPO ]]; then + link_package $LINKED_CLI_REPO "cli" + else + # the $1 lets us insert a string in that spot if one is passed to `linkcli` (useful for when we're calling this from + # within another linking function) + echo "ERROR: Can't link @sentry/cli $1because directory $LINKED_CLI_REPO does not exist." fi } function linkplugin() { - if [[ $LINK_PLUGIN ]]; then - if [[ $WEBPACK_PLUGIN_REPO ]]; then - link_package $WEBPACK_PLUGIN_REPO "webpack-plugin" - - # the webpack plugin depends on `@sentry/cli`, so if we're using a linked version of the cli package, the plugin - # needs to link to it, too - if [[ $LINK_CLI ]]; then - pushd $WEBPACK_PLUGIN_REPO - link_cli - popd - fi - else - echo "Can't link @sentry/wepack-plugin because WEBPACK_PLUGIN_REPO is not set." + if [[ ! $LINKED_PLUGIN_REPO ]]; then + return + fi + + # check to make sure the repo directory exists + if [[ -d $LINKED_PLUGIN_REPO ]]; then + link_package $LINKED_PLUGIN_REPO "webpack-plugin" + + # the webpack plugin depends on `@sentry/cli`, so if we're also using a linked version of the cli package, the + # plugin needs to link to it, too + if [[ $LINKED_CLI_REPO ]]; then + pushd $LINKED_PLUGIN_REPO + link_cli "in webpack plugin repo " + popd fi + else + echo "ERROR: Can't link @sentry/wepack-plugin because $LINKED_PLUGIN_REPO does not exist." fi } diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh index f5c937b28643..b44a617e1ed6 100755 --- a/packages/nextjs/test/run-integration-tests.sh +++ b/packages/nextjs/test/run-integration-tests.sh @@ -58,8 +58,7 @@ for NEXTJS_VERSION in 10 11; do fi yarn --no-lockfile --silent >/dev/null 2>&1 # if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless - # LINK_CLI, CLI_REPO, LINK_PLUGIN, and WEBPACK_PLUGIN_REPO (or just the first two if only `@sentry/cli` is being - # linked) are set) + # LINKED_CLI_REPO and/or LINKED_PLUGIN_REPO is set) linkcli && linkplugin mv -f package.json.bak package.json 2>/dev/null || true