From 197d9a5114ae4ec9776e81cf1507024e0206f999 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 27 May 2024 13:20:46 +0200 Subject: [PATCH] Add test for inspector import --- .../public-api/LocalVariables/deny-inspector.mjs | 13 +++++++++++++ .../suites/public-api/LocalVariables/test.ts | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 dev-packages/node-integration-tests/suites/public-api/LocalVariables/deny-inspector.mjs diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/deny-inspector.mjs b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/deny-inspector.mjs new file mode 100644 index 000000000000..99323e91f0bc --- /dev/null +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/deny-inspector.mjs @@ -0,0 +1,13 @@ +import * as Sentry from '@sentry/node'; +import Hook from 'import-in-the-middle'; + +Hook((_, name) => { + if (name === 'inspector') { + throw new Error('No inspector!'); + } + if (name === 'node:inspector') { + throw new Error('No inspector!'); + } +}); + +Sentry.init({}); diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts index 61b9fc3064a4..0ad4ddad7c5a 100644 --- a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts @@ -76,6 +76,14 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => { .start(done); }); + test('Should not import inspector when not in use', done => { + createRunner(__dirname, 'deny-inspector.mjs') + .withFlags('--import=@sentry/node/import') + .ensureNoErrorOutput() + .ignore('session') + .start(done); + }); + test('Includes local variables for caught exceptions when enabled', done => { createRunner(__dirname, 'local-variables-caught.js') .ignore('session')