Skip to content

Commit 389ae60

Browse files
authored
feat(nextjs): Add ability for integration tests to use linked @sentry/xxxx packages (getsentry#4019)
In the nextjs integration tests, we use file dependencies for all of the packages in the `sentry-javascript` repo, so that the tests test the local (rather than published) version of the SDK. We don't do the same for `@sentry/cli` or `@sentry/webpack-plugin`, though, because they're in a separate repo and we can't predict where the local copy of that repo lives. As a result, we currently can't (in the nextjs integration tests, at least) test any local changes in either package. This solves that problem by optionally linking to the local copies of those repos as part of the integration test runner script. In order to use this optional linking: - To link `@sentry/cli`, set `LINKED_CLI_REPO=<abs path of local sentry-cli repo>`. - To link `@sentry/webpack-plugin`, set the CLI variable above (since `@sentry/cli` is a dependency of `@sentry/webpack-plugin`, we need to link it in the plugin repo also) as well as `LINKED_PLUGIN_REPO=<abs path of local sentry-webpack-plugin repo>`
1 parent feb2bb5 commit 389ae60

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function link_package() {
2+
local package_abs_path=$1
3+
local package_name=$2
4+
5+
echo "Setting up @sentry/${package_name} for linking"
6+
pushd $package_abs_path
7+
yarn link
8+
popd
9+
10+
echo "Linking @sentry/$package_name"
11+
yarn link "@sentry/$package_name"
12+
13+
}
14+
15+
# Note: LINKED_CLI_REPO and LINKED_PLUGIN_REPO in the functions below should be set to the absolute path of each local repo
16+
17+
function linkcli() {
18+
if [[ ! $LINKED_CLI_REPO ]]; then
19+
return
20+
fi
21+
22+
# check to make sure the repo directory exists
23+
if [[ -d $LINKED_CLI_REPO ]]; then
24+
link_package $LINKED_CLI_REPO "cli"
25+
else
26+
# the $1 lets us insert a string in that spot if one is passed to `linkcli` (useful for when we're calling this from
27+
# within another linking function)
28+
echo "ERROR: Can't link @sentry/cli $1because directory $LINKED_CLI_REPO does not exist."
29+
fi
30+
}
31+
32+
function linkplugin() {
33+
if [[ ! $LINKED_PLUGIN_REPO ]]; then
34+
return
35+
fi
36+
37+
# check to make sure the repo directory exists
38+
if [[ -d $LINKED_PLUGIN_REPO ]]; then
39+
link_package $LINKED_PLUGIN_REPO "webpack-plugin"
40+
41+
# the webpack plugin depends on `@sentry/cli`, so if we're also using a linked version of the cli package, the
42+
# plugin needs to link to it, too
43+
if [[ $LINKED_CLI_REPO ]]; then
44+
pushd $LINKED_PLUGIN_REPO
45+
link_cli "in webpack plugin repo "
46+
popd
47+
fi
48+
else
49+
echo "ERROR: Can't link @sentry/wepack-plugin because $LINKED_PLUGIN_REPO does not exist."
50+
fi
51+
}

packages/nextjs/test/run-integration-tests.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
source test/integration_test_utils.sh
4+
35
set -e
46

57
START_TIME=$(date -R)
@@ -55,6 +57,9 @@ for NEXTJS_VERSION in 10 11; do
5557
sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
5658
fi
5759
yarn --no-lockfile --silent >/dev/null 2>&1
60+
# if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless
61+
# LINKED_CLI_REPO and/or LINKED_PLUGIN_REPO is set)
62+
linkcli && linkplugin
5863
mv -f package.json.bak package.json 2>/dev/null || true
5964

6065
for RUN_WEBPACK_5 in false true; do
@@ -72,9 +77,10 @@ for NEXTJS_VERSION in 10 11; do
7277
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
7378
yarn build | grep "Using webpack"
7479

80+
# if the user hasn't passed any args, use the default one, which restricts each test to only outputting success and
81+
# failure messages
7582
args=$*
7683
if [[ ! $args ]]; then
77-
# restrict each test to only output success and failure messages
7884
args="--silent"
7985
fi
8086

0 commit comments

Comments
 (0)