Skip to content
3 changes: 2 additions & 1 deletion dev-packages/node-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ module.exports = {
},
},
{
files: ['suites/**/*.ts'],
files: ['suites/**/*.ts', 'suites/**/*.mjs'],
parserOptions: {
project: ['tsconfig.test.json'],
sourceType: 'module',
ecmaVersion: 'latest',
},
rules: {
'@typescript-eslint/typedef': 'off',
Expand Down
1 change: 1 addition & 0 deletions dev-packages/node-integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
suites/**/tmp_*
3 changes: 1 addition & 2 deletions dev-packages/node-integration-tests/suites/anr/app-path.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';
import * as path from 'path';
import * as url from 'url';

import * as Sentry from '@sentry/node';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
Expand Down
3 changes: 1 addition & 2 deletions dev-packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

setTimeout(() => {
process.exit();
}, 10000);
Expand Down
3 changes: 1 addition & 2 deletions dev-packages/node-integration-tests/suites/anr/isolated.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as Sentry from '@sentry/node';
import * as assert from 'assert';
import * as crypto from 'crypto';

import * as Sentry from '@sentry/node';

setTimeout(() => {
process.exit();
}, 10000);
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const ANR_EVENT_WITH_DEBUG_META: Event = {
},
};

describe('should report ANR when event loop blocked', { timeout: 60_000 }, () => {
describe('should report ANR when event loop blocked', { timeout: 90_000 }, () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but this flaked some times, let's see if this helps...

afterAll(() => {
cleanupChildProcesses();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import { spawn } from 'child_process';
import { join } from 'path';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { Worker } from 'worker_threads';

const __dirname = new URL('.', import.meta.url).pathname;
Expand All @@ -13,16 +13,18 @@ Sentry.init({
transport: loggingTransport,
});

await new Promise(resolve => {
const child = spawn('sleep', ['a']);
child.on('error', resolve);
child.on('exit', resolve);
});
(async () => {
await new Promise(resolve => {
const child = spawn('sleep', ['a']);
child.on('error', resolve);
child.on('exit', resolve);
});

await new Promise(resolve => {
const worker = new Worker(join(__dirname, 'worker.mjs'));
worker.on('error', resolve);
worker.on('exit', resolve);
});
await new Promise(resolve => {
const worker = new Worker(join(__dirname, 'worker.mjs'));
worker.on('error', resolve);
worker.on('exit', resolve);
});

throw new Error('This is a test error');
throw new Error('This is a test error');
})();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import { fork } from 'child_process';
import * as path from 'path';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

const __dirname = new URL('.', import.meta.url).pathname;

Expand All @@ -12,6 +12,7 @@ Sentry.init({
transport: loggingTransport,
});

// eslint-disable-next-line no-unused-vars
const _child = fork(path.join(__dirname, 'child.mjs'));

setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as path from 'path';
import { Worker } from 'worker_threads';

const __dirname = new URL('.', import.meta.url).pathname;
Expand All @@ -12,6 +12,7 @@ Sentry.init({
transport: loggingTransport,
});

// eslint-disable-next-line no-unused-vars
const _worker = new Worker(path.join(__dirname, 'child.mjs'));

setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('ContextLines integration in ESM', () => {
const instrumentPath = join(__dirname, 'instrument.mjs');

await createRunner(__dirname, 'scenario with space.mjs')
.withFlags('--import', instrumentPath)
.withInstrument(instrumentPath)
.expect({
event: {
exception: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as iitm from 'import-in-the-middle';

new iitm.Hook((_, name) => {
Expand All @@ -14,6 +14,8 @@ Sentry.init({
transport: loggingTransport,
});

await import('./sub-module.mjs');
await import('http');
await import('os');
(async () => {
await import('./sub-module.mjs');
await import('http');
await import('os');
})();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
transport: loggingTransport,
});

import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';

const app = express();

app.get('/test/success', (req, res) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as Sentry from '@sentry/node';
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';
import http from 'http';

const app = express();

app.get('/test', (_req, res) => {
http.get(`http://localhost:${app.port}/test2`, httpRes => {
httpRes.on('data', () => {
setTimeout(() => {
res.send({ response: 'response 1' });
}, 200);
});
});
});

app.get('/test2', (_req, res) => {
res.send({ response: 'response 2' });
});

app.get('/test3', (_req, res) => {
res.send({ response: 'response 3' });
});

Sentry.setupExpressErrorHandler(app);

startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { afterAll, describe } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('express with http import', () => {
afterAll(() => {
cleanupChildProcesses();
});

createEsmAndCjsTests(
__dirname,
'scenario.mjs',
'instrument.mjs',
(createRunner, test) => {
test('it works when importing the http module', async () => {
const runner = createRunner()
.expect({
transaction: {
transaction: 'GET /test2',
},
})
.expect({
transaction: {
transaction: 'GET /test',
},
})
.expect({
transaction: {
transaction: 'GET /test3',
},
})
.start();
await runner.makeRequest('get', '/test');
await runner.makeRequest('get', '/test3');
await runner.completed();
});
// TODO: This is failing on ESM because importing http is triggering the http spans twice :(
// We need to fix this!
},
{ failsOnEsm: true },
);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { register } from 'node:module';

// eslint-disable-next-line no-unused-vars
const hookScript = Buffer.from(`

`);
Expand All @@ -16,6 +17,8 @@ export async function resolve(specifier, context, nextResolve) {
import.meta.url,
);

const Sentry = await import('@sentry/node');
(async () => {
const Sentry = await import('@sentry/node');

Sentry.init({});
Sentry.init({});
})();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-vars */
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand Down
58 changes: 0 additions & 58 deletions dev-packages/node-integration-tests/suites/tracing/ai/scenario.js

This file was deleted.

19 changes: 6 additions & 13 deletions dev-packages/node-integration-tests/suites/tracing/ai/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { join } from 'node:path';
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

// `ai` SDK only support Node 18+
describe('ai', () => {
Expand Down Expand Up @@ -126,15 +125,9 @@ describe('ai', () => {
]),
};

test('creates ai related spans - cjs', async () => {
await createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});

test('creates ai related spans - esm', async () => {
await createRunner(__dirname, 'scenario.mjs')
.withFlags('--import', join(__dirname, 'instrument.mjs'))
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates ai related spans ', async () => {
await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});
});
});
Loading
Loading