From 30d9e45e72e8ac552f70aab1c2714cc56a67fd3b Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 10 Nov 2021 20:24:48 -0800 Subject: [PATCH 1/6] derive package name from abs path of directory when linking packages --- packages/nextjs/test/integration_test_utils.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/test/integration_test_utils.sh b/packages/nextjs/test/integration_test_utils.sh index 48d76685f234..1c893d0ab3e5 100644 --- a/packages/nextjs/test/integration_test_utils.sh +++ b/packages/nextjs/test/integration_test_utils.sh @@ -1,6 +1,7 @@ function link_package() { local package_abs_path=$1 - local package_name=$2 + # strip the 'sentry-' prefix from the repo name of packages not in the monorepo (`cli`, `webpack-plugin`, and `wizard`) + local package_name=$(basename $package_abs_path | sed s/sentry-//) echo "Setting up @sentry/${package_name} for linking" pushd $package_abs_path @@ -21,7 +22,7 @@ function linkcli() { # check to make sure the repo directory exists if [[ -d $LINKED_CLI_REPO ]]; then - link_package $LINKED_CLI_REPO "cli" + link_package $LINKED_CLI_REPO 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) @@ -36,7 +37,7 @@ function linkplugin() { # check to make sure the repo directory exists if [[ -d $LINKED_PLUGIN_REPO ]]; then - link_package $LINKED_PLUGIN_REPO "webpack-plugin" + link_package $LINKED_PLUGIN_REPO # 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 From 4c0373527a3f0c906e0cb0eb6507116104ead414 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 10 Nov 2021 20:25:31 -0800 Subject: [PATCH 2/6] add function to link monorepo packages into test project for debugging --- .../nextjs/test/integration_test_utils.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/nextjs/test/integration_test_utils.sh b/packages/nextjs/test/integration_test_utils.sh index 1c893d0ab3e5..c067ab9c227d 100644 --- a/packages/nextjs/test/integration_test_utils.sh +++ b/packages/nextjs/test/integration_test_utils.sh @@ -50,3 +50,30 @@ function linkplugin() { echo "ERROR: Can't link @sentry/wepack-plugin because $LINKED_PLUGIN_REPO does not exist." fi } + +# This is only really useful for running tests in the debugger, as the normal test runner reinstalls all SDK packages +# from the local files on each test run +function link_monorepo_packages() { + local repo_packages_dir=$1 + + for abs_package_path in ${repo_packages_dir}/*; do + local package_name=$(basename $abs_package_path) + + # Skip packages under the `@sentry-internal` namespace (our function is only linking packages in the `@sentry` + # namespace, and besides, there's no reason to link such packages, as they're purely SDK dev dependencies). + # + # (The regex test ( `=~` ) is a sneaky way of testing if `package_name` is any of the three packages listed: if the + # string containing all of the packages containes a match to the regex solely consisting of the current package + # name, the current package must be in the list.) + if [[ "eslint-config-sdk eslint-plugin-sdk typescript" =~ $package_name ]]; then + continue + fi + + # `-L` tests if the given file is a symbolic link, to see if linking has already been done + if [[ ! -L node_modules/@sentry/$package_name ]]; then + echo "Linking @sentry/$package_name" + link_package $abs_package_path >/dev/null 2>&1 + fi + + done +} From 82c239fdc60ae37d0cf64c54271bf55654edf1e5 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 9 Nov 2021 23:26:08 -0800 Subject: [PATCH 3/6] clean up debugger config and add prelaunch task --- .vscode/launch.json | 35 ++++++++++++++----- .vscode/tasks.json | 13 +++++++ packages/nextjs/test/integration/package.json | 1 + 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index a0a7d18de2e2..f1e4a2249a26 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -51,17 +51,17 @@ // @sentry/nextjs - Run a specific integration test file - // Must have file in currently active tab when hitting the play button + // Must have test file in currently active tab when hitting the play button, and must already have run `yarn` in test app directory { "name": "Debug @sentry/nextjs integration tests - just open file", "type": "node", "cwd": "${workspaceFolder}/packages/nextjs", "request": "launch", - // TODO create a build task - // "preLaunchTask": "yarn build", - - // this is going straight to `server.js` (rather than running the tests through yarn) in order to be able to skip - // having to reinstall dependencies on every new test run + // since we're not using the normal test runner, we need to make sure we're using the current version of all local + // SDK packages and then manually rebuild the test app + "preLaunchTask": "Prepare nextjs integration test app for debugging", + // running `server.js` directly (rather than running the tests through yarn) allows us to skip having to reinstall + // dependencies on every new test run "program": "${workspaceFolder}/packages/nextjs/test/integration/test/server.js", "args": [ "--debug", @@ -69,10 +69,29 @@ "--filter", "${fileBasename}" ], - "sourceMaps": true, + "skipFiles": [ - "/**", "**/tslib/**" + "/**", + // this prevents us from landing in a neverending cycle of TS async-polyfill functions as we're stepping through + // our code + "${workspaceFolder}/node_modules/tslib/**/*" ], + "sourceMaps": true, + // this controls which files are sourcemapped + "outFiles": [ + // our SDK code + "${workspaceFolder}/**/dist/**/*.js", + // the built test app + "${workspaceFolder}/packages/nextjs/test/integration/.next/**/*.js", + "!**/node_modules/**" + ], + "resolveSourceMapLocations": [ + "${workspaceFolder}/**/dist/**", + "${workspaceFolder}/packages/nextjs/test/integration/.next/**", + "!**/node_modules/**" + ], + "internalConsoleOptions": "openOnSessionStart" + }, ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000000..6e797a064c61 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 for documentation about `tasks.json` syntax + "version": "2.0.0", + "tasks": [ + { + "label": "Prepare nextjs integration test app for VSCode debugger", + "type": "npm", + "script": "predebug", + "path": "packages/nextjs/test/integration/", + "detail": "Link the SDK (if not already linked) and build test app" + } + ] +} diff --git a/packages/nextjs/test/integration/package.json b/packages/nextjs/test/integration/package.json index cd117b39ec31..5523ee933d20 100644 --- a/packages/nextjs/test/integration/package.json +++ b/packages/nextjs/test/integration/package.json @@ -4,6 +4,7 @@ "scripts": { "dev": "next", "build": "next build", + "predebug": "source ../integration_test_utils.sh && link_monorepo_packages '../../..' && yarn build", "start": "next start" }, "dependencies": { From b244d4a7afd5629702e1d3fc1acdd44869ec20e4 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 10 Nov 2021 20:22:11 -0800 Subject: [PATCH 4/6] add comments re: outgoing requests for testing span creation --- packages/nextjs/test/integration/pages/api/http/index.ts | 2 ++ packages/nextjs/test/integration/pages/fetch.tsx | 1 + packages/nextjs/test/integration/test/server/tracingHttp.js | 1 + 3 files changed, 4 insertions(+) diff --git a/packages/nextjs/test/integration/pages/api/http/index.ts b/packages/nextjs/test/integration/pages/api/http/index.ts index 5804f79bb085..958dc09ad6f6 100644 --- a/packages/nextjs/test/integration/pages/api/http/index.ts +++ b/packages/nextjs/test/integration/pages/api/http/index.ts @@ -3,7 +3,9 @@ import { get } from 'http'; import { NextApiRequest, NextApiResponse } from 'next'; const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + // make an outgoing request in order to test that the `Http` integration creates a span await new Promise(resolve => get('http://example.com', resolve)); + res.status(200).json({}); }; diff --git a/packages/nextjs/test/integration/pages/fetch.tsx b/packages/nextjs/test/integration/pages/fetch.tsx index 44e0a4ceb68d..1b538c936494 100644 --- a/packages/nextjs/test/integration/pages/fetch.tsx +++ b/packages/nextjs/test/integration/pages/fetch.tsx @@ -1,6 +1,7 @@ const ButtonPage = (): JSX.Element => (