From dbcd3729d7c0d0023a0b2c141cdcb713f18a298f Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 2 Sep 2022 13:25:54 -0400 Subject: [PATCH 1/6] feat(NODE-4607): add exports needed by legacy client --- src/index.ts | 22 ++++--- test/tools/utils.ts | 14 ++++ test/unit/index.test.ts | 143 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 test/unit/index.test.ts diff --git a/src/index.ts b/src/index.ts index 933be8772e..f432443c03 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,7 @@ import { Admin } from './admin'; import { ObjectId } from './bson'; +import { OrderedBulkOperation } from './bulk/ordered'; +import { UnorderedBulkOperation } from './bulk/unordered'; import { ChangeStream } from './change_stream'; import { Collection } from './collection'; import { AbstractCursor } from './cursor/abstract_cursor'; @@ -9,10 +11,13 @@ import { ListCollectionsCursor } from './cursor/list_collections_cursor'; import { ListIndexesCursor } from './cursor/list_indexes_cursor'; import { Db } from './db'; import { GridFSBucket } from './gridfs'; +import { GridFSBucketReadStream } from './gridfs/download'; +import { GridFSBucketWriteStream } from './gridfs/upload'; import { Logger } from './logger'; import { MongoClient } from './mongo_client'; import { CancellationToken } from './mongo_types'; import { PromiseProvider } from './promise_provider'; +import { ClientSession } from './sessions'; /** @internal */ export { BSON } from './bson'; @@ -80,16 +85,21 @@ export { AggregationCursor, CancellationToken, ChangeStream, + ClientSession, Collection, Db, FindCursor, GridFSBucket, + GridFSBucketReadStream, + GridFSBucketWriteStream, ListCollectionsCursor, ListIndexesCursor, Logger, MongoClient, + OrderedBulkOperation, // Utils - PromiseProvider as Promise + PromiseProvider as Promise, + UnorderedBulkOperation }; // enums @@ -171,8 +181,6 @@ export type { FindOperators, WriteConcernErrorData } from './bulk/common'; -export type { OrderedBulkOperation } from './bulk/ordered'; -export type { UnorderedBulkOperation } from './bulk/unordered'; export type { ChangeStreamCollModDocument, ChangeStreamCreateDocument, @@ -268,18 +276,13 @@ export type { Encrypter, EncrypterOptions } from './encrypter'; export type { AnyError, ErrorDescription, MongoNetworkErrorOptions } from './error'; export type { Explain, ExplainOptions, ExplainVerbosityLike } from './explain'; export type { - GridFSBucketReadStream, GridFSBucketReadStreamOptions, GridFSBucketReadStreamOptionsWithRevision, GridFSBucketReadStreamPrivate, GridFSFile } from './gridfs/download'; export type { GridFSBucketEvents, GridFSBucketOptions, GridFSBucketPrivate } from './gridfs/index'; -export type { - GridFSBucketWriteStream, - GridFSBucketWriteStreamOptions, - GridFSChunk -} from './gridfs/upload'; +export type { GridFSBucketWriteStreamOptions, GridFSChunk } from './gridfs/upload'; export type { LoggerFunction, LoggerOptions } from './logger'; export type { Auth, @@ -453,7 +456,6 @@ export type { } from './sdam/topology'; export type { TopologyDescription, TopologyDescriptionOptions } from './sdam/topology_description'; export type { - ClientSession, ClientSessionEvents, ClientSessionOptions, EndSessionOptions, diff --git a/test/tools/utils.ts b/test/tools/utils.ts index 24bed64c47..a32fa15803 100644 --- a/test/tools/utils.ts +++ b/test/tools/utils.ts @@ -503,3 +503,17 @@ export function isBSONExtImported() { const driverBSON = require('../../src/bson'); return driverBSON.deserialize.toString().includes('[native code]'); } + +export const byStrings = (a: any, b: any) => { + const res = `${a}`.localeCompare(`${b}`); + return res < 0 ? -1 : res > 0 ? 1 : 0; +}; + +export const sorted = (iterable: Iterable, how: (a: T, b: T) => 0 | 1 | -1) => { + if (typeof how !== 'function') { + throw new TypeError('must provide a "how" function to sorted'); + } + const items = Array.from(iterable); + items.sort(how); + return items; +}; diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts new file mode 100644 index 0000000000..be06accc5b --- /dev/null +++ b/test/unit/index.test.ts @@ -0,0 +1,143 @@ +import { expect } from 'chai'; +import { inspect } from 'util'; + +import * as mongodb from '../../lib/index'; +import { setDifference } from '../../src/utils'; +import { byStrings, sorted } from '../tools/utils'; + +// prettier-ignore +const expectedExports = new Map([ + // BSON + ['BSON', 'reason'], + ['Binary', 'reason'], + ['BSONRegExp', 'reason'], + ['BSONSymbol', 'reason'], + ['Code', 'reason'], + ['DBRef', 'reason'], + ['Decimal128', 'reason'], + ['Double', 'reason'], + ['Int32', 'reason'], + ['Long', 'reason'], + ['Map', 'reason'], + ['MaxKey', 'reason'], + ['MinKey', 'reason'], + ['ObjectId', 'reason'], + ['Timestamp', 'reason'], + ['ChangeStreamCursor', 'reason'], + ['ObjectID', 'reason'], + // errors + ['MongoBulkWriteError', 'reason'], + ['MongoAPIError', 'reason'], + ['MongoAWSError', 'reason'], + ['MongoBatchReExecutionError', 'reason'], + ['MongoChangeStreamError', 'reason'], + ['MongoCompatibilityError', 'reason'], + ['MongoCursorExhaustedError', 'reason'], + ['MongoCursorInUseError', 'reason'], + ['MongoDecompressionError', 'reason'], + ['MongoDriverError', 'reason'], + ['MongoError', 'reason'], + ['MongoExpiredSessionError', 'reason'], + ['MongoGridFSChunkError', 'reason'], + ['MongoGridFSStreamError', 'reason'], + ['MongoInvalidArgumentError', 'reason'], + ['MongoKerberosError', 'reason'], + ['MongoMissingCredentialsError', 'reason'], + ['MongoMissingDependencyError', 'reason'], + ['MongoNetworkError', 'reason'], + ['MongoNetworkTimeoutError', 'reason'], + ['MongoNotConnectedError', 'reason'], + ['MongoParseError', 'reason'], + ['MongoRuntimeError', 'reason'], + ['MongoServerClosedError', 'reason'], + ['MongoServerError', 'reason'], + ['MongoServerSelectionError', 'reason'], + ['MongoSystemError', 'reason'], + ['MongoTailableCursorError', 'reason'], + ['MongoTopologyClosedError', 'reason'], + ['MongoTransactionError', 'reason'], + ['MongoUnexpectedServerResponseError', 'reason'], + ['MongoWriteConcernError', 'reason'], + // classes + ['AbstractCursor', 'reason'], + ['Admin', 'reason'], + ['AggregationCursor', 'reason'], + ['CancellationToken', 'reason'], + ['ChangeStream', 'reason'], + ['ClientSession', 'reason'], + ['Collection', 'reason'], + ['Db', 'reason'], + ['FindCursor', 'reason'], + ['GridFSBucket', 'reason'], + ['ListCollectionsCursor', 'reason'], + ['ListIndexesCursor', 'reason'], + ['Logger', 'reason'], + ['MongoClient', 'reason'], + // global promise setter + ['Promise', 'global promise setter'], + // enums + ['BatchType', 'reason'], + ['GSSAPICanonicalizationValue', 'reason'], + ['AuthMechanism', 'reason'], + ['Compressor', 'reason'], + ['CURSOR_FLAGS', 'reason'], + ['AutoEncryptionLoggerLevel', 'reason'], + ['MongoErrorLabel', 'reason'], + ['ExplainVerbosity', 'reason'], + ['LoggerLevel', 'reason'], + ['ServerApiVersion', 'reason'], + ['BSONType', 'reason'], + ['ReturnDocument', 'reason'], + ['ProfilingLevel', 'reason'], + ['ReadConcernLevel', 'reason'], + ['ReadPreferenceMode', 'reason'], + ['ServerType', 'reason'], + ['TopologyType', 'reason'], + ['ReadConcern', 'reason'], + ['ReadPreference', 'reason'], + ['WriteConcern', 'reason'], + // events + ['CommandFailedEvent', 'reason'], + ['CommandStartedEvent', 'reason'], + ['CommandSucceededEvent', 'reason'], + ['ConnectionCheckedInEvent', 'reason'], + ['ConnectionCheckedOutEvent', 'reason'], + ['ConnectionCheckOutFailedEvent', 'reason'], + ['ConnectionCheckOutStartedEvent', 'reason'], + ['ConnectionClosedEvent', 'reason'], + ['ConnectionCreatedEvent', 'reason'], + ['ConnectionPoolClearedEvent', 'reason'], + ['ConnectionPoolClosedEvent', 'reason'], + ['ConnectionPoolCreatedEvent', 'reason'], + ['ConnectionPoolMonitoringEvent', 'reason'], + ['ConnectionReadyEvent', 'reason'], + ['ServerClosedEvent', 'reason'], + ['ServerDescriptionChangedEvent', 'reason'], + ['ServerHeartbeatFailedEvent', 'reason'], + ['ServerHeartbeatStartedEvent', 'reason'], + ['ServerHeartbeatSucceededEvent', 'reason'], + ['ServerOpeningEvent', 'reason'], + ['TopologyClosedEvent', 'reason'], + ['TopologyDescriptionChangedEvent', 'reason'], + ['TopologyOpeningEvent', 'reason'], + ['SrvPollingEvent', 'reason'], + + ['GridFSBucketReadStream', 'reason'], + ['GridFSBucketWriteStream', 'reason'], + ['OrderedBulkOperation', 'reason'], + ['UnorderedBulkOperation', 'reason'], +]); + +describe('mongodb entrypoint', () => { + it('should export all keys in our exports list', () => { + expect(sorted(Object.keys(mongodb), byStrings)).to.deep.equal( + sorted(expectedExports.keys(), byStrings) + ); + }); + + it('should export only keys in our exports list', () => { + const currentExports = Object.keys(mongodb); + const difference = setDifference(currentExports, expectedExports.keys()); + expect(difference, inspect(difference, { breakLength: Infinity })).to.have.lengthOf(0); + }); +}); From b800552289e0fd671aaf30574e0725d3a46408e8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 2 Sep 2022 14:22:36 -0400 Subject: [PATCH 2/6] docs: internal flags on all exported constructors --- src/bulk/ordered.ts | 1 + src/bulk/unordered.ts | 1 + src/gridfs/download.ts | 3 ++- src/gridfs/upload.ts | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bulk/ordered.ts b/src/bulk/ordered.ts index e0dbf9b7e3..97ee6444d8 100644 --- a/src/bulk/ordered.ts +++ b/src/bulk/ordered.ts @@ -8,6 +8,7 @@ import { Batch, BatchType, BulkOperationBase, BulkWriteOptions } from './common' /** @public */ export class OrderedBulkOperation extends BulkOperationBase { + /** @internal */ constructor(collection: Collection, options: BulkWriteOptions) { super(collection, options, true); } diff --git a/src/bulk/unordered.ts b/src/bulk/unordered.ts index b4227e8d03..5f2e562f3c 100644 --- a/src/bulk/unordered.ts +++ b/src/bulk/unordered.ts @@ -9,6 +9,7 @@ import { Batch, BatchType, BulkOperationBase, BulkWriteOptions, BulkWriteResult /** @public */ export class UnorderedBulkOperation extends BulkOperationBase { + /** @internal */ constructor(collection: Collection, options: BulkWriteOptions) { super(collection, options, false); } diff --git a/src/gridfs/download.ts b/src/gridfs/download.ts index a13cdac39d..c161333854 100644 --- a/src/gridfs/download.ts +++ b/src/gridfs/download.ts @@ -103,11 +103,12 @@ export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableS */ static readonly CLOSE = 'close' as const; - /** @internal + /** * @param chunks - Handle for chunks collection * @param files - Handle for files collection * @param readPreference - The read preference to use * @param filter - The filter to use to find the file document + * @internal */ constructor( chunks: Collection, diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index ae0d678998..9e9b40aa07 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -69,10 +69,11 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable */ static readonly FINISH = 'finish'; - /** @internal + /** * @param bucket - Handle for this stream's corresponding bucket * @param filename - The value of the 'filename' key in the files doc * @param options - Optional settings. + * @internal */ constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions) { super(); From 144b03b9332b5bae7b8c6e35d66d0292e1cdfe4b Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 2 Sep 2022 16:54:11 -0400 Subject: [PATCH 3/6] test: fix for ts-node strangeness --- test/unit/index.test.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index be06accc5b..d97749a046 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; -import { inspect } from 'util'; -import * as mongodb from '../../lib/index'; +import * as mongodb from '../../src/index'; import { setDifference } from '../../src/utils'; import { byStrings, sorted } from '../tools/utils'; @@ -126,6 +125,10 @@ const expectedExports = new Map([ ['GridFSBucketWriteStream', 'reason'], ['OrderedBulkOperation', 'reason'], ['UnorderedBulkOperation', 'reason'], + + // TS-NODE Adds these keys but they are undefined... weird + ['AnyBulkWriteOperation', 'ts-node'], + ['BulkWriteOptions', 'ts-node'], ]); describe('mongodb entrypoint', () => { @@ -138,6 +141,21 @@ describe('mongodb entrypoint', () => { it('should export only keys in our exports list', () => { const currentExports = Object.keys(mongodb); const difference = setDifference(currentExports, expectedExports.keys()); - expect(difference, inspect(difference, { breakLength: Infinity })).to.have.lengthOf(0); + expect( + difference, + `Found extra exports [${Array.from(difference).join( + ', ' + )}], if these are expected, just add them to the list in this file` + ).to.have.lengthOf(0); + }); + + it('meta test: ts-node adds keys to the module that point to undefined', () => { + const tsNodeKeys = Array.from(expectedExports.entries()).filter( + ([, value]) => value === 'ts-node' + ); + + for (const [tsNodeKey] of tsNodeKeys) { + expect(mongodb).to.have.property(tsNodeKey, undefined); + } }); }); From d681d4638b37941fd2f5a7a762a3c50da32a37e4 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 7 Sep 2022 17:00:11 -0400 Subject: [PATCH 4/6] fixup --- test/unit/index.test.ts | 272 +++++++++++++++++++--------------------- 1 file changed, 126 insertions(+), 146 deletions(-) diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index d97749a046..224fca33cd 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,161 +1,141 @@ import { expect } from 'chai'; import * as mongodb from '../../src/index'; -import { setDifference } from '../../src/utils'; import { byStrings, sorted } from '../tools/utils'; -// prettier-ignore -const expectedExports = new Map([ - // BSON - ['BSON', 'reason'], - ['Binary', 'reason'], - ['BSONRegExp', 'reason'], - ['BSONSymbol', 'reason'], - ['Code', 'reason'], - ['DBRef', 'reason'], - ['Decimal128', 'reason'], - ['Double', 'reason'], - ['Int32', 'reason'], - ['Long', 'reason'], - ['Map', 'reason'], - ['MaxKey', 'reason'], - ['MinKey', 'reason'], - ['ObjectId', 'reason'], - ['Timestamp', 'reason'], - ['ChangeStreamCursor', 'reason'], - ['ObjectID', 'reason'], - // errors - ['MongoBulkWriteError', 'reason'], - ['MongoAPIError', 'reason'], - ['MongoAWSError', 'reason'], - ['MongoBatchReExecutionError', 'reason'], - ['MongoChangeStreamError', 'reason'], - ['MongoCompatibilityError', 'reason'], - ['MongoCursorExhaustedError', 'reason'], - ['MongoCursorInUseError', 'reason'], - ['MongoDecompressionError', 'reason'], - ['MongoDriverError', 'reason'], - ['MongoError', 'reason'], - ['MongoExpiredSessionError', 'reason'], - ['MongoGridFSChunkError', 'reason'], - ['MongoGridFSStreamError', 'reason'], - ['MongoInvalidArgumentError', 'reason'], - ['MongoKerberosError', 'reason'], - ['MongoMissingCredentialsError', 'reason'], - ['MongoMissingDependencyError', 'reason'], - ['MongoNetworkError', 'reason'], - ['MongoNetworkTimeoutError', 'reason'], - ['MongoNotConnectedError', 'reason'], - ['MongoParseError', 'reason'], - ['MongoRuntimeError', 'reason'], - ['MongoServerClosedError', 'reason'], - ['MongoServerError', 'reason'], - ['MongoServerSelectionError', 'reason'], - ['MongoSystemError', 'reason'], - ['MongoTailableCursorError', 'reason'], - ['MongoTopologyClosedError', 'reason'], - ['MongoTransactionError', 'reason'], - ['MongoUnexpectedServerResponseError', 'reason'], - ['MongoWriteConcernError', 'reason'], - // classes - ['AbstractCursor', 'reason'], - ['Admin', 'reason'], - ['AggregationCursor', 'reason'], - ['CancellationToken', 'reason'], - ['ChangeStream', 'reason'], - ['ClientSession', 'reason'], - ['Collection', 'reason'], - ['Db', 'reason'], - ['FindCursor', 'reason'], - ['GridFSBucket', 'reason'], - ['ListCollectionsCursor', 'reason'], - ['ListIndexesCursor', 'reason'], - ['Logger', 'reason'], - ['MongoClient', 'reason'], - // global promise setter - ['Promise', 'global promise setter'], - // enums - ['BatchType', 'reason'], - ['GSSAPICanonicalizationValue', 'reason'], - ['AuthMechanism', 'reason'], - ['Compressor', 'reason'], - ['CURSOR_FLAGS', 'reason'], - ['AutoEncryptionLoggerLevel', 'reason'], - ['MongoErrorLabel', 'reason'], - ['ExplainVerbosity', 'reason'], - ['LoggerLevel', 'reason'], - ['ServerApiVersion', 'reason'], - ['BSONType', 'reason'], - ['ReturnDocument', 'reason'], - ['ProfilingLevel', 'reason'], - ['ReadConcernLevel', 'reason'], - ['ReadPreferenceMode', 'reason'], - ['ServerType', 'reason'], - ['TopologyType', 'reason'], - ['ReadConcern', 'reason'], - ['ReadPreference', 'reason'], - ['WriteConcern', 'reason'], - // events - ['CommandFailedEvent', 'reason'], - ['CommandStartedEvent', 'reason'], - ['CommandSucceededEvent', 'reason'], - ['ConnectionCheckedInEvent', 'reason'], - ['ConnectionCheckedOutEvent', 'reason'], - ['ConnectionCheckOutFailedEvent', 'reason'], - ['ConnectionCheckOutStartedEvent', 'reason'], - ['ConnectionClosedEvent', 'reason'], - ['ConnectionCreatedEvent', 'reason'], - ['ConnectionPoolClearedEvent', 'reason'], - ['ConnectionPoolClosedEvent', 'reason'], - ['ConnectionPoolCreatedEvent', 'reason'], - ['ConnectionPoolMonitoringEvent', 'reason'], - ['ConnectionReadyEvent', 'reason'], - ['ServerClosedEvent', 'reason'], - ['ServerDescriptionChangedEvent', 'reason'], - ['ServerHeartbeatFailedEvent', 'reason'], - ['ServerHeartbeatStartedEvent', 'reason'], - ['ServerHeartbeatSucceededEvent', 'reason'], - ['ServerOpeningEvent', 'reason'], - ['TopologyClosedEvent', 'reason'], - ['TopologyDescriptionChangedEvent', 'reason'], - ['TopologyOpeningEvent', 'reason'], - ['SrvPollingEvent', 'reason'], +/** + * TS-NODE Adds these keys but they are undefined, they are not present when you import from lib + * We did not think this strangeness was worth investigating so we just make sure they remain set to undefined + */ +const TS_NODE_EXPORTS = ['AnyBulkWriteOperation', 'BulkWriteOptions']; - ['GridFSBucketReadStream', 'reason'], - ['GridFSBucketWriteStream', 'reason'], - ['OrderedBulkOperation', 'reason'], - ['UnorderedBulkOperation', 'reason'], - - // TS-NODE Adds these keys but they are undefined... weird - ['AnyBulkWriteOperation', 'ts-node'], - ['BulkWriteOptions', 'ts-node'], -]); +const EXPECTED_EXPORTS = [ + ...TS_NODE_EXPORTS, + 'BSON', + 'Binary', + 'BSONRegExp', + 'BSONSymbol', + 'Code', + 'DBRef', + 'Decimal128', + 'Double', + 'Int32', + 'Long', + 'Map', + 'MaxKey', + 'MinKey', + 'ObjectId', + 'Timestamp', + 'ChangeStreamCursor', + 'ObjectID', + 'MongoBulkWriteError', + 'MongoAPIError', + 'MongoAWSError', + 'MongoBatchReExecutionError', + 'MongoChangeStreamError', + 'MongoCompatibilityError', + 'MongoCursorExhaustedError', + 'MongoCursorInUseError', + 'MongoDecompressionError', + 'MongoDriverError', + 'MongoError', + 'MongoExpiredSessionError', + 'MongoGridFSChunkError', + 'MongoGridFSStreamError', + 'MongoInvalidArgumentError', + 'MongoKerberosError', + 'MongoMissingCredentialsError', + 'MongoMissingDependencyError', + 'MongoNetworkError', + 'MongoNetworkTimeoutError', + 'MongoNotConnectedError', + 'MongoParseError', + 'MongoRuntimeError', + 'MongoServerClosedError', + 'MongoServerError', + 'MongoServerSelectionError', + 'MongoSystemError', + 'MongoTailableCursorError', + 'MongoTopologyClosedError', + 'MongoTransactionError', + 'MongoUnexpectedServerResponseError', + 'MongoWriteConcernError', + 'AbstractCursor', + 'Admin', + 'AggregationCursor', + 'CancellationToken', + 'ChangeStream', + 'ClientSession', + 'Collection', + 'Db', + 'FindCursor', + 'GridFSBucket', + 'ListCollectionsCursor', + 'ListIndexesCursor', + 'Logger', + 'MongoClient', + 'Promise', + 'BatchType', + 'GSSAPICanonicalizationValue', + 'AuthMechanism', + 'Compressor', + 'CURSOR_FLAGS', + 'AutoEncryptionLoggerLevel', + 'MongoErrorLabel', + 'ExplainVerbosity', + 'LoggerLevel', + 'ServerApiVersion', + 'BSONType', + 'ReturnDocument', + 'ProfilingLevel', + 'ReadConcernLevel', + 'ReadPreferenceMode', + 'ServerType', + 'TopologyType', + 'ReadConcern', + 'ReadPreference', + 'WriteConcern', + 'CommandFailedEvent', + 'CommandStartedEvent', + 'CommandSucceededEvent', + 'ConnectionCheckedInEvent', + 'ConnectionCheckedOutEvent', + 'ConnectionCheckOutFailedEvent', + 'ConnectionCheckOutStartedEvent', + 'ConnectionClosedEvent', + 'ConnectionCreatedEvent', + 'ConnectionPoolClearedEvent', + 'ConnectionPoolClosedEvent', + 'ConnectionPoolCreatedEvent', + 'ConnectionPoolMonitoringEvent', + 'ConnectionReadyEvent', + 'ServerClosedEvent', + 'ServerDescriptionChangedEvent', + 'ServerHeartbeatFailedEvent', + 'ServerHeartbeatStartedEvent', + 'ServerHeartbeatSucceededEvent', + 'ServerOpeningEvent', + 'TopologyClosedEvent', + 'TopologyDescriptionChangedEvent', + 'TopologyOpeningEvent', + 'SrvPollingEvent', + 'GridFSBucketReadStream', + 'GridFSBucketWriteStream', + 'OrderedBulkOperation', + 'UnorderedBulkOperation' +]; describe('mongodb entrypoint', () => { - it('should export all keys in our exports list', () => { + it('should export all and only the expected keys in expected_exports', () => { expect(sorted(Object.keys(mongodb), byStrings)).to.deep.equal( - sorted(expectedExports.keys(), byStrings) + sorted(EXPECTED_EXPORTS, byStrings) ); }); - it('should export only keys in our exports list', () => { - const currentExports = Object.keys(mongodb); - const difference = setDifference(currentExports, expectedExports.keys()); - expect( - difference, - `Found extra exports [${Array.from(difference).join( - ', ' - )}], if these are expected, just add them to the list in this file` - ).to.have.lengthOf(0); - }); - - it('meta test: ts-node adds keys to the module that point to undefined', () => { - const tsNodeKeys = Array.from(expectedExports.entries()).filter( - ([, value]) => value === 'ts-node' - ); - - for (const [tsNodeKey] of tsNodeKeys) { - expect(mongodb).to.have.property(tsNodeKey, undefined); + it('should export keys added by ts-node as undefined', () => { + expect(TS_NODE_EXPORTS).to.have.length.greaterThan(0); // Are there no longer fake ts-node exports? + for (const tsNodeExportKey of TS_NODE_EXPORTS) { + expect(mongodb).to.have.property(tsNodeExportKey, undefined); } }); }); From cfb0ad3fc8adc5da66c6036bd3a75663b95533b3 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 7 Sep 2022 17:04:30 -0400 Subject: [PATCH 5/6] sort lines --- test/unit/index.test.ts | 114 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 224fca33cd..ab71fbe0ee 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -11,34 +11,71 @@ const TS_NODE_EXPORTS = ['AnyBulkWriteOperation', 'BulkWriteOptions']; const EXPECTED_EXPORTS = [ ...TS_NODE_EXPORTS, - 'BSON', + 'AbstractCursor', + 'Admin', + 'AggregationCursor', + 'AuthMechanism', + 'AutoEncryptionLoggerLevel', + 'BatchType', 'Binary', + 'BSON', 'BSONRegExp', 'BSONSymbol', + 'BSONType', + 'CancellationToken', + 'ChangeStream', + 'ChangeStreamCursor', + 'ClientSession', 'Code', + 'Collection', + 'CommandFailedEvent', + 'CommandStartedEvent', + 'CommandSucceededEvent', + 'Compressor', + 'ConnectionCheckedInEvent', + 'ConnectionCheckedOutEvent', + 'ConnectionCheckOutFailedEvent', + 'ConnectionCheckOutStartedEvent', + 'ConnectionClosedEvent', + 'ConnectionCreatedEvent', + 'ConnectionPoolClearedEvent', + 'ConnectionPoolClosedEvent', + 'ConnectionPoolCreatedEvent', + 'ConnectionPoolMonitoringEvent', + 'ConnectionReadyEvent', + 'CURSOR_FLAGS', + 'Db', 'DBRef', 'Decimal128', 'Double', + 'ExplainVerbosity', + 'FindCursor', + 'GridFSBucket', + 'GridFSBucketReadStream', + 'GridFSBucketWriteStream', + 'GSSAPICanonicalizationValue', 'Int32', + 'ListCollectionsCursor', + 'ListIndexesCursor', + 'Logger', + 'LoggerLevel', 'Long', 'Map', 'MaxKey', 'MinKey', - 'ObjectId', - 'Timestamp', - 'ChangeStreamCursor', - 'ObjectID', - 'MongoBulkWriteError', 'MongoAPIError', 'MongoAWSError', 'MongoBatchReExecutionError', + 'MongoBulkWriteError', 'MongoChangeStreamError', + 'MongoClient', 'MongoCompatibilityError', 'MongoCursorExhaustedError', 'MongoCursorInUseError', 'MongoDecompressionError', 'MongoDriverError', 'MongoError', + 'MongoErrorLabel', 'MongoExpiredSessionError', 'MongoGridFSChunkError', 'MongoGridFSStreamError', @@ -60,69 +97,32 @@ const EXPECTED_EXPORTS = [ 'MongoTransactionError', 'MongoUnexpectedServerResponseError', 'MongoWriteConcernError', - 'AbstractCursor', - 'Admin', - 'AggregationCursor', - 'CancellationToken', - 'ChangeStream', - 'ClientSession', - 'Collection', - 'Db', - 'FindCursor', - 'GridFSBucket', - 'ListCollectionsCursor', - 'ListIndexesCursor', - 'Logger', - 'MongoClient', - 'Promise', - 'BatchType', - 'GSSAPICanonicalizationValue', - 'AuthMechanism', - 'Compressor', - 'CURSOR_FLAGS', - 'AutoEncryptionLoggerLevel', - 'MongoErrorLabel', - 'ExplainVerbosity', - 'LoggerLevel', - 'ServerApiVersion', - 'BSONType', - 'ReturnDocument', + 'ObjectId', + 'ObjectID', + 'OrderedBulkOperation', 'ProfilingLevel', - 'ReadConcernLevel', - 'ReadPreferenceMode', - 'ServerType', - 'TopologyType', + 'Promise', 'ReadConcern', + 'ReadConcernLevel', 'ReadPreference', - 'WriteConcern', - 'CommandFailedEvent', - 'CommandStartedEvent', - 'CommandSucceededEvent', - 'ConnectionCheckedInEvent', - 'ConnectionCheckedOutEvent', - 'ConnectionCheckOutFailedEvent', - 'ConnectionCheckOutStartedEvent', - 'ConnectionClosedEvent', - 'ConnectionCreatedEvent', - 'ConnectionPoolClearedEvent', - 'ConnectionPoolClosedEvent', - 'ConnectionPoolCreatedEvent', - 'ConnectionPoolMonitoringEvent', - 'ConnectionReadyEvent', + 'ReadPreferenceMode', + 'ReturnDocument', + 'ServerApiVersion', 'ServerClosedEvent', 'ServerDescriptionChangedEvent', 'ServerHeartbeatFailedEvent', 'ServerHeartbeatStartedEvent', 'ServerHeartbeatSucceededEvent', 'ServerOpeningEvent', + 'ServerType', + 'SrvPollingEvent', + 'Timestamp', 'TopologyClosedEvent', 'TopologyDescriptionChangedEvent', 'TopologyOpeningEvent', - 'SrvPollingEvent', - 'GridFSBucketReadStream', - 'GridFSBucketWriteStream', - 'OrderedBulkOperation', - 'UnorderedBulkOperation' + 'TopologyType', + 'UnorderedBulkOperation', + 'WriteConcern' ]; describe('mongodb entrypoint', () => { From ce60aa3cc0efc6429167d9fd8a6854d0d8a11fbb Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 7 Sep 2022 17:14:18 -0400 Subject: [PATCH 6/6] question -> action --- test/unit/index.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index ab71fbe0ee..98c2ced75e 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -133,7 +133,8 @@ describe('mongodb entrypoint', () => { }); it('should export keys added by ts-node as undefined', () => { - expect(TS_NODE_EXPORTS).to.have.length.greaterThan(0); // Are there no longer fake ts-node exports? + // If the array is empty, this test would be a no-op so we should remove it + expect(TS_NODE_EXPORTS).to.have.length.greaterThan(0); for (const tsNodeExportKey of TS_NODE_EXPORTS) { expect(mongodb).to.have.property(tsNodeExportKey, undefined); }