|
| 1 | +import { expect } from 'chai'; |
| 2 | + |
| 3 | +import * as mongodb from '../../src/index'; |
| 4 | +import { byStrings, sorted } from '../tools/utils'; |
| 5 | + |
| 6 | +/** |
| 7 | + * TS-NODE Adds these keys but they are undefined, they are not present when you import from lib |
| 8 | + * We did not think this strangeness was worth investigating so we just make sure they remain set to undefined |
| 9 | + */ |
| 10 | +const TS_NODE_EXPORTS = ['AnyBulkWriteOperation', 'BulkWriteOptions']; |
| 11 | + |
| 12 | +const EXPECTED_EXPORTS = [ |
| 13 | + ...TS_NODE_EXPORTS, |
| 14 | + 'AbstractCursor', |
| 15 | + 'Admin', |
| 16 | + 'AggregationCursor', |
| 17 | + 'AuthMechanism', |
| 18 | + 'AutoEncryptionLoggerLevel', |
| 19 | + 'BatchType', |
| 20 | + 'Binary', |
| 21 | + 'BSON', |
| 22 | + 'BSONRegExp', |
| 23 | + 'BSONSymbol', |
| 24 | + 'BSONType', |
| 25 | + 'CancellationToken', |
| 26 | + 'ChangeStream', |
| 27 | + 'ChangeStreamCursor', |
| 28 | + 'ClientSession', |
| 29 | + 'Code', |
| 30 | + 'Collection', |
| 31 | + 'CommandFailedEvent', |
| 32 | + 'CommandStartedEvent', |
| 33 | + 'CommandSucceededEvent', |
| 34 | + 'Compressor', |
| 35 | + 'ConnectionCheckedInEvent', |
| 36 | + 'ConnectionCheckedOutEvent', |
| 37 | + 'ConnectionCheckOutFailedEvent', |
| 38 | + 'ConnectionCheckOutStartedEvent', |
| 39 | + 'ConnectionClosedEvent', |
| 40 | + 'ConnectionCreatedEvent', |
| 41 | + 'ConnectionPoolClearedEvent', |
| 42 | + 'ConnectionPoolClosedEvent', |
| 43 | + 'ConnectionPoolCreatedEvent', |
| 44 | + 'ConnectionPoolMonitoringEvent', |
| 45 | + 'ConnectionReadyEvent', |
| 46 | + 'CURSOR_FLAGS', |
| 47 | + 'Db', |
| 48 | + 'DBRef', |
| 49 | + 'Decimal128', |
| 50 | + 'Double', |
| 51 | + 'ExplainVerbosity', |
| 52 | + 'FindCursor', |
| 53 | + 'GridFSBucket', |
| 54 | + 'GridFSBucketReadStream', |
| 55 | + 'GridFSBucketWriteStream', |
| 56 | + 'GSSAPICanonicalizationValue', |
| 57 | + 'Int32', |
| 58 | + 'ListCollectionsCursor', |
| 59 | + 'ListIndexesCursor', |
| 60 | + 'Logger', |
| 61 | + 'LoggerLevel', |
| 62 | + 'Long', |
| 63 | + 'Map', |
| 64 | + 'MaxKey', |
| 65 | + 'MinKey', |
| 66 | + 'MongoAPIError', |
| 67 | + 'MongoAWSError', |
| 68 | + 'MongoBatchReExecutionError', |
| 69 | + 'MongoBulkWriteError', |
| 70 | + 'MongoChangeStreamError', |
| 71 | + 'MongoClient', |
| 72 | + 'MongoCompatibilityError', |
| 73 | + 'MongoCursorExhaustedError', |
| 74 | + 'MongoCursorInUseError', |
| 75 | + 'MongoDecompressionError', |
| 76 | + 'MongoDriverError', |
| 77 | + 'MongoError', |
| 78 | + 'MongoErrorLabel', |
| 79 | + 'MongoExpiredSessionError', |
| 80 | + 'MongoGridFSChunkError', |
| 81 | + 'MongoGridFSStreamError', |
| 82 | + 'MongoInvalidArgumentError', |
| 83 | + 'MongoKerberosError', |
| 84 | + 'MongoMissingCredentialsError', |
| 85 | + 'MongoMissingDependencyError', |
| 86 | + 'MongoNetworkError', |
| 87 | + 'MongoNetworkTimeoutError', |
| 88 | + 'MongoNotConnectedError', |
| 89 | + 'MongoParseError', |
| 90 | + 'MongoRuntimeError', |
| 91 | + 'MongoServerClosedError', |
| 92 | + 'MongoServerError', |
| 93 | + 'MongoServerSelectionError', |
| 94 | + 'MongoSystemError', |
| 95 | + 'MongoTailableCursorError', |
| 96 | + 'MongoTopologyClosedError', |
| 97 | + 'MongoTransactionError', |
| 98 | + 'MongoUnexpectedServerResponseError', |
| 99 | + 'MongoWriteConcernError', |
| 100 | + 'ObjectId', |
| 101 | + 'ObjectID', |
| 102 | + 'OrderedBulkOperation', |
| 103 | + 'ProfilingLevel', |
| 104 | + 'Promise', |
| 105 | + 'ReadConcern', |
| 106 | + 'ReadConcernLevel', |
| 107 | + 'ReadPreference', |
| 108 | + 'ReadPreferenceMode', |
| 109 | + 'ReturnDocument', |
| 110 | + 'ServerApiVersion', |
| 111 | + 'ServerClosedEvent', |
| 112 | + 'ServerDescriptionChangedEvent', |
| 113 | + 'ServerHeartbeatFailedEvent', |
| 114 | + 'ServerHeartbeatStartedEvent', |
| 115 | + 'ServerHeartbeatSucceededEvent', |
| 116 | + 'ServerOpeningEvent', |
| 117 | + 'ServerType', |
| 118 | + 'SrvPollingEvent', |
| 119 | + 'Timestamp', |
| 120 | + 'TopologyClosedEvent', |
| 121 | + 'TopologyDescriptionChangedEvent', |
| 122 | + 'TopologyOpeningEvent', |
| 123 | + 'TopologyType', |
| 124 | + 'UnorderedBulkOperation', |
| 125 | + 'WriteConcern' |
| 126 | +]; |
| 127 | + |
| 128 | +describe('mongodb entrypoint', () => { |
| 129 | + it('should export all and only the expected keys in expected_exports', () => { |
| 130 | + expect(sorted(Object.keys(mongodb), byStrings)).to.deep.equal( |
| 131 | + sorted(EXPECTED_EXPORTS, byStrings) |
| 132 | + ); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should export keys added by ts-node as undefined', () => { |
| 136 | + // If the array is empty, this test would be a no-op so we should remove it |
| 137 | + expect(TS_NODE_EXPORTS).to.have.length.greaterThan(0); |
| 138 | + for (const tsNodeExportKey of TS_NODE_EXPORTS) { |
| 139 | + expect(mongodb).to.have.property(tsNodeExportKey, undefined); |
| 140 | + } |
| 141 | + }); |
| 142 | +}); |
0 commit comments