Skip to content

Commit 26590ea

Browse files
onurtemizkanLuca Forstner
authored and
Luca Forstner
committed
fix(test): Fix MongoDB integration tests on CI (#4810)
1 parent de3421f commit 26590ea

File tree

5 files changed

+121
-163
lines changed

5 files changed

+121
-163
lines changed

packages/node-integration-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"express": "^4.17.3",
2222
"mysql": "^2.18.1",
2323
"mongodb": "^3.7.3",
24-
"mongodb-memory-server": "^8.4.1",
24+
"mongodb-memory-server": "^7.6.3",
2525
"nock": "^13.1.0",
2626
"pg": "^8.7.3",
2727
"portfinder": "^1.0.28"

packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/scenario.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
21
import '@sentry/tracing';
32

43
import * as Sentry from '@sentry/node';
Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,91 @@
11
import { MongoMemoryServer } from 'mongodb-memory-server';
22

3-
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../../utils';
3+
import { assertSentryTransaction, conditionalTest, getEnvelopeRequest, runServer } from '../../../../utils';
44

5-
test('should auto-instrument `mongodb` package.', async () => {
6-
const mongoServer = await MongoMemoryServer.create();
7-
process.env.MONGO_URL = mongoServer.getUri();
5+
conditionalTest({ min: 12 })('MongoDB Test', () => {
6+
let mongoServer: MongoMemoryServer;
87

9-
const url = await runServer(__dirname);
8+
beforeAll(async () => {
9+
mongoServer = await MongoMemoryServer.create();
10+
process.env.MONGO_URL = mongoServer.getUri();
11+
}, 30000);
1012

11-
const envelope = await getEnvelopeRequest(url);
13+
afterAll(async () => {
14+
await mongoServer.stop();
15+
});
16+
17+
test('should auto-instrument `mongodb` package.', async () => {
18+
const url = await runServer(__dirname);
19+
20+
const envelope = await getEnvelopeRequest(url);
1221

13-
expect(envelope).toHaveLength(3);
22+
expect(envelope).toHaveLength(3);
1423

15-
assertSentryTransaction(envelope[2], {
16-
transaction: 'Test Transaction',
17-
spans: [
18-
{
19-
data: {
20-
collectionName: 'movies',
21-
dbName: 'admin',
22-
namespace: 'admin.movies',
23-
doc: '{"title":"Rick and Morty"}',
24+
assertSentryTransaction(envelope[2], {
25+
transaction: 'Test Transaction',
26+
spans: [
27+
{
28+
data: {
29+
collectionName: 'movies',
30+
dbName: 'admin',
31+
namespace: 'admin.movies',
32+
doc: '{"title":"Rick and Morty"}',
33+
},
34+
description: 'insertOne',
35+
op: 'db',
2436
},
25-
description: 'insertOne',
26-
op: 'db',
27-
},
28-
{
29-
data: {
30-
collectionName: 'movies',
31-
dbName: 'admin',
32-
namespace: 'admin.movies',
33-
query: '{"title":"Back to the Future"}',
37+
{
38+
data: {
39+
collectionName: 'movies',
40+
dbName: 'admin',
41+
namespace: 'admin.movies',
42+
query: '{"title":"Back to the Future"}',
43+
},
44+
description: 'findOne',
45+
op: 'db',
3446
},
35-
description: 'findOne',
36-
op: 'db',
37-
},
38-
{
39-
data: {
40-
collectionName: 'movies',
41-
dbName: 'admin',
42-
namespace: 'admin.movies',
43-
query: '{"title":"Back to the Future"}',
47+
{
48+
data: {
49+
collectionName: 'movies',
50+
dbName: 'admin',
51+
namespace: 'admin.movies',
52+
query: '{"title":"Back to the Future"}',
53+
},
54+
description: 'find',
55+
op: 'db',
4456
},
45-
description: 'find',
46-
op: 'db',
47-
},
48-
{
49-
data: {
50-
collectionName: 'movies',
51-
dbName: 'admin',
52-
namespace: 'admin.movies',
53-
filter: '{"title":"Back to the Future"}',
54-
update: '{"$set":{"title":"South Park"}}',
57+
{
58+
data: {
59+
collectionName: 'movies',
60+
dbName: 'admin',
61+
namespace: 'admin.movies',
62+
filter: '{"title":"Back to the Future"}',
63+
update: '{"$set":{"title":"South Park"}}',
64+
},
65+
description: 'updateOne',
66+
op: 'db',
5567
},
56-
description: 'updateOne',
57-
op: 'db',
58-
},
59-
{
60-
data: {
61-
collectionName: 'movies',
62-
dbName: 'admin',
63-
namespace: 'admin.movies',
64-
query: '{"title":"South Park"}',
68+
{
69+
data: {
70+
collectionName: 'movies',
71+
dbName: 'admin',
72+
namespace: 'admin.movies',
73+
query: '{"title":"South Park"}',
74+
},
75+
description: 'findOne',
76+
op: 'db',
6577
},
66-
description: 'findOne',
67-
op: 'db',
68-
},
69-
{
70-
data: {
71-
collectionName: 'movies',
72-
dbName: 'admin',
73-
namespace: 'admin.movies',
74-
query: '{"title":"South Park"}',
78+
{
79+
data: {
80+
collectionName: 'movies',
81+
dbName: 'admin',
82+
namespace: 'admin.movies',
83+
query: '{"title":"South Park"}',
84+
},
85+
description: 'find',
86+
op: 'db',
7587
},
76-
description: 'find',
77-
op: 'db',
78-
},
79-
],
88+
],
89+
});
8090
});
8191
});

packages/node-integration-tests/utils/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
import { parseSemver } from '@sentry/utils';
23
import { Express } from 'express';
34
import * as http from 'http';
45
import nock from 'nock';
56
import * as path from 'path';
67
import { getPortPromise } from 'portfinder';
78

9+
/**
10+
* Returns`describe` or `describe.skip` depending on allowed major versions of Node.
11+
*
12+
* @param {{ min?: number; max?: number }} allowedVersion
13+
* @return {*} {jest.Describe}
14+
*/
15+
export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => {
16+
const NODE_VERSION = parseSemver(process.versions.node).major;
17+
if (!NODE_VERSION) {
18+
return describe.skip;
19+
}
20+
21+
return NODE_VERSION < (allowedVersion.min || -Infinity) || NODE_VERSION > (allowedVersion.max || Infinity)
22+
? describe.skip
23+
: describe;
24+
};
25+
826
/**
927
* Asserts against a Sentry Event ignoring non-deterministic properties
1028
*

0 commit comments

Comments
 (0)