Skip to content

Commit 0889751

Browse files
authored
test(node): All integration tests now use the new runner (#11341)
This PR converts the remaining tests to using the newer child process runner. Because the test scenarios are now completely isolated, Jest can be used to run them rather than the custom script.
1 parent ae84d1a commit 0889751

File tree

60 files changed

+658
-660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+658
-660
lines changed

dev-packages/node-integration-tests/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
"fix": "eslint . --format stylish --fix",
2222
"type-check": "tsc",
2323
"pretest": "run-s --silent prisma:init",
24-
"test": "ts-node ./utils/run-tests.ts",
25-
"jest": "jest --config ./jest.config.js",
24+
"test": "jest --config ./jest.config.js",
2625
"test:watch": "yarn test --watch"
2726
},
2827
"dependencies": {
2928
"@hapi/hapi": "^20.3.0",
30-
"@nestjs/common": "^10.3.3",
29+
"@nestjs/common": "^10.3.7",
3130
"@nestjs/core": "^10.3.3",
3231
"@nestjs/platform-express": "^10.3.3",
3332
"@prisma/client": "5.9.1",

dev-packages/node-integration-tests/suites/public-api/addBreadcrumb/empty-obj/scenario.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
Sentry.addBreadcrumb({});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should add an empty breadcrumb, when an empty object is given', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const envelope = await env.getEnvelopeRequest();
6-
7-
expect(envelope).toHaveLength(3);
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
86

9-
assertSentryEvent(envelope[2], {
10-
message: 'test-empty-obj',
11-
});
7+
test('should add an empty breadcrumb, when an empty object is given', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
message: 'test-empty-obj',
12+
},
13+
})
14+
.start(done);
1215
});

dev-packages/node-integration-tests/suites/public-api/addBreadcrumb/multiple_breadcrumbs/scenario.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
Sentry.addBreadcrumb({
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should add multiple breadcrumbs', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const events = await env.getEnvelopeRequest();
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
66

7-
assertSentryEvent(events[2], {
8-
message: 'test_multi_breadcrumbs',
9-
breadcrumbs: [
10-
{
11-
category: 'foo',
12-
message: 'bar',
13-
level: 'fatal',
14-
},
15-
{
16-
category: 'qux',
7+
test('should add multiple breadcrumbs', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
message: 'test_multi_breadcrumbs',
12+
breadcrumbs: [
13+
{
14+
category: 'foo',
15+
message: 'bar',
16+
level: 'fatal',
17+
},
18+
{
19+
category: 'qux',
20+
},
21+
],
1722
},
18-
],
19-
});
23+
})
24+
.start(done);
2025
});

dev-packages/node-integration-tests/suites/public-api/addBreadcrumb/simple_breadcrumb/scenario.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
Sentry.addBreadcrumb({
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { createRunner } from '../../../../utils/runner';
22

3-
test('should add a simple breadcrumb', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const event = await env.getEnvelopeRequest();
6-
7-
assertSentryEvent(event[2], {
8-
message: 'test_simple',
9-
breadcrumbs: [
10-
{
11-
category: 'foo',
12-
message: 'bar',
13-
level: 'fatal',
3+
test('should add a simple breadcrumb', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.expect({
6+
event: {
7+
message: 'test_simple',
8+
breadcrumbs: [
9+
{
10+
category: 'foo',
11+
message: 'bar',
12+
level: 'fatal',
13+
},
14+
],
1415
},
15-
],
16-
});
16+
})
17+
.start(done);
1718
});

dev-packages/node-integration-tests/suites/public-api/captureException/catched-error/scenario.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
try {
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should work inside catch block', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const event = await env.getEnvelopeRequest();
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
66

7-
assertSentryEvent(event[2], {
8-
exception: {
9-
values: [
10-
{
11-
type: 'Error',
12-
value: 'catched_error',
13-
mechanism: {
14-
type: 'generic',
15-
handled: true,
16-
},
17-
stacktrace: {
18-
frames: expect.arrayContaining([
19-
expect.objectContaining({
20-
context_line: " throw new Error('catched_error');",
21-
pre_context: [
22-
'',
23-
'Sentry.init({',
24-
" dsn: 'https://[email protected]/1337',",
25-
" release: '1.0',",
26-
'});',
27-
'',
28-
'try {',
29-
],
30-
post_context: ['} catch (err) {', ' Sentry.captureException(err);', '}', ''],
31-
}),
32-
]),
33-
},
7+
test('should work inside catch block', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
exception: {
12+
values: [
13+
{
14+
type: 'Error',
15+
value: 'catched_error',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
stacktrace: {
21+
frames: expect.arrayContaining([
22+
expect.objectContaining({
23+
context_line: " throw new Error('catched_error');",
24+
pre_context: [
25+
'Sentry.init({',
26+
" dsn: 'https://[email protected]/1337',",
27+
" release: '1.0',",
28+
' transport: loggingTransport,',
29+
'});',
30+
'',
31+
'try {',
32+
],
33+
post_context: ['} catch (err) {', ' Sentry.captureException(err);', '}', ''],
34+
}),
35+
]),
36+
},
37+
},
38+
],
3439
},
35-
],
36-
},
37-
});
40+
},
41+
})
42+
.start(done);
3843
});
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
Sentry.captureException({});
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should capture an empty object', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const event = await env.getEnvelopeRequest();
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
66

7-
assertSentryEvent(event[2], {
8-
exception: {
9-
values: [
10-
{
11-
type: 'Error',
12-
value: 'Object captured as exception with keys: [object has no keys]',
13-
mechanism: {
14-
type: 'generic',
15-
handled: true,
16-
},
7+
test('should capture an empty object', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
exception: {
12+
values: [
13+
{
14+
type: 'Error',
15+
value: 'Object captured as exception with keys: [object has no keys]',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
},
21+
],
1722
},
18-
],
19-
},
20-
});
23+
},
24+
})
25+
.start(done);
2126
});
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
Sentry.captureException(new Error('test_simple_error'));
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should capture a simple error with message', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const envelope = await env.getEnvelopeRequest();
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
66

7-
assertSentryEvent(envelope[2], {
8-
exception: {
9-
values: [
10-
{
11-
type: 'Error',
12-
value: 'test_simple_error',
13-
mechanism: {
14-
type: 'generic',
15-
handled: true,
16-
},
17-
stacktrace: {
18-
frames: expect.any(Array),
19-
},
7+
test('should capture a simple error with message', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
exception: {
12+
values: [
13+
{
14+
type: 'Error',
15+
value: 'test_simple_error',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
stacktrace: {
21+
frames: expect.any(Array),
22+
},
23+
},
24+
],
2025
},
21-
],
22-
},
23-
});
26+
},
27+
})
28+
.start(done);
2429
});

dev-packages/node-integration-tests/suites/public-api/captureMessage/parameterized_message/scenario.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
12
import * as Sentry from '@sentry/node';
23

34
Sentry.init({
45
dsn: 'https://[email protected]/1337',
56
release: '1.0',
7+
transport: loggingTransport,
68
});
79

810
const x = 'first';
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { TestEnv, assertSentryEvent } from '../../../../utils';
1+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
22

3-
test('should capture a parameterized representation of the message', async () => {
4-
const env = await TestEnv.init(__dirname);
5-
const event = await env.getEnvelopeRequest();
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
66

7-
assertSentryEvent(event[2], {
8-
logentry: {
9-
message: 'This is a log statement with %s and %s params',
10-
params: ['first', 'second'],
11-
},
12-
});
7+
test('should capture a parameterized representation of the message', done => {
8+
createRunner(__dirname, 'scenario.ts')
9+
.expect({
10+
event: {
11+
logentry: {
12+
message: 'This is a log statement with %s and %s params',
13+
params: ['first', 'second'],
14+
},
15+
},
16+
})
17+
.start(done);
1318
});

0 commit comments

Comments
 (0)