Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
});
});

test('With --inspect', done => {
expect.assertions(7);

const testScriptPath = path.resolve(__dirname, 'basic.js');

childProcess.exec(`node --inspect ${testScriptPath}`, { encoding: 'utf8' }, (_, stdout) => {

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [absolute path](1).
const [event] = parseJsonLines<[Event]>(stdout, 1);

expect(event.exception?.values?.[0].mechanism).toEqual({ type: 'ANR' });
expect(event.exception?.values?.[0].type).toEqual('ApplicationNotResponding');
expect(event.exception?.values?.[0].value).toEqual('Application Not Responding for at least 200 ms');
expect(event.exception?.values?.[0].stacktrace?.frames?.length).toBeGreaterThan(4);

expect(event.exception?.values?.[0].stacktrace?.frames?.[2].function).toEqual('?');
expect(event.exception?.values?.[0].stacktrace?.frames?.[3].function).toEqual('longWork');

done();
});
});

test('With session', done => {
expect.assertions(9);

Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class Anr implements Integration {
if (options.captureStackTrace) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const inspector: InspectorApi = require('inspector');
inspector.open(0);
if (!inspector.url()) {
inspector.open(0);
}
}

const { Worker } = getWorkerThreads();
Expand Down