Skip to content

Commit dc6bbec

Browse files
authored
test: Fix flakey inspector test (#12274)
Uses an alternative test method. Should reduce failures like [this](https://github.com/getsentry/sentry-javascript/actions/runs/9281632639/job/25538103763).
1 parent c3b66fa commit dc6bbec

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import * as Sentry from '@sentry/node';
2-
import Hook from 'import-in-the-middle';
1+
import { register } from 'node:module';
32

4-
Hook((_, name) => {
5-
if (name === 'inspector') {
6-
throw new Error('No inspector!');
7-
}
8-
if (name === 'node:inspector') {
9-
throw new Error('No inspector!');
3+
const hookScript = Buffer.from(`
4+
5+
`);
6+
7+
register(
8+
new URL(`data:application/javascript,
9+
export async function resolve(specifier, context, nextResolve) {
10+
if (specifier === 'node:inspector' || specifier === 'inspector') {
11+
throw new Error('Should not use node:inspector module');
1012
}
11-
});
13+
14+
return nextResolve(specifier);
15+
}`),
16+
import.meta.url,
17+
);
18+
19+
const Sentry = await import('@sentry/node');
1220

1321
Sentry.init({});

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => {
7676
.start(done);
7777
});
7878

79-
test('Should not import inspector when not in use', done => {
80-
createRunner(__dirname, 'deny-inspector.mjs')
81-
.withFlags('--import=@sentry/node/import')
82-
.ensureNoErrorOutput()
83-
.ignore('session')
84-
.start(done);
79+
conditionalTest({ min: 19 })('Node v19+', () => {
80+
test('Should not import inspector when not in use', done => {
81+
createRunner(__dirname, 'deny-inspector.mjs').ensureNoErrorOutput().ignore('session').start(done);
82+
});
8583
});
8684

8785
test('Includes local variables for caught exceptions when enabled', done => {

0 commit comments

Comments
 (0)