From dfc5a0e6f308859f846fdb4255ae658283352b81 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Thu, 30 Oct 2025 11:33:49 +0100 Subject: [PATCH 1/3] test(NODE-7280): remove test/mongodb.ts and its usage --- test/action/dependency.test.ts | 36 +++-- .../examples/transactions.test.js | 4 +- .../node-specific/examples/versioned_api.js | 3 +- .../resource_tracking_script_builder.ts | 4 +- test/mocha_mongodb.js | 4 +- test/mongodb.ts | 140 ------------------ test/tools/mongodb-mock/src/server.js | 2 +- test/tools/runner/hooks/legacy_crud_shims.ts | 12 +- test/tools/spec-runner/index.js | 4 +- test/tools/unified-spec-runner/entities.ts | 7 +- test/tools/unified-spec-runner/match.ts | 2 +- test/tools/unified-spec-runner/runner.ts | 6 +- test/tools/unified-spec-runner/schema.ts | 2 +- .../unified-spec-runner/unified-utils.ts | 8 +- test/tools/utils.ts | 5 +- test/unit/sdam/topology.test.ts | 2 +- 16 files changed, 45 insertions(+), 196 deletions(-) delete mode 100644 test/mongodb.ts diff --git a/test/action/dependency.test.ts b/test/action/dependency.test.ts index e21059b1100..275f0f545f0 100644 --- a/test/action/dependency.test.ts +++ b/test/action/dependency.test.ts @@ -5,7 +5,7 @@ import * as path from 'node:path'; import { expect } from 'chai'; import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json'; -import { setDifference } from '../mongodb'; +import { setDifference } from '../../src/utils'; import { alphabetically, itInNodeProcess, sorted } from '../tools/utils'; const EXPECTED_DEPENDENCIES = sorted( @@ -82,16 +82,15 @@ describe('package.json', function () { }); if (depName === 'snappy') { - itInNodeProcess( - 'getSnappy returns rejected import', - async function ({ expect, mongodb }) { - const snappyImport = mongodb.getSnappy(); - expect(snappyImport).to.have.nested.property( - 'kModuleError.name', - 'MongoMissingDependencyError' - ); - } - ); + itInNodeProcess('getSnappy returns rejected import', async function ({ expect }) { + // @ts-expect-error: import from the inside forked process + const { getSnappy } = await import('./src/deps.ts'); + const snappyImport = getSnappy(); + expect(snappyImport).to.have.nested.property( + 'kModuleError.name', + 'MongoMissingDependencyError' + ); + }); } }); @@ -111,14 +110,13 @@ describe('package.json', function () { }); if (depName === 'snappy') { - itInNodeProcess( - 'getSnappy returns fulfilled import', - async function ({ expect, mongodb }) { - const snappyImport = mongodb.getSnappy(); - expect(snappyImport).to.have.property('compress').that.is.a('function'); - expect(snappyImport).to.have.property('uncompress').that.is.a('function'); - } - ); + itInNodeProcess('getSnappy returns fulfilled import', async function ({ expect }) { + // @ts-expect-error: import from the inside forked process + const { getSnappy } = await import('./src/deps.ts'); + const snappyImport = getSnappy(); + expect(snappyImport).to.have.property('compress').that.is.a('function'); + expect(snappyImport).to.have.property('uncompress').that.is.a('function'); + }); } }); } diff --git a/test/integration/node-specific/examples/transactions.test.js b/test/integration/node-specific/examples/transactions.test.js index 4b72a88801c..ed26b31979d 100644 --- a/test/integration/node-specific/examples/transactions.test.js +++ b/test/integration/node-specific/examples/transactions.test.js @@ -1,6 +1,4 @@ -'use strict'; - -const { MongoClient } = require('../../../mongodb'); +const { MongoClient } = require('mongodb'); // Yes, we are shadowing a global here but we are not actually ever printing anything in this file // This just so the examples can use console.log to make for nice copy pasting diff --git a/test/integration/node-specific/examples/versioned_api.js b/test/integration/node-specific/examples/versioned_api.js index e8e131c1309..be111bb1b24 100644 --- a/test/integration/node-specific/examples/versioned_api.js +++ b/test/integration/node-specific/examples/versioned_api.js @@ -1,5 +1,4 @@ -'use strict'; -const { MongoClient } = require('../../../mongodb'); +const { MongoClient } = require('mongodb'); describe('examples.versionedApi:', function () { let uri; diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index e166dfb6b4c..2a985c71576 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -9,8 +9,7 @@ import { AssertionError, expect } from 'chai'; import type * as timers from 'timers'; import { parseSnapshot } from 'v8-heapsnapshot'; -import type * as mongodb from '../../mongodb'; -import { type MongoClient } from '../../mongodb'; +import { type MongoClient } from '../../../src'; import { type TestConfiguration } from '../../tools/runner/config'; import { type sleep } from '../../tools/utils'; @@ -27,7 +26,6 @@ export type ProcessResourceTestFunction = (options: { uri?: string; log?: (out: any) => void; expect: typeof expect; - mongodb?: typeof mongodb; sleep?: typeof sleep; getTimerCount?: () => number; timers?: typeof timers; diff --git a/test/mocha_mongodb.js b/test/mocha_mongodb.js index b33ea65622f..9c32b0ea4ca 100644 --- a/test/mocha_mongodb.js +++ b/test/mocha_mongodb.js @@ -27,7 +27,9 @@ module.exports = { 'test/integration/node-specific/examples/handler.test.js', 'test/integration/node-specific/examples/aws_handler.js', 'test/integration/node-specific/examples/aws_handler.test.js', - 'test/integration/node-specific/examples/setup.js' + 'test/integration/node-specific/examples/setup.js', + 'test/integration/node-specific/examples/transactions.test.js', + 'test/integration/node-specific/examples/versioned_api.js' ], 'node-option': Number(major) >= 23 ? ['no-experimental-strip-types'] : undefined }; diff --git a/test/mongodb.ts b/test/mongodb.ts deleted file mode 100644 index b289249eb65..00000000000 --- a/test/mongodb.ts +++ /dev/null @@ -1,140 +0,0 @@ -import * as fs from 'node:fs'; -import * as path from 'node:path'; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function printExports() { - function* walk(root: string): Generator { - const directoryContents = fs.readdirSync(root); - for (const filepath of directoryContents) { - const fullPath = path.join(root, filepath); - const stat = fs.statSync(fullPath); - if (stat.isDirectory()) { - yield* walk(fullPath); - } else if (stat.isFile()) { - yield fullPath; - } - } - } - const driverSourceFiles = Array.from(walk(path.resolve(__dirname, '..', 'src'))); - - for (const srcFile of driverSourceFiles) { - console.log(`export * from '${path.relative(__dirname, srcFile)}';`); - } -} - -export * from '../src/admin'; -export * from '../src/bson'; -export * from '../src/bulk/common'; -export * from '../src/bulk/ordered'; -export * from '../src/bulk/unordered'; -export * from '../src/change_stream'; -export * from '../src/client-side-encryption/auto_encrypter'; -export * from '../src/client-side-encryption/client_encryption'; -export * from '../src/client-side-encryption/errors'; -export * from '../src/client-side-encryption/mongocryptd_manager'; -export * from '../src/client-side-encryption/providers/aws'; -export * from '../src/client-side-encryption/providers/azure'; -export * from '../src/client-side-encryption/providers/gcp'; -export * from '../src/client-side-encryption/providers/index'; -export * from '../src/client-side-encryption/state_machine'; -export * from '../src/cmap/auth/auth_provider'; -export * from '../src/cmap/auth/aws_temporary_credentials'; -export * from '../src/cmap/auth/gssapi'; -export * from '../src/cmap/auth/mongo_credentials'; -export * from '../src/cmap/auth/mongodb_aws'; -export * from '../src/cmap/auth/mongodb_oidc'; -export * from '../src/cmap/auth/mongodb_oidc/automated_callback_workflow'; -export * from '../src/cmap/auth/mongodb_oidc/azure_machine_workflow'; -export * from '../src/cmap/auth/mongodb_oidc/callback_workflow'; -export * from '../src/cmap/auth/plain'; -export * from '../src/cmap/auth/providers'; -export * from '../src/cmap/auth/scram'; -export * from '../src/cmap/auth/x509'; -export * from '../src/cmap/command_monitoring_events'; -export * from '../src/cmap/commands'; -export * from '../src/cmap/connect'; -export * from '../src/cmap/connection'; -export * from '../src/cmap/connection_pool'; -export * from '../src/cmap/connection_pool_events'; -export * from '../src/cmap/errors'; -export * from '../src/cmap/handshake/client_metadata'; -export * from '../src/cmap/metrics'; -export * from '../src/cmap/stream_description'; -export * from '../src/cmap/wire_protocol/compression'; -export * from '../src/cmap/wire_protocol/constants'; -export * from '../src/cmap/wire_protocol/on_demand/document'; -export * from '../src/cmap/wire_protocol/responses'; -export * from '../src/cmap/wire_protocol/shared'; -export * from '../src/collection'; -export * from '../src/connection_string'; -export * from '../src/constants'; -export * from '../src/cursor/abstract_cursor'; -export * from '../src/cursor/aggregation_cursor'; -export * from '../src/cursor/change_stream_cursor'; -export * from '../src/cursor/find_cursor'; -export * from '../src/cursor/list_collections_cursor'; -export * from '../src/cursor/list_indexes_cursor'; -export * from '../src/cursor/run_command_cursor'; -export * from '../src/db'; -export * from '../src/deps'; -export * from '../src/encrypter'; -export * from '../src/error'; -export * from '../src/explain'; -export * from '../src/gridfs/download'; -export * from '../src/gridfs/index'; -export * from '../src/gridfs/upload'; -export * from '../src/mongo_client'; -export * from '../src/mongo_logger'; -export * from '../src/mongo_types'; -export * from '../src/operations/aggregate'; -export * from '../src/operations/client_bulk_write/command_builder'; -export * from '../src/operations/client_bulk_write/common'; -export * from '../src/operations/client_bulk_write/results_merger'; -export * from '../src/operations/command'; -export * from '../src/operations/count'; -export * from '../src/operations/create_collection'; -export * from '../src/operations/delete'; -export * from '../src/operations/distinct'; -export * from '../src/operations/drop'; -export * from '../src/operations/estimated_document_count'; -export * from '../src/operations/execute_operation'; -export * from '../src/operations/find'; -export * from '../src/operations/find_and_modify'; -export * from '../src/operations/get_more'; -export * from '../src/operations/indexes'; -export * from '../src/operations/insert'; -export * from '../src/operations/kill_cursors'; -export * from '../src/operations/list_collections'; -export * from '../src/operations/list_databases'; -export * from '../src/operations/operation'; -export * from '../src/operations/profiling_level'; -export * from '../src/operations/remove_user'; -export * from '../src/operations/rename'; -export * from '../src/operations/run_command'; -export * from '../src/operations/search_indexes/create'; -export * from '../src/operations/search_indexes/drop'; -export * from '../src/operations/search_indexes/update'; -export * from '../src/operations/set_profiling_level'; -export * from '../src/operations/stats'; -export * from '../src/operations/update'; -export * from '../src/operations/validate_collection'; -export * from '../src/read_concern'; -export * from '../src/read_preference'; -export * from '../src/sdam/common'; -export * from '../src/sdam/events'; -export * from '../src/sdam/monitor'; -export * from '../src/sdam/server'; -export * from '../src/sdam/server_description'; -export * from '../src/sdam/server_selection'; -export * from '../src/sdam/srv_polling'; -export * from '../src/sdam/topology'; -export * from '../src/sdam/topology_description'; -export * from '../src/sessions'; -export * from '../src/sort'; -export * from '../src/timeout'; -export * from '../src/transactions'; -export * from '../src/utils'; -export * from '../src/write_concern'; - -// Must be last for precedence -export * from '../src/index'; diff --git a/test/tools/mongodb-mock/src/server.js b/test/tools/mongodb-mock/src/server.js index 57ccefb6107..e4cad7bef10 100644 --- a/test/tools/mongodb-mock/src/server.js +++ b/test/tools/mongodb-mock/src/server.js @@ -9,7 +9,7 @@ const Request = require('./request'); const { Query } = require('./protocol'); const EventEmitter = require('events'); const { setTimeout } = require('timers'); -const { HostAddress } = require('../../../mongodb'); +const { HostAddress } = require('../../../../src/utils'); /* * MockServer class diff --git a/test/tools/runner/hooks/legacy_crud_shims.ts b/test/tools/runner/hooks/legacy_crud_shims.ts index 357b0a6d503..5c4bfd8b3fb 100644 --- a/test/tools/runner/hooks/legacy_crud_shims.ts +++ b/test/tools/runner/hooks/legacy_crud_shims.ts @@ -14,25 +14,21 @@ const legacyUsageMaximums = { }; // @ts-expect-error: Method no longer exists on Collection -Collection.prototype.insert = function (docs, options, callback) { +Collection.prototype.insert = function (docs, options) { legacyUsageCounts.insert += 1; - callback = - typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined; options = options != null && typeof options === 'object' ? options : { ordered: false }; docs = Array.isArray(docs) ? docs : [docs]; - return this.insertMany(docs, options, callback); + return this.insertMany(docs, options); }; // @ts-expect-error: Method no longer exists on Collection -Collection.prototype.update = function (filter, update, options, callback) { +Collection.prototype.update = function (filter, update, options) { legacyUsageCounts.update += 1; - callback = - typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined; options = options != null && typeof options === 'object' ? options : {}; - return this.updateMany(filter, update, options, callback); + return this.updateMany(filter, update, options); }; function assertLegacyAPIUsageDoesNotIncrease() { diff --git a/test/tools/spec-runner/index.js b/test/tools/spec-runner/index.js index 40d02fe4c36..3a23c439eb1 100644 --- a/test/tools/spec-runner/index.js +++ b/test/tools/spec-runner/index.js @@ -5,7 +5,7 @@ const chai = require('chai'); const expect = chai.expect; const { EJSON } = require('bson'); -const { isRecord } = require('../../mongodb'); +const { isRecord } = require('../../../src/utils'); const TestRunnerContext = require('./context').TestRunnerContext; const resolveConnectionString = require('./utils').resolveConnectionString; const { @@ -13,7 +13,7 @@ const { CMAP_EVENTS: SOURCE_CMAP_EVENTS, TOPOLOGY_EVENTS, HEARTBEAT_EVENTS -} = require('../../mongodb'); +} = require('../../../src/constants'); const { isAnyRequirementSatisfied } = require('../unified-spec-runner/unified-utils'); const { getCSFLEKMSProviders } = require('../../csfle-kms-providers'); diff --git a/test/tools/unified-spec-runner/entities.ts b/test/tools/unified-spec-runner/entities.ts index f332e2de332..42b9bcd19ef 100644 --- a/test/tools/unified-spec-runner/entities.ts +++ b/test/tools/unified-spec-runner/entities.ts @@ -34,21 +34,20 @@ import { type MongoCredentials, ReadConcern, ReadPreference, - SENSITIVE_COMMANDS, type ServerClosedEvent, type ServerDescriptionChangedEvent, type ServerHeartbeatFailedEvent, type ServerHeartbeatStartedEvent, type ServerHeartbeatSucceededEvent, type ServerOpeningEvent, - Timeout, - TimeoutError, type TopologyClosedEvent, type TopologyDescription, type TopologyDescriptionChangedEvent, type TopologyOpeningEvent, WriteConcern -} from '../../mongodb'; +} from '../../../src'; +import { SENSITIVE_COMMANDS } from '../../../src/cmap/command_monitoring_events'; +import { Timeout, TimeoutError } from '../../../src/timeout'; import { getEncryptExtraOptions, getEnvironmentalOptions } from '../../tools/utils'; import { AlpineTestConfiguration, type TestConfiguration } from '../runner/config'; import { EntityEventRegistry } from './entity_event_registry'; diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index 112748a10a8..9c61ccac1ce 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -38,7 +38,7 @@ import { TopologyClosedEvent, TopologyDescriptionChangedEvent, TopologyOpeningEvent -} from '../../mongodb'; +} from '../../../src'; import { ejson } from '../utils'; import { type CmapEvent, type CommandEvent, type EntitiesMap, type SdamEvent } from './entities'; import { diff --git a/test/tools/unified-spec-runner/runner.ts b/test/tools/unified-spec-runner/runner.ts index aefe740747a..a5d8f332cdc 100644 --- a/test/tools/unified-spec-runner/runner.ts +++ b/test/tools/unified-spec-runner/runner.ts @@ -4,13 +4,13 @@ import { gte as semverGte, satisfies as semverSatisfies } from 'semver'; import { type MongoClient, - MONGODB_ERROR_CODES, MongoParseError, MongoServerError, - ns, ReadPreference, TopologyType -} from '../../mongodb'; +} from '../../../src'; +import { MONGODB_ERROR_CODES } from '../../../src/error'; +import { ns } from '../../../src/utils'; import { ejson } from '../utils'; import { AstrolabeResultsWriter } from './astrolabe_results_writer'; import { EntitiesMap, type UnifiedMongoClient } from './entities'; diff --git a/test/tools/unified-spec-runner/schema.ts b/test/tools/unified-spec-runner/schema.ts index 0f7e048b17b..7b03f0f0d12 100644 --- a/test/tools/unified-spec-runner/schema.ts +++ b/test/tools/unified-spec-runner/schema.ts @@ -10,7 +10,7 @@ import type { TagSet, TopologyType, W -} from '../../mongodb'; +} from '../../../src'; import { type TestConfiguration } from '../runner/config'; import { type UnifiedThread } from './entities'; diff --git a/test/tools/unified-spec-runner/unified-utils.ts b/test/tools/unified-spec-runner/unified-utils.ts index 1b599a7ed9d..d259a89245f 100644 --- a/test/tools/unified-spec-runner/unified-utils.ts +++ b/test/tools/unified-spec-runner/unified-utils.ts @@ -3,17 +3,17 @@ import ConnectionString from 'mongodb-connection-string-url'; import { coerce, gte as semverGte, lte as semverLte } from 'semver'; import { isDeepStrictEqual } from 'util'; -import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; -import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { type AutoEncryptionOptions, type CollectionOptions, type DbOptions, type Document, - getMongoDBClientEncryption, type MongoClient, ReturnDocument -} from '../../mongodb'; +} from '../../../src'; +import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; +import { getMongoDBClientEncryption } from '../../../src/deps'; +import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import type { CmapEvent, CommandEvent, EntitiesMap, SdamEvent } from './entities'; import { matchesEvents } from './match'; import { MalformedOperationError } from './operations'; diff --git a/test/tools/utils.ts b/test/tools/utils.ts index 7720b3167d6..eed0fde5f17 100644 --- a/test/tools/utils.ts +++ b/test/tools/utils.ts @@ -293,14 +293,13 @@ export function topologyWithPlaceholderClient( export async function itInNodeProcess( title: string, - fn: (d: { expect: typeof import('chai').expect; mongodb: typeof import('../mongodb') }) => void + fn: (d: { expect: typeof import('chai').expect }) => void ) { it(title, async () => { const script = ` import { expect } from 'chai'; - import * as mongodb from './test/mongodb'; const run = ${fn}; - run({ expect, mongodb }).then( + run({ expect }).then( () => { process.exitCode = 0; }, diff --git a/test/unit/sdam/topology.test.ts b/test/unit/sdam/topology.test.ts index d53fa6cad42..cf0511a8437 100644 --- a/test/unit/sdam/topology.test.ts +++ b/test/unit/sdam/topology.test.ts @@ -6,6 +6,7 @@ import { satisfies } from 'semver'; import * as sinon from 'sinon'; import { clearTimeout } from 'timers'; +import { ConnectionPool } from '../../../src/cmap/connection_pool'; import { makeClientMetadata } from '../../../src/cmap/handshake/client_metadata'; import { LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE, @@ -25,7 +26,6 @@ import { Topology } from '../../../src/sdam/topology'; import { TopologyDescription } from '../../../src/sdam/topology_description'; import { TimeoutContext } from '../../../src/timeout'; import { isHello, ns } from '../../../src/utils'; -import { ConnectionPool } from '../../mongodb'; import * as mock from '../../tools/mongodb-mock/index'; import { topologyWithPlaceholderClient } from '../../tools/utils'; From 4ee24994eaf0fa9811fd4937511812ba01311ef4 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Thu, 30 Oct 2025 13:23:17 +0100 Subject: [PATCH 2/3] test(NODE-7280): use mongodb native driver public interface --- .../node-specific/resource_tracking_script_builder.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/integration/node-specific/resource_tracking_script_builder.ts b/test/integration/node-specific/resource_tracking_script_builder.ts index 2a985c71576..bf634a58d08 100644 --- a/test/integration/node-specific/resource_tracking_script_builder.ts +++ b/test/integration/node-specific/resource_tracking_script_builder.ts @@ -9,23 +9,24 @@ import { AssertionError, expect } from 'chai'; import type * as timers from 'timers'; import { parseSnapshot } from 'v8-heapsnapshot'; -import { type MongoClient } from '../../../src'; +import type * as mongodb from '../../../src'; import { type TestConfiguration } from '../../tools/runner/config'; import { type sleep } from '../../tools/utils'; export type ResourceTestFunction = HeapResourceTestFunction | ProcessResourceTestFunction; export type HeapResourceTestFunction = (options: { - MongoClient: typeof MongoClient; + MongoClient: typeof mongodb.MongoClient; uri: string; iteration: number; }) => Promise; export type ProcessResourceTestFunction = (options: { - MongoClient: typeof MongoClient; + MongoClient: typeof mongodb.MongoClient; uri?: string; log?: (out: any) => void; expect: typeof expect; + mongodb?: typeof mongodb; sleep?: typeof sleep; getTimerCount?: () => number; timers?: typeof timers; From 33ff656dbef61c19bc451253d2f8fd92c0ba7bc3 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Thu, 30 Oct 2025 13:25:40 +0100 Subject: [PATCH 3/3] test(NODE-7280): do not modify original "use strict;" usage --- test/integration/node-specific/examples/transactions.test.js | 2 ++ test/integration/node-specific/examples/versioned_api.js | 1 + 2 files changed, 3 insertions(+) diff --git a/test/integration/node-specific/examples/transactions.test.js b/test/integration/node-specific/examples/transactions.test.js index ed26b31979d..c2e66a0d39a 100644 --- a/test/integration/node-specific/examples/transactions.test.js +++ b/test/integration/node-specific/examples/transactions.test.js @@ -1,3 +1,5 @@ +'use strict'; + const { MongoClient } = require('mongodb'); // Yes, we are shadowing a global here but we are not actually ever printing anything in this file diff --git a/test/integration/node-specific/examples/versioned_api.js b/test/integration/node-specific/examples/versioned_api.js index be111bb1b24..b812964aac3 100644 --- a/test/integration/node-specific/examples/versioned_api.js +++ b/test/integration/node-specific/examples/versioned_api.js @@ -1,3 +1,4 @@ +'use strict'; const { MongoClient } = require('mongodb'); describe('examples.versionedApi:', function () {