From 1dc105071a120d203d92642e62b9911b3653b94a Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Thu, 18 Sep 2025 09:17:00 -0700 Subject: [PATCH 1/5] test(NODE-7160): migrate `node-mongodb-native/test/unit/assorted` tests --- .eslintrc.json | 2 - test/benchmarks/unitBench/list.bench.js | 3 +- test/integration/auth/mongodb_aws.test.ts | 1 - ...nt_side_encryption.prose.06.corpus.test.ts | 1 - ..._side_encryption.prose.12.deadlock.test.ts | 1 - ...ryption.prose.14.decryption_events.test.ts | 1 - ..._encryption.prose.17.on_demand_gcp.test.ts | 1 - ...ion.prose.18.azure_kms_mock_server.test.ts | 2 - ...ncryption.prose.19.on_demand_azure.test.ts | 2 - ....21.automatic_data_encryption_keys.test.ts | 2 - ...prose.22.range_explicit_encryption.test.ts | 2 - ...prose.23.range_encryption_defaults.test.ts | 1 - ...26.custom_aws_credential_providers.test.ts | 1 - .../client_side_encryption.prose.test.ts | 1 - .../client-side-encryption/driver.test.ts | 1 - ...lient_side_operations_timeout.unit.test.ts | 1 - .../node-specific/client_encryption.test.ts | 3 - test/mongodb.ts | 1 - test/tools/fixtures/shared_library_test.js | 5 +- .../unified-spec-runner/unified-utils.ts | 1 - test/unit/assorted/client.test.js | 4 +- test/unit/assorted/collations.test.js | 6 +- test/unit/assorted/max_staleness.spec.test.js | 7 +- test/unit/assorted/optional_require.test.ts | 14 +- ...records_for_mongos_discovery.prose.test.ts | 20 +-- test/unit/assorted/scram_iterations.test.ts | 11 +- ...rver_discovery_and_monitoring.spec.test.ts | 41 ++--- .../server_discovery_and_monitoring.test.ts | 16 +- .../assorted/server_selection.spec.test.ts | 2 +- .../server_selection_latency_window_utils.ts | 12 +- .../server_selection_logic_spec_utils.ts | 14 +- .../assorted/server_selection_spec_helper.js | 19 +- test/unit/assorted/sessions_client.test.js | 167 +++++++++--------- .../unit/assorted/sessions_collection.test.js | 4 +- test/unit/assorted/wire_version.test.ts | 9 +- test/unit/assorted/write_concern.test.js | 9 +- .../auto_encrypter.test.ts | 4 - .../client_encryption.test.ts | 4 - .../client-side-encryption/errors.test.ts | 1 - .../mongocryptd_manager.test.ts | 1 - .../providers/credentialsProvider.test.ts | 5 - .../requirements.helper.ts | 1 - .../state_machine.test.ts | 2 - .../automated_callback_workflow.test.ts | 2 - .../azure_machine_workflow.test.ts | 1 - .../mongodb_oidc/gcp_machine_workflow.test.ts | 1 - .../token_machine_workflow.test.ts | 1 - test/unit/commands.test.ts | 1 - test/unit/error.test.ts | 2 - test/unit/index.test.ts | 1 - 50 files changed, 169 insertions(+), 246 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index adf89319dca..59b2beaa206 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -178,7 +178,6 @@ { "patterns": [ "**/../lib/**", - "**/../src/**", "mongodb-mock-server" ] } @@ -217,7 +216,6 @@ { "patterns": [ "**/../lib/**", - "**/../src/**", "mongodb-mock-server" ] } diff --git a/test/benchmarks/unitBench/list.bench.js b/test/benchmarks/unitBench/list.bench.js index 025e531275e..7e1a8fba4c5 100644 --- a/test/benchmarks/unitBench/list.bench.js +++ b/test/benchmarks/unitBench/list.bench.js @@ -1,6 +1,5 @@ -/* eslint-disable no-restricted-modules */ const chalk = require('chalk'); -const { List } = require('../../../lib/utils'); +const { List } = require('../../../src/utils'); const { createHistogram } = require('perf_hooks'); const iterations = 100; diff --git a/test/integration/auth/mongodb_aws.test.ts b/test/integration/auth/mongodb_aws.test.ts index e65b9c60bda..18951514071 100644 --- a/test/integration/auth/mongodb_aws.test.ts +++ b/test/integration/auth/mongodb_aws.test.ts @@ -5,7 +5,6 @@ import * as http from 'http'; import { performance } from 'perf_hooks'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers'; import { AWSTemporaryCredentialProvider, diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts index c90ec8e888e..41c7c8cb94c 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts @@ -5,7 +5,6 @@ import { expect } from 'chai'; import * as fs from 'fs'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { type MongoClient, WriteConcern } from '../../mongodb'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts index 972bbb80f37..1c54b136c24 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import { readFileSync } from 'fs'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { type CommandStartedEvent, type MongoClient, type MongoClientOptions } from '../../mongodb'; import { type TestConfiguration } from '../../tools/runner/config'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts index e3b4e4cb97e..9901cb08820 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { Binary, diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.17.on_demand_gcp.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.17.on_demand_gcp.test.ts index 98c204fb2e3..566809cc2b5 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.17.on_demand_gcp.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.17.on_demand_gcp.test.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; import { env } from 'process'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { Binary } from '../../mongodb'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.18.azure_kms_mock_server.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.18.azure_kms_mock_server.test.ts index c99820b6f83..7b4c92ad53a 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.18.azure_kms_mock_server.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.18.azure_kms_mock_server.test.ts @@ -1,8 +1,6 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongoCryptAzureKMSRequestError } from '../../../src/client-side-encryption/errors'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { type AzureKMSRequestOptions, fetchAzureKMSToken diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.19.on_demand_azure.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.19.on_demand_azure.test.ts index aba12464f8a..b0b93d7655b 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.19.on_demand_azure.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.19.on_demand_azure.test.ts @@ -1,9 +1,7 @@ import { expect } from 'chai'; import { env } from 'process'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { MongoCryptAzureKMSRequestError } from '../../../src/client-side-encryption/errors'; import { Binary } from '../../mongodb'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.21.automatic_data_encryption_keys.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.21.automatic_data_encryption_keys.test.ts index f81ab73d982..24afe0e7315 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.21.automatic_data_encryption_keys.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.21.automatic_data_encryption_keys.test.ts @@ -1,8 +1,6 @@ import { expect } from 'chai'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { MongoCryptCreateEncryptedCollectionError } from '../../../src/client-side-encryption/errors'; import { getCSFLEKMSProviders, diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts index 3e23c685b43..08ab2bb096b 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts @@ -4,9 +4,7 @@ import { readFile } from 'fs/promises'; import { join } from 'path'; import { Decimal128, type Document, Double, Long, type MongoClient } from '../../../src'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { MongoCryptError } from '../../../src/client-side-encryption/errors'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.23.range_encryption_defaults.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.23.range_encryption_defaults.test.ts index ea4041f746b..c6deedc2f8d 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.23.range_encryption_defaults.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.23.range_encryption_defaults.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { type Binary, Int32, Long } from '../../mongodb'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.26.custom_aws_credential_providers.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.26.custom_aws_credential_providers.test.ts index 59e32946baf..c1c3cac59d3 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.26.custom_aws_credential_providers.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.26.custom_aws_credential_providers.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { AWSTemporaryCredentialProvider, Binary, MongoClient } from '../../mongodb'; import { getEncryptExtraOptions } from '../../tools/utils'; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.test.ts index eaf1746f2b7..7d326fcaa15 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import * as fs from 'fs/promises'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { diff --git a/test/integration/client-side-encryption/driver.test.ts b/test/integration/client-side-encryption/driver.test.ts index ffa0e69b97f..a7a5a9f8e7d 100644 --- a/test/integration/client-side-encryption/driver.test.ts +++ b/test/integration/client-side-encryption/driver.test.ts @@ -6,7 +6,6 @@ import * as sinon from 'sinon'; import { setTimeout } from 'timers/promises'; import * as tls from 'tls'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { diff --git a/test/integration/client-side-operations-timeout/client_side_operations_timeout.unit.test.ts b/test/integration/client-side-operations-timeout/client_side_operations_timeout.unit.test.ts index 73db0b9191d..0eef0318bac 100644 --- a/test/integration/client-side-operations-timeout/client_side_operations_timeout.unit.test.ts +++ b/test/integration/client-side-operations-timeout/client_side_operations_timeout.unit.test.ts @@ -10,7 +10,6 @@ import { setTimeout } from 'timers'; import { TLSSocket } from 'tls'; import { promisify } from 'util'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { StateMachine } from '../../../src/client-side-encryption/state_machine'; import { Connection, diff --git a/test/integration/node-specific/client_encryption.test.ts b/test/integration/node-specific/client_encryption.test.ts index d21de71a56f..90800f92903 100644 --- a/test/integration/node-specific/client_encryption.test.ts +++ b/test/integration/node-specific/client_encryption.test.ts @@ -2,14 +2,11 @@ import { expect } from 'chai'; import { readFileSync } from 'fs'; import * as sinon from 'sinon'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption, type DataKey } from '../../../src/client-side-encryption/client_encryption'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { MongoCryptInvalidArgumentError } from '../../../src/client-side-encryption/errors'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { StateMachine } from '../../../src/client-side-encryption/state_machine'; import { Binary, type Collection, Int32, Long, type MongoClient, UUID } from '../../mongodb'; diff --git a/test/mongodb.ts b/test/mongodb.ts index 9c385b21c2b..4be7c6d2ce3 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-restricted-imports */ import * as fs from 'node:fs'; import * as path from 'node:path'; import * as process from 'node:process'; diff --git a/test/tools/fixtures/shared_library_test.js b/test/tools/fixtures/shared_library_test.js index e87140a4834..5a334bc98e6 100644 --- a/test/tools/fixtures/shared_library_test.js +++ b/test/tools/fixtures/shared_library_test.js @@ -1,7 +1,6 @@ -/* eslint-disable no-restricted-modules */ const { EJSON } = require('bson'); -const { AutoEncrypter } = require('../../../lib/client-side-encryption/auto_encrypter'); -const { MongoClient } = require('../../../lib/mongo_client'); +const { AutoEncrypter } = require('../../../src/client-side-encryption/auto_encrypter'); +const { MongoClient } = require('../../../src/mongo_client'); try { const extraOptions = JSON.parse(process.env.EXTRA_OPTIONS); diff --git a/test/tools/unified-spec-runner/unified-utils.ts b/test/tools/unified-spec-runner/unified-utils.ts index 79ba247f8e0..1b599a7ed9d 100644 --- a/test/tools/unified-spec-runner/unified-utils.ts +++ b/test/tools/unified-spec-runner/unified-utils.ts @@ -3,7 +3,6 @@ import ConnectionString from 'mongodb-connection-string-url'; import { coerce, gte as semverGte, lte as semverLte } from 'semver'; import { isDeepStrictEqual } from 'util'; -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; import { getCSFLEKMSProviders } from '../../csfle-kms-providers'; import { diff --git a/test/unit/assorted/client.test.js b/test/unit/assorted/client.test.js index 530b3931570..9d40b7decd4 100644 --- a/test/unit/assorted/client.test.js +++ b/test/unit/assorted/client.test.js @@ -2,8 +2,8 @@ const { expect } = require('chai'); const mock = require('../../tools/mongodb-mock/index'); -const { MongoClient } = require('../../mongodb'); -const { isHello } = require('../../mongodb'); +const { isHello } = require('../../../src/utils'); +const { MongoClient } = require('../../../src/mongo_client'); describe('Client (unit)', function () { let server, client; diff --git a/test/unit/assorted/collations.test.js b/test/unit/assorted/collations.test.js index 124d020afcf..6efc253c93b 100644 --- a/test/unit/assorted/collations.test.js +++ b/test/unit/assorted/collations.test.js @@ -1,9 +1,9 @@ 'use strict'; const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); -const { Long } = require('../../mongodb'); -const { isHello } = require('../../mongodb'); -const { MongoClient } = require('../../mongodb'); +const { Long } = require('../../../src/bson'); +const { isHello } = require('../../../src/utils'); +const { MongoClient } = require('../../../src/mongo_client'); const testContext = {}; describe('Collation', function () { diff --git a/test/unit/assorted/max_staleness.spec.test.js b/test/unit/assorted/max_staleness.spec.test.js index f0355cb1cce..bb4b2a4d9db 100644 --- a/test/unit/assorted/max_staleness.spec.test.js +++ b/test/unit/assorted/max_staleness.spec.test.js @@ -2,7 +2,7 @@ const path = require('path'); const fs = require('fs'); const { executeServerSelectionTest } = require('./server_selection_spec_helper'); -const { Server } = require('../../mongodb'); +const { Server } = require('../../../src/sdam/server'); // src/sdam/server.ts const { EJSON } = require('bson'); @@ -47,10 +47,11 @@ describe('Max Staleness (spec)', function () { const specTests = collectStalenessTests(maxStalenessDir); for (const [specTestName, test] of Object.entries(specTests)) { describe(specTestName, () => { - for (const testData of test) + for (const testData of test) { it(testData.description, async function () { - return executeServerSelectionTest(testData); + await executeServerSelectionTest(testData); }); + } }); } }); diff --git a/test/unit/assorted/optional_require.test.ts b/test/unit/assorted/optional_require.test.ts index 83eb32cfc24..0a729d6fd4f 100644 --- a/test/unit/assorted/optional_require.test.ts +++ b/test/unit/assorted/optional_require.test.ts @@ -2,14 +2,12 @@ import { expect } from 'chai'; import { existsSync } from 'fs'; import { resolve } from 'path'; -import { - AuthContext, - compress, - GSSAPI, - HostAddress, - MongoDBAWS, - MongoMissingDependencyError -} from '../../mongodb'; +import { AuthContext } from '../../../src/cmap/auth/auth_provider'; +import { GSSAPI } from '../../../src/cmap/auth/gssapi'; +import { MongoDBAWS } from '../../../src/cmap/auth/mongodb_aws'; +import { compress } from '../../../src/cmap/wire_protocol/compression'; +import { MongoMissingDependencyError } from '../../../src/error'; +import { HostAddress } from '../../../src/utils'; function moduleExistsSync(moduleName) { return existsSync(resolve(__dirname, `../../../node_modules/${moduleName}`)); diff --git a/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts b/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts index 8ec5cd8e29c..ae2a8116795 100644 --- a/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts +++ b/test/unit/assorted/polling_srv_records_for_mongos_discovery.prose.test.ts @@ -4,17 +4,11 @@ import { once } from 'events'; import { satisfies } from 'semver'; import * as sinon from 'sinon'; -import { - HostAddress, - isHello, - MongoClient, - SrvPoller, - type SrvPollerOptions, - SrvPollingEvent, - type Topology, - type TopologyOptions, - TopologyType -} from '../../mongodb'; +import { MongoClient } from '../../../src/mongo_client'; +import { TopologyType } from '../../../src/sdam/common'; +import { SrvPoller, type SrvPollerOptions, SrvPollingEvent } from '../../../src/sdam/srv_polling'; +import type { Topology, TopologyOptions } from '../../../src/sdam/topology'; +import { HostAddress, isHello } from '../../../src/utils'; import * as mock from '../../tools/mongodb-mock/index'; import type { MockServer } from '../../tools/mongodb-mock/src/server'; import { processTick, topologyWithPlaceholderClient } from '../../tools/utils'; @@ -75,10 +69,10 @@ describe('Polling Srv Records for Mongos Discovery', () => { } class FakeSrvPoller extends SrvPoller { - start() { + override start() { return; } - stop() { + override stop() { return; } trigger(srvRecords) { diff --git a/test/unit/assorted/scram_iterations.test.ts b/test/unit/assorted/scram_iterations.test.ts index 106550ae106..c28c6cf30be 100644 --- a/test/unit/assorted/scram_iterations.test.ts +++ b/test/unit/assorted/scram_iterations.test.ts @@ -1,12 +1,9 @@ import { expect } from 'chai'; -import { - isHello, - MongoClient, - MongoCredentials, - MongoNetworkError, - MongoRuntimeError -} from '../../mongodb'; +import { MongoCredentials } from '../../../src/cmap/auth/mongo_credentials'; +import { MongoNetworkError, MongoRuntimeError } from '../../../src/error'; +import { MongoClient } from '../../../src/mongo_client'; +import { isHello } from '../../../src/utils'; import * as mock from '../../tools/mongodb-mock/index'; describe('SCRAM Iterations Tests', function () { diff --git a/test/unit/assorted/server_discovery_and_monitoring.spec.test.ts b/test/unit/assorted/server_discovery_and_monitoring.spec.test.ts index d4df5685f7d..62a545417bb 100644 --- a/test/unit/assorted/server_discovery_and_monitoring.spec.test.ts +++ b/test/unit/assorted/server_discovery_and_monitoring.spec.test.ts @@ -1,42 +1,43 @@ -import { EJSON, ObjectId } from 'bson'; +import { type Document, EJSON, ObjectId } from 'bson'; import { expect } from 'chai'; import * as fs from 'fs'; import * as path from 'path'; import * as sinon from 'sinon'; +import { ConnectionPool } from '../../../src/cmap/connection_pool'; import { - ConnectionPool, HEARTBEAT_EVENTS, - isRecord, - MongoClient, + SERVER_CLOSED, + SERVER_DESCRIPTION_CHANGED, + SERVER_OPENING, + TOPOLOGY_CLOSED, + TOPOLOGY_DESCRIPTION_CHANGED, + TOPOLOGY_OPENING +} from '../../../src/constants'; +import { MongoCompatibilityError, MongoError, MongoNetworkError, MongoNetworkTimeoutError, - MongoServerError, - ns, - RunCommandOperation, - Server, - SERVER_CLOSED, - SERVER_DESCRIPTION_CHANGED, - SERVER_OPENING, + MongoServerError +} from '../../../src/error'; +import { MongoClient } from '../../../src/mongo_client'; +import { RunCommandOperation } from '../../../src/operations/run_command'; +import { ServerClosedEvent, - ServerDescription, ServerDescriptionChangedEvent, ServerHeartbeatFailedEvent, ServerHeartbeatStartedEvent, ServerHeartbeatSucceededEvent, ServerOpeningEvent, - squashError, - Topology, - TOPOLOGY_CLOSED, - TOPOLOGY_DESCRIPTION_CHANGED, - TOPOLOGY_OPENING, TopologyClosedEvent, TopologyDescriptionChangedEvent, - TopologyOpeningEvent, - type TopologyVersion -} from '../../mongodb'; + TopologyOpeningEvent +} from '../../../src/sdam/events'; +import { Server } from '../../../src/sdam/server'; +import { ServerDescription, type TopologyVersion } from '../../../src/sdam/server_description'; +import { Topology } from '../../../src/sdam/topology'; +import { isRecord, ns, squashError } from '../../../src/utils'; import { ejson } from '../../tools/utils'; const SDAM_EVENT_CLASSES = { diff --git a/test/unit/assorted/server_discovery_and_monitoring.test.ts b/test/unit/assorted/server_discovery_and_monitoring.test.ts index 1c58591fb85..2f6e312594f 100644 --- a/test/unit/assorted/server_discovery_and_monitoring.test.ts +++ b/test/unit/assorted/server_discovery_and_monitoring.test.ts @@ -1,15 +1,13 @@ +import { ObjectId } from 'bson'; import { expect } from 'chai'; -import { type TopologyDescription } from 'mongodb-legacy'; import * as sinon from 'sinon'; -import { - MongoClient, - ObjectId, - Server, - ServerDescription, - Topology, - type TopologyDescriptionChangedEvent -} from '../../mongodb'; +import { MongoClient } from '../../../src/mongo_client'; +import { type TopologyDescriptionChangedEvent } from '../../../src/sdam/events'; +import { Server } from '../../../src/sdam/server'; +import { ServerDescription } from '../../../src/sdam/server_description'; +import { Topology } from '../../../src/sdam/topology'; +import { type TopologyDescription } from '../../../src/sdam/topology_description'; describe('Server Discovery and Monitoring', function () { let serverConnect: sinon.SinonStub; diff --git a/test/unit/assorted/server_selection.spec.test.ts b/test/unit/assorted/server_selection.spec.test.ts index 44707aa7580..46ce5bbd677 100644 --- a/test/unit/assorted/server_selection.spec.test.ts +++ b/test/unit/assorted/server_selection.spec.test.ts @@ -1,7 +1,7 @@ import { join, resolve } from 'path'; import * as sinon from 'sinon'; -import { Server } from '../../mongodb'; +import { Server } from '../../../src/sdam/server'; import { loadLatencyWindowTests, runServerSelectionLatencyWindowTest diff --git a/test/unit/assorted/server_selection_latency_window_utils.ts b/test/unit/assorted/server_selection_latency_window_utils.ts index 9aa8dd24818..da4e8463569 100644 --- a/test/unit/assorted/server_selection_latency_window_utils.ts +++ b/test/unit/assorted/server_selection_latency_window_utils.ts @@ -3,14 +3,10 @@ import { expect } from 'chai'; import { readdirSync, readFileSync } from 'fs'; import { join } from 'path'; -import { - ReadPreference, - type Server, - type ServerType, - STATE_CONNECTED, - type Topology, - type TopologyType -} from '../../mongodb'; +import { ReadPreference } from '../../../src/read_preference'; +import { type ServerType, STATE_CONNECTED, type TopologyType } from '../../../src/sdam/common'; +import { type Server } from '../../../src/sdam/server'; +import { type Topology } from '../../../src/sdam/topology'; import { topologyWithPlaceholderClient } from '../../tools/utils'; import { serverDescriptionFromDefinition } from './server_selection_spec_helper'; diff --git a/test/unit/assorted/server_selection_logic_spec_utils.ts b/test/unit/assorted/server_selection_logic_spec_utils.ts index d489c682102..62a31fba189 100644 --- a/test/unit/assorted/server_selection_logic_spec_utils.ts +++ b/test/unit/assorted/server_selection_logic_spec_utils.ts @@ -6,15 +6,15 @@ import { basename, extname, join } from 'path'; import { ReadPreference, type ReadPreferenceMode, - type ReadPreferenceOptions, + type ReadPreferenceOptions +} from '../../../src/read_preference'; +import { type ServerType, type TopologyType } from '../../../src/sdam/common'; +import { type ServerDescription, type TagSet } from '../../../src/sdam/server_description'; +import { readPreferenceServerSelector, - type ServerDescription, - type ServerType, - type TagSet, - TopologyDescription, - type TopologyType, writableServerSelector -} from '../../mongodb'; +} from '../../../src/sdam/server_selection'; +import { TopologyDescription } from '../../../src/sdam/topology_description'; import { serverDescriptionFromDefinition } from './server_selection_spec_helper'; interface ServerSelectionLogicTestServer { diff --git a/test/unit/assorted/server_selection_spec_helper.js b/test/unit/assorted/server_selection_spec_helper.js index 20bcea87a23..0dccbeb7446 100644 --- a/test/unit/assorted/server_selection_spec_helper.js +++ b/test/unit/assorted/server_selection_spec_helper.js @@ -1,16 +1,17 @@ 'use strict'; -const { Topology } = require('../../mongodb'); -const { ServerType, TopologyType } = require('../../mongodb'); -const { ServerDescription } = require('../../mongodb'); -const { ReadPreference } = require('../../mongodb'); -const { MongoServerSelectionError } = require('../../mongodb'); -const ServerSelectors = require('../../mongodb'); + +import { MongoServerSelectionError } from '../../../src/error'; +import { ReadPreference } from '../../../src/read_preference'; +import { ServerType, TopologyType } from '../../../src/sdam/common'; +import { ServerDescription } from '../../../src/sdam/server_description'; +import * as ServerSelectors from '../../../src/sdam/server_selection'; // src/sdam/server_selection.ts +import { Topology } from '../../../src/sdam/topology'; const sinon = require('sinon'); const { expect } = require('chai'); const { topologyWithPlaceholderClient } = require('../../tools/utils'); -function serverDescriptionFromDefinition(definition, hosts) { +export function serverDescriptionFromDefinition(definition, hosts) { hosts = hosts || []; const serverType = definition.type; @@ -80,7 +81,7 @@ function readPreferenceFromDefinition(definition) { return new ReadPreference(mode, tags, options); } -async function executeServerSelectionTest(testDefinition) { +export async function executeServerSelectionTest(testDefinition) { const topologyDescription = testDefinition.topology_description; const seedData = topologyDescription.servers.reduce( (result, seed) => { @@ -183,5 +184,3 @@ async function executeServerSelectionTest(testDefinition) { topology.close(); } } - -module.exports = { executeServerSelectionTest, serverDescriptionFromDefinition }; diff --git a/test/unit/assorted/sessions_client.test.js b/test/unit/assorted/sessions_client.test.js index 1b806543396..8f4eabc6353 100644 --- a/test/unit/assorted/sessions_client.test.js +++ b/test/unit/assorted/sessions_client.test.js @@ -3,21 +3,20 @@ const expect = require('chai').expect; const mock = require('../../tools/mongodb-mock/index'); const { ReplSetFixture } = require('../../tools/common'); -const { isHello } = require('../../mongodb'); -const { MongoClient } = require('../../mongodb'); +const { isHello } = require('../../../src/utils'); +const { MongoClient } = require('../../../src/mongo_client'); const test = {}; describe('Sessions - client/unit', function () { describe('Client', function () { - afterEach(() => mock.cleanup()); + afterEach(async () => await mock.cleanup()); - beforeEach(() => { - return mock.createServer().then(server => { - test.server = server; - }); + beforeEach(async () => { + const server = await mock.createServer(); + test.server = server; }); - it('should not throw a synchronous exception if sessions are not supported', function () { + it('should not throw a synchronous exception if sessions are not supported', async function () { test.server.setMessageHandler(request => { var doc = request.document; if (isHello(doc)) { @@ -28,84 +27,78 @@ describe('Sessions - client/unit', function () { }); const client = new MongoClient(`mongodb://${test.server.uri()}/test`); - return client.connect().then(() => { - expect(() => client.startSession()).to.not.throw( - 'Current topology does not support sessions' - ); - return client.close(); - }); + await client.connect(); + expect(() => client.startSession()).to.not.throw( + 'Current topology does not support sessions' + ); + await client.close(); }); - it('should throw an exception if sessions are not supported on some servers', function () { + it('should throw an exception if sessions are not supported on some servers', async function () { const replicaSetMock = new ReplSetFixture(); - let testClient; - return replicaSetMock - .setup({ doNotInitHandlers: true }) - .then(() => { - replicaSetMock.firstSecondaryServer.setMessageHandler(request => { - var doc = request.document; - if (isHello(doc)) { - const hello = replicaSetMock.firstSecondaryStates[0]; - hello.logicalSessionTimeoutMinutes = 20; - request.reply(hello); - } else if (doc.endSessions) { - request.reply({ ok: 1 }); - } - }); - - replicaSetMock.secondSecondaryServer.setMessageHandler(request => { - var doc = request.document; - if (isHello(doc)) { - const hello = replicaSetMock.secondSecondaryStates[0]; - hello.logicalSessionTimeoutMinutes = 10; - request.reply(hello); - } else if (doc.endSessions) { - request.reply({ ok: 1 }); - } - }); - - replicaSetMock.arbiterServer.setMessageHandler(request => { - var doc = request.document; - if (isHello(doc)) { - const hello = replicaSetMock.arbiterStates[0]; - hello.logicalSessionTimeoutMinutes = 30; - request.reply(hello); - } else if (doc.endSessions) { - request.reply({ ok: 1 }); - } - }); - - replicaSetMock.primaryServer.setMessageHandler(request => { - var doc = request.document; - if (isHello(doc)) { - const hello = replicaSetMock.primaryStates[0]; - hello.logicalSessionTimeoutMinutes = null; - request.reply(hello); - } else if (doc.endSessions) { - request.reply({ ok: 1 }); - } - }); - - return replicaSetMock.uri(); - }) - .then(uri => { - testClient = new MongoClient(uri); - return testClient.connect(); - }) - .then(client => { - const session = client.startSession(); - return client.db().collection('t').insertOne({ a: 1 }, { session }); - }) - .then(() => { - expect.fail('Expected an error to be thrown about not supporting sessions'); - }) - .catch(error => { - expect(error.message).to.equal('Current topology does not support sessions'); - }) - .finally(() => (testClient ? testClient.close() : null)); + await replicaSetMock.setup({ doNotInitHandlers: true }); + + replicaSetMock.firstSecondaryServer.setMessageHandler(request => { + var doc = request.document; + if (isHello(doc)) { + const hello = replicaSetMock.firstSecondaryStates[0]; + hello.logicalSessionTimeoutMinutes = 20; + request.reply(hello); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); + } + }); + + replicaSetMock.secondSecondaryServer.setMessageHandler(request => { + var doc = request.document; + if (isHello(doc)) { + const hello = replicaSetMock.secondSecondaryStates[0]; + hello.logicalSessionTimeoutMinutes = 10; + request.reply(hello); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); + } + }); + + replicaSetMock.arbiterServer.setMessageHandler(request => { + var doc = request.document; + if (isHello(doc)) { + const hello = replicaSetMock.arbiterStates[0]; + hello.logicalSessionTimeoutMinutes = 30; + request.reply(hello); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); + } + }); + + replicaSetMock.primaryServer.setMessageHandler(request => { + var doc = request.document; + if (isHello(doc)) { + const hello = replicaSetMock.primaryStates[0]; + hello.logicalSessionTimeoutMinutes = null; + request.reply(hello); + } else if (doc.endSessions) { + request.reply({ ok: 1 }); + } + }); + + const uri = replicaSetMock.uri(); + + const client = new MongoClient(uri); + await client.connect(); + const session = client.startSession(); + + try { + await client.db().collection('t').insertOne({ a: 1 }, { session }); + expect.fail('Expected an error to be thrown about not supporting sessions'); + } catch (error) { + expect(error.message).to.equal('Current topology does not support sessions'); + } finally { + await client.close(); + } }); - it('should return a client session when requested if the topology supports it', function (done) { + it('should return a client session when requested if the topology supports it', async function () { test.server.setMessageHandler(request => { var doc = request.document; if (isHello(doc)) { @@ -120,14 +113,12 @@ describe('Sessions - client/unit', function () { }); const client = new MongoClient(`mongodb://${test.server.uri()}/test`); - client.connect(function (err, client) { - expect(err).to.not.exist; - let session = client.startSession(); - expect(session).to.exist; + await client.connect(); - session.endSession({ skipCommand: true }); - client.close(done); - }); + let session = client.startSession(); + expect(session).to.exist; + session.endSession({ skipCommand: true }); + client.close(); }); }); }); diff --git a/test/unit/assorted/sessions_collection.test.js b/test/unit/assorted/sessions_collection.test.js index e7711efb6b5..736d0e8be1d 100644 --- a/test/unit/assorted/sessions_collection.test.js +++ b/test/unit/assorted/sessions_collection.test.js @@ -2,8 +2,8 @@ const { Timestamp } = require('bson'); const { expect } = require('chai'); const mock = require('../../tools/mongodb-mock/index'); -const { isHello } = require('../../mongodb'); -const { MongoClient } = require('../../mongodb'); +import { MongoClient } from '../../../lib'; +import { isHello } from '../../../lib/utils'; const test = {}; describe('Sessions - unit/sessions', function () { diff --git a/test/unit/assorted/wire_version.test.ts b/test/unit/assorted/wire_version.test.ts index 448622ce20f..4bbab4fde5e 100644 --- a/test/unit/assorted/wire_version.test.ts +++ b/test/unit/assorted/wire_version.test.ts @@ -1,12 +1,11 @@ import { expect } from 'chai'; +import { MongoClient, MongoServerSelectionError } from '../../../src'; import { - isHello, MAX_SUPPORTED_WIRE_VERSION, - MIN_SUPPORTED_WIRE_VERSION, - MongoClient, - MongoServerSelectionError -} from '../../mongodb'; + MIN_SUPPORTED_WIRE_VERSION +} from '../../../src/cmap/wire_protocol/constants'; +import { isHello } from '../../../src/utils'; import * as mock from '../../tools/mongodb-mock/index'; const minCompatErrMsg = `minimum wire version ${ diff --git a/test/unit/assorted/write_concern.test.js b/test/unit/assorted/write_concern.test.js index 6e45ca69dca..418dd20f971 100644 --- a/test/unit/assorted/write_concern.test.js +++ b/test/unit/assorted/write_concern.test.js @@ -1,9 +1,12 @@ 'use strict'; const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); -const { ObjectId, MongoClient } = require('../../mongodb'); -const { LEGACY_HELLO_COMMAND } = require('../../mongodb'); -const { isHello } = require('../../mongodb'); + +import { ObjectId } from 'bson'; + +import { LEGACY_HELLO_COMMAND } from '../../../src/constants'; +import { MongoClient } from '../../../src/mongo_client'; +import { isHello } from '../../../src/utils'; const TEST_OPTIONS = { writeConcern: { w: 2, wtimeoutMS: 1000 } }; diff --git a/test/unit/client-side-encryption/auto_encrypter.test.ts b/test/unit/client-side-encryption/auto_encrypter.test.ts index 816b3a6cb93..7ccc391ece7 100644 --- a/test/unit/client-side-encryption/auto_encrypter.test.ts +++ b/test/unit/client-side-encryption/auto_encrypter.test.ts @@ -3,13 +3,9 @@ import * as fs from 'fs'; import * as net from 'net'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { StateMachine } from '../../../src/client-side-encryption/state_machine'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongoClient } from '../../../src/mongo_client'; import { BSON, type DataKey } from '../../mongodb'; import * as requirements from './requirements.helper'; diff --git a/test/unit/client-side-encryption/client_encryption.test.ts b/test/unit/client-side-encryption/client_encryption.test.ts index aeb1ac9beef..422ad8bdd82 100644 --- a/test/unit/client-side-encryption/client_encryption.test.ts +++ b/test/unit/client-side-encryption/client_encryption.test.ts @@ -3,16 +3,12 @@ import * as fs from 'fs'; import { resolve } from 'path'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as cryptoCallbacks from '../../../src/client-side-encryption/crypto_callbacks'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongoCryptCreateDataKeyError, MongoCryptCreateEncryptedCollectionError } from '../../../src/client-side-encryption/errors'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { StateMachine } from '../../../src/client-side-encryption/state_machine'; import { Binary, BSON, deserialize, MongoClient } from '../../mongodb'; diff --git a/test/unit/client-side-encryption/errors.test.ts b/test/unit/client-side-encryption/errors.test.ts index 6eaa0dbd6b5..b4b8b8224c2 100644 --- a/test/unit/client-side-encryption/errors.test.ts +++ b/test/unit/client-side-encryption/errors.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-restricted-imports */ import { expect } from 'chai'; import { diff --git a/test/unit/client-side-encryption/mongocryptd_manager.test.ts b/test/unit/client-side-encryption/mongocryptd_manager.test.ts index f8004781d8c..eb199eb7c26 100644 --- a/test/unit/client-side-encryption/mongocryptd_manager.test.ts +++ b/test/unit/client-side-encryption/mongocryptd_manager.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager'; describe('MongocryptdManager', function () { diff --git a/test/unit/client-side-encryption/providers/credentialsProvider.test.ts b/test/unit/client-side-encryption/providers/credentialsProvider.test.ts index a21ac96ef33..aab342222f8 100644 --- a/test/unit/client-side-encryption/providers/credentialsProvider.test.ts +++ b/test/unit/client-side-encryption/providers/credentialsProvider.test.ts @@ -2,22 +2,17 @@ import { expect } from 'chai'; import * as http from 'http'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { MongoCryptAzureKMSRequestError } from '../../../../src/client-side-encryption/errors'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { isEmptyCredentials, type KMSProviders, refreshKMSCredentials } from '../../../../src/client-side-encryption/providers'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { fetchAzureKMSToken, tokenCache } from '../../../../src/client-side-encryption/providers/azure'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { AWSSDKCredentialProvider } from '../../../../src/cmap/auth/aws_temporary_credentials'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as utils from '../../../../src/utils'; import { MongoNetworkTimeoutError } from '../../../mongodb'; import * as requirements from '../requirements.helper'; diff --git a/test/unit/client-side-encryption/requirements.helper.ts b/test/unit/client-side-encryption/requirements.helper.ts index 68e6ecfce76..3aa8fa4b36a 100644 --- a/test/unit/client-side-encryption/requirements.helper.ts +++ b/test/unit/client-side-encryption/requirements.helper.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { getAwsCredentialProvider, getGcpMetadata } from '../../../src/deps'; // Data Key Stuff diff --git a/test/unit/client-side-encryption/state_machine.test.ts b/test/unit/client-side-encryption/state_machine.test.ts index 920ce567dde..21cecd83574 100644 --- a/test/unit/client-side-encryption/state_machine.test.ts +++ b/test/unit/client-side-encryption/state_machine.test.ts @@ -8,9 +8,7 @@ import { setTimeout } from 'timers'; import { setTimeout as setTimeoutAsync } from 'timers/promises'; import * as tls from 'tls'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { StateMachine } from '../../../src/client-side-encryption/state_machine'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { Db } from '../../../src/db'; import { BSON, diff --git a/test/unit/cmap/auth/mongodb_oidc/automated_callback_workflow.test.ts b/test/unit/cmap/auth/mongodb_oidc/automated_callback_workflow.test.ts index 33d37e593d7..fd2343eb913 100644 --- a/test/unit/cmap/auth/mongodb_oidc/automated_callback_workflow.test.ts +++ b/test/unit/cmap/auth/mongodb_oidc/automated_callback_workflow.test.ts @@ -1,9 +1,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { TokenCache } from '../../../../../src/cmap/auth/mongodb_oidc/token_cache'; import { AutomatedCallbackWorkflow, diff --git a/test/unit/cmap/auth/mongodb_oidc/azure_machine_workflow.test.ts b/test/unit/cmap/auth/mongodb_oidc/azure_machine_workflow.test.ts index b61bbd62465..0db2db100b3 100644 --- a/test/unit/cmap/auth/mongodb_oidc/azure_machine_workflow.test.ts +++ b/test/unit/cmap/auth/mongodb_oidc/azure_machine_workflow.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/azure_machine_workflow'; import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../mongodb'; diff --git a/test/unit/cmap/auth/mongodb_oidc/gcp_machine_workflow.test.ts b/test/unit/cmap/auth/mongodb_oidc/gcp_machine_workflow.test.ts index f99465cb1f7..23b890fd988 100644 --- a/test/unit/cmap/auth/mongodb_oidc/gcp_machine_workflow.test.ts +++ b/test/unit/cmap/auth/mongodb_oidc/gcp_machine_workflow.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow'; import { OIDC_VERSION, type OIDCCallbackParams } from '../../../../mongodb'; diff --git a/test/unit/cmap/auth/mongodb_oidc/token_machine_workflow.test.ts b/test/unit/cmap/auth/mongodb_oidc/token_machine_workflow.test.ts index 624c37dbb27..912be77be01 100644 --- a/test/unit/cmap/auth/mongodb_oidc/token_machine_workflow.test.ts +++ b/test/unit/cmap/auth/mongodb_oidc/token_machine_workflow.test.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/token_machine_workflow'; describe('Token machine workflow', function () { diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 3f601c678c0..b0e2c476018 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as compression from '../../src/cmap/wire_protocol/compression'; import { compress, diff --git a/test/unit/error.test.ts b/test/unit/error.test.ts index 355b1dd0005..1a3ddd25403 100644 --- a/test/unit/error.test.ts +++ b/test/unit/error.test.ts @@ -2,9 +2,7 @@ import { expect } from 'chai'; import { setTimeout } from 'timers'; // Exception to the import from mongodb rule we're unit testing our public Errors API -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as importsFromErrorSrc from '../../src/error'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as importsFromEntryPoint from '../../src/index'; import { isHello, diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 653792492ce..c39a09641e0 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; // Exception to the import from mongodb rule we're unit testing our public API -// eslint-disable-next-line @typescript-eslint/no-restricted-imports import * as mongodb from '../../src/index'; import { setDifference } from '../mongodb'; From bbdb366c206749cab024b6f6db37b3b7038e5f5c Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Thu, 18 Sep 2025 13:40:43 -0700 Subject: [PATCH 2/5] Update test/unit/assorted/max_staleness.spec.test.js remove extra comment Co-authored-by: Bailey Pearson --- test/unit/assorted/max_staleness.spec.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/assorted/max_staleness.spec.test.js b/test/unit/assorted/max_staleness.spec.test.js index bb4b2a4d9db..582787ce9ea 100644 --- a/test/unit/assorted/max_staleness.spec.test.js +++ b/test/unit/assorted/max_staleness.spec.test.js @@ -2,7 +2,7 @@ const path = require('path'); const fs = require('fs'); const { executeServerSelectionTest } = require('./server_selection_spec_helper'); -const { Server } = require('../../../src/sdam/server'); // src/sdam/server.ts +const { Server } = require('../../../src/sdam/server'); const { EJSON } = require('bson'); From 16f5dc51a80f845cb6b56e7fdbd2a440a69d7680 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Thu, 18 Sep 2025 14:04:07 -0700 Subject: [PATCH 3/5] fix: pr feedback --- test/unit/assorted/server_selection_spec_helper.js | 12 ++++++------ test/unit/assorted/sessions_collection.test.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/assorted/server_selection_spec_helper.js b/test/unit/assorted/server_selection_spec_helper.js index 0dccbeb7446..040d8fbdf10 100644 --- a/test/unit/assorted/server_selection_spec_helper.js +++ b/test/unit/assorted/server_selection_spec_helper.js @@ -1,11 +1,11 @@ 'use strict'; -import { MongoServerSelectionError } from '../../../src/error'; -import { ReadPreference } from '../../../src/read_preference'; -import { ServerType, TopologyType } from '../../../src/sdam/common'; -import { ServerDescription } from '../../../src/sdam/server_description'; -import * as ServerSelectors from '../../../src/sdam/server_selection'; // src/sdam/server_selection.ts -import { Topology } from '../../../src/sdam/topology'; +const { MongoServerSelectionError } = require('../../../src/error'); +const { ReadPreference } = require('../../../src/read_preference'); +const { ServerType, TopologyType } = require('../../../src/sdam/common'); +const { ServerDescription } = require('../../../src/sdam/server_description'); +const { Topology } = require('../../../src/sdam/topology'); +const ServerSelectors = require('../../../src/sdam/server_selection'); const sinon = require('sinon'); const { expect } = require('chai'); diff --git a/test/unit/assorted/sessions_collection.test.js b/test/unit/assorted/sessions_collection.test.js index 736d0e8be1d..0593ab8c42a 100644 --- a/test/unit/assorted/sessions_collection.test.js +++ b/test/unit/assorted/sessions_collection.test.js @@ -2,8 +2,8 @@ const { Timestamp } = require('bson'); const { expect } = require('chai'); const mock = require('../../tools/mongodb-mock/index'); -import { MongoClient } from '../../../lib'; -import { isHello } from '../../../lib/utils'; +const { isHello } = require('../../../src/utils'); +const { MongoClient } = require('../../../src'); const test = {}; describe('Sessions - unit/sessions', function () { From 88b54e324d7ab1bed1dfe79a5961b18d58b3959f Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Fri, 19 Sep 2025 08:11:26 -0700 Subject: [PATCH 4/5] fix: js files should not be using import --- test/unit/assorted/write_concern.test.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/unit/assorted/write_concern.test.js b/test/unit/assorted/write_concern.test.js index 418dd20f971..ed0368b5c95 100644 --- a/test/unit/assorted/write_concern.test.js +++ b/test/unit/assorted/write_concern.test.js @@ -2,11 +2,10 @@ const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); -import { ObjectId } from 'bson'; - -import { LEGACY_HELLO_COMMAND } from '../../../src/constants'; -import { MongoClient } from '../../../src/mongo_client'; -import { isHello } from '../../../src/utils'; +const { isHello } = require('../../../src/utils'); +const { LEGACY_HELLO_COMMAND } = require('../../../src/constants'); +const { MongoClient } = require('../../../src/mongo_client'); +const { ObjectId } = require('bson'); const TEST_OPTIONS = { writeConcern: { w: 2, wtimeoutMS: 1000 } }; From be1fb8e356b3f7bfd61cfed8167c3a1c9b439dd2 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Fri, 19 Sep 2025 09:02:57 -0700 Subject: [PATCH 5/5] fix: for shared library test, continue to reference `lib`, not `src`. --- test/tools/fixtures/shared_library_test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/tools/fixtures/shared_library_test.js b/test/tools/fixtures/shared_library_test.js index 5a334bc98e6..e87140a4834 100644 --- a/test/tools/fixtures/shared_library_test.js +++ b/test/tools/fixtures/shared_library_test.js @@ -1,6 +1,7 @@ +/* eslint-disable no-restricted-modules */ const { EJSON } = require('bson'); -const { AutoEncrypter } = require('../../../src/client-side-encryption/auto_encrypter'); -const { MongoClient } = require('../../../src/mongo_client'); +const { AutoEncrypter } = require('../../../lib/client-side-encryption/auto_encrypter'); +const { MongoClient } = require('../../../lib/mongo_client'); try { const extraOptions = JSON.parse(process.env.EXTRA_OPTIONS);