Skip to content

Commit bc349a2

Browse files
authored
test(instrumentation-mongodb): Include all versions in coverage (open-telemetry#2681)
1 parent 92106ff commit bc349a2

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

plugins/node/opentelemetry-instrumentation-mongodb/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
"repository": "open-telemetry/opentelemetry-js-contrib",
88
"scripts": {
99
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
10-
"test": "npm run test-v5-v6",
11-
"test-v3": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
12-
"test-v4": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
13-
"test-v5-v6": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
10+
"test": "npm run test-v3 && npm run test-v4 && npm run test-v5-v6 && nyc merge .nyc_output ./coverage/coverage-final.json",
11+
"test-v3": "tav mongodb 3.7.4 npm run test-v3-run",
12+
"test-v4": "tav mongodb 4.17.0 npm run test-v4-run",
13+
"test-v5-v6": "npm run test-v5-v6-run",
14+
"test-v3-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
15+
"test-v4-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
16+
"test-v5-v6-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
1417
"test-all-versions": "tav",
15-
"tdd": "npm run test -- --watch-extensions ts --watch",
18+
"tdd": "npm run test-v5-v6-run -- --watch-extensions ts --watch",
1619
"clean": "rimraf build/*",
1720
"lint": "eslint . --ext .ts",
1821
"lint:fix": "eslint . --ext .ts --fix",

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ import {
3939
SEMATTRS_NET_PEER_PORT,
4040
} from '@opentelemetry/semantic-conventions';
4141

42+
// We can't use @ts-expect-error because it will fail depending on the used mongodb version on tests
43+
/* eslint-disable @typescript-eslint/ban-ts-comment */
44+
4245
describe('MongoDBInstrumentation-Tracing-v3', () => {
4346
function create(config: MongoDBInstrumentationConfig = {}) {
4447
instrumentation.setConfig(config);
@@ -85,7 +88,7 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
8588
}
8689
// Non traced insertion of basic data to perform tests
8790
const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }];
88-
// @ts-expect-error -- v5 removed callback support
91+
// @ts-ignore -- v5 removed callback support
8992
collection.insertMany(insertData, (err: any, result: any) => {
9093
resetMemoryExporter();
9194
done();
@@ -94,7 +97,7 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
9497

9598
afterEach(done => {
9699
if (shouldTest) {
97-
// @ts-expect-error -- v5 removed callback support
100+
// @ts-ignore -- v5 removed callback support
98101
collection.deleteMany({}, done);
99102
} else {
100103
done();
@@ -619,7 +622,6 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
619622
let collection: Collection;
620623
before(done => {
621624
accessCollection(URL, DB_NAME, COLLECTION_NAME, {
622-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
623625
// @ts-ignore
624626
useUnifiedTopology: true,
625627
})
@@ -642,7 +644,7 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
642644
it('should generate correct span attributes', done => {
643645
const span = trace.getTracer('default').startSpan('findRootSpan');
644646
context.with(trace.setSpan(context.active(), span), () => {
645-
// @ts-expect-error -- v5 removed callback support
647+
// @ts-ignore -- v5 removed callback support
646648
collection.find({ a: 1 }).toArray((err, results) => {
647649
span.end();
648650
const [mongoSpan] = getTestSpans();
@@ -723,3 +725,5 @@ describe('MongoDBInstrumentation-Tracing-v3', () => {
723725
});
724726
});
725727
});
728+
729+
/* eslint-enable @typescript-eslint/ban-ts-comment */

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import type { MongoClient, Collection } from 'mongodb';
3737
import { assertSpans, accessCollection, DEFAULT_MONGO_HOST } from './utils';
3838
import { SEMATTRS_DB_STATEMENT } from '@opentelemetry/semantic-conventions';
3939

40+
// We can't use @ts-expect-error because it will fail depending on the used mongodb version on tests
41+
/* eslint-disable @typescript-eslint/ban-ts-comment */
42+
4043
describe('MongoDBInstrumentation-Tracing-v4', () => {
4144
function create(config: MongoDBInstrumentationConfig = {}) {
4245
instrumentation.setConfig(config);
@@ -82,7 +85,7 @@ describe('MongoDBInstrumentation-Tracing-v4', () => {
8285
}
8386
// Non traced insertion of basic data to perform tests
8487
const insertData = [{ a: 1 }, { a: 2 }, { a: 3 }];
85-
// @ts-expect-error -- v5 removed callback support
88+
// @ts-ignore -- v5 removed callback support
8689
collection.insertMany(insertData, (err: any, result: any) => {
8790
resetMemoryExporter();
8891
done();
@@ -91,7 +94,7 @@ describe('MongoDBInstrumentation-Tracing-v4', () => {
9194

9295
afterEach(done => {
9396
if (shouldTest) {
94-
// @ts-expect-error -- v5 removed callback support
97+
// @ts-ignore -- v5 removed callback support
9598
collection.deleteMany({}, done);
9699
} else {
97100
done();
@@ -693,3 +696,5 @@ describe('MongoDBInstrumentation-Tracing-v4', () => {
693696
});
694697
});
695698
});
699+
700+
/* eslint-enable @typescript-eslint/ban-ts-comment */

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v5-v6.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ import type { MongoClient, Collection } from 'mongodb';
4646
import { assertSpans, accessCollection, DEFAULT_MONGO_HOST } from './utils';
4747
import { SEMATTRS_DB_STATEMENT } from '@opentelemetry/semantic-conventions';
4848

49+
// We can't use @ts-expect-error because it will fail depending on the used mongodb version on tests
50+
/* eslint-disable @typescript-eslint/ban-ts-comment */
51+
4952
describe('MongoDBInstrumentation-Tracing-v5', () => {
5053
function create(config: MongoDBInstrumentationConfig = {}) {
5154
instrumentation.setConfig(config);
@@ -706,3 +709,5 @@ describe('MongoDBInstrumentation-Tracing-v5', () => {
706709
});
707710
});
708711
});
712+
713+
/* eslint-enable @typescript-eslint/ban-ts-comment */

0 commit comments

Comments
 (0)