Skip to content

Commit fc8fc4f

Browse files
committed
test(node): Add --import test to integration tests
1 parent b271bc8 commit fc8fc4f

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
tracePropagationTargets: [/\/v0/, 'v1'],
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as http from 'http';
2+
import * as Sentry from '@sentry/node';
3+
4+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
5+
Sentry.startSpan({ name: 'test_span' }, async () => {
6+
await makeHttpRequest(`${process.env.SERVER_URL}/api/v0`);
7+
await makeHttpRequest(`${process.env.SERVER_URL}/api/v1`);
8+
await makeHttpRequest(`${process.env.SERVER_URL}/api/v2`);
9+
await makeHttpRequest(`${process.env.SERVER_URL}/api/v3`);
10+
});
11+
12+
function makeHttpRequest(url) {
13+
return new Promise(resolve => {
14+
http
15+
.request(url, httpRes => {
16+
httpRes.on('data', () => {
17+
// we don't care about data
18+
});
19+
httpRes.on('end', () => {
20+
resolve();
21+
});
22+
})
23+
.end();
24+
});
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { join } from 'path';
2+
import { createRunner } from '../../../../utils/runner';
3+
import { createTestServer } from '../../../../utils/server';
4+
5+
test('outgoing sampled http requests are correctly instrumented in ESM', done => {
6+
expect.assertions(11);
7+
8+
createTestServer(done)
9+
.get('/api/v0', headers => {
10+
expect(headers['baggage']).toEqual(expect.any(String));
11+
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})-1$/));
12+
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-1');
13+
})
14+
.get('/api/v1', headers => {
15+
expect(headers['baggage']).toEqual(expect.any(String));
16+
expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})-1$/));
17+
expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-1');
18+
})
19+
.get('/api/v2', headers => {
20+
expect(headers['baggage']).toBeUndefined();
21+
expect(headers['sentry-trace']).toBeUndefined();
22+
})
23+
.get('/api/v3', headers => {
24+
expect(headers['baggage']).toBeUndefined();
25+
expect(headers['sentry-trace']).toBeUndefined();
26+
})
27+
.start()
28+
.then(([SERVER_URL, closeTestServer]) => {
29+
const instrumentPath = join(__dirname, 'instrument.mjs');
30+
createRunner(__dirname, 'scenario.mjs')
31+
.withFlags('--import', instrumentPath)
32+
.withEnv({ SERVER_URL })
33+
.expect({
34+
transaction: {
35+
// we're not too concerned with the actual transaction here since this is tested elsewhere
36+
},
37+
})
38+
.start(closeTestServer);
39+
});
40+
});

dev-packages/node-integration-tests/utils/runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ export function createRunner(...paths: string[]) {
338338
const output = data.toString();
339339
logs.push(output.trim());
340340

341+
if (process.env.DEBUG) log('stderr line', output);
342+
341343
if (ensureNoErrorOutput) {
342344
complete(new Error(`Expected no error output but got: '${output}'`));
343345
}

0 commit comments

Comments
 (0)