diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index aeec8a62a9..3f190a3145 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -832,21 +832,6 @@ functions: ${PREPARE_SHELL} ${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh - "run bson-ext test": - - command: subprocess.exec - type: test - params: - working_dir: "src" - timeout_secs: 60 - env: - PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} - MONGODB_URI: ${MONGODB_URI} - TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT} - binary: bash - args: - - '${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh' - - "upload test results": # Upload the xunit-format test results. - command: attach.xunit_results diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 29dcbcebcf..739ceaf64f 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -790,19 +790,6 @@ functions: script: | ${PREPARE_SHELL} ${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh - run bson-ext test: - - command: subprocess.exec - type: test - params: - working_dir: src - timeout_secs: 60 - env: - PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} - MONGODB_URI: ${MONGODB_URI} - TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT} - binary: bash - args: - - ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh upload test results: - command: attach.xunit_results params: @@ -2131,40 +2118,6 @@ tasks: variant: '*' status: '*' patch_optional: true - - name: run-bson-ext-integration - tags: - - run-custom-dependency-tests - commands: - - func: install dependencies - vars: - NODE_LTS_NAME: fermium - - func: bootstrap mongo-orchestration - vars: - VERSION: '5.0' - TOPOLOGY: server - AUTH: auth - - name: run-bson-ext-integration - func: run bson-ext test - vars: - NODE_LTS_NAME: fermium - TEST_NPM_SCRIPT: check:test - - name: run-bson-ext-unit - tags: - - run-custom-dependency-tests - commands: - - func: install dependencies - vars: - NODE_LTS_NAME: fermium - - func: bootstrap mongo-orchestration - vars: - VERSION: '5.0' - TOPOLOGY: server - AUTH: auth - - name: run-bson-ext-unit - func: run bson-ext test - vars: - NODE_LTS_NAME: fermium - TEST_NPM_SCRIPT: check:unit - name: run-custom-csfle-tests-5.0-pinned-commit tags: - run-custom-dependency-tests @@ -3060,8 +3013,6 @@ buildvariants: display_name: Custom Dependency Version Test run_on: rhel80-large tasks: - - run-bson-ext-integration - - run-bson-ext-unit - run-custom-csfle-tests-5.0-pinned-commit - run-custom-csfle-tests-5.0-master - run-custom-csfle-tests-rapid-pinned-commit diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 19315718be..295d239baf 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -576,46 +576,7 @@ BUILD_VARIANTS.push({ tasks: AWS_AUTH_TASKS }); -const oneOffFuncs = [ - { - name: 'run-bson-ext-integration', - func: 'run bson-ext test', - vars: { - NODE_LTS_NAME: LOWEST_LTS, - TEST_NPM_SCRIPT: 'check:test' - } - }, - { - name: 'run-bson-ext-unit', - func: 'run bson-ext test', - vars: { - NODE_LTS_NAME: LOWEST_LTS, - TEST_NPM_SCRIPT: 'check:unit' - } - } -]; - -const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({ - name: oneOffFunc.name, - tags: ['run-custom-dependency-tests'], - commands: [ - { - func: 'install dependencies', - vars: { - NODE_LTS_NAME: LOWEST_LTS - } - }, - { - func: 'bootstrap mongo-orchestration', - vars: { - VERSION: '5.0', - TOPOLOGY: 'server', - AUTH: 'auth' - } - }, - oneOffFunc - ] -})); +const oneOffFuncAsTasks = [] for (const version of ['5.0', 'rapid', 'latest']) { for (const ref of ['ddb19ae22dc4a5f8b9208096f69fc23e19bae6c9', 'master']) { diff --git a/.evergreen/run-bson-ext-test.sh b/.evergreen/run-bson-ext-test.sh deleted file mode 100755 index 112ba611aa..0000000000 --- a/.evergreen/run-bson-ext-test.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh - -set -o xtrace # Write all commands first to stderr -set -o errexit # Exit the script with error if any of the commands fail - -# Supported/used environment variables: -# SSL Set to enable SSL. Defaults to "nossl" -# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info) -# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test" - -MONGODB_URI=${MONGODB_URI:-} -TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:test} - -# ssl setup -SSL=${SSL:-nossl} -if [ "$SSL" != "nossl" ]; then - export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem" - export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem" -fi - -# run tests -echo "Running $AUTH tests over $SSL, connecting to $MONGODB_URI" - -npm install mongodb-client-encryption@">=2.3.0" -npm install bson-ext - -export MONGODB_API_VERSION=${MONGODB_API_VERSION} -export MONGODB_URI=${MONGODB_URI} - -npm run "${TEST_NPM_SCRIPT}" diff --git a/README.md b/README.md index 94131a8f63..ea175a50e7 100644 --- a/README.md +++ b/README.md @@ -71,16 +71,24 @@ If you are a Typescript user, you will need the Node.js type definitions to use npm install -D @types/node ``` -## Troubleshooting +## Driver Extensions -The MongoDB driver depends on several other packages. These are: +The MongoDB driver can optionally be enhanced by the following feature packages: -- [bson](https://github.com/mongodb/js-bson) -- [bson-ext](https://github.com/mongodb-js/bson-ext) -- [kerberos](https://github.com/mongodb-js/kerberos) -- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme) +Maintained by MongoDB: + +- Zstd network compression - [@mongodb-js/zstd](https://github.com/mongodb-js/zstd) +- MongoDB field level and queryable encryption - [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme) +- GSSAPI / SSPI / Kerberos authentication - [kerberos](https://github.com/mongodb-js/kerberos) + +Some of these packages include native C++ extensions. +Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into compilation issues. + +Third party: + +- Snappy network compression - [snappy](https://github.com/Brooooooklyn/snappy) +- AWS authentication - [@aws-sdk/credential-providers](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers) -Some of these packages include native C++ extensions. Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into issues. ## Quick Start diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index 30f76f22dc..7a24e8b474 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -192,9 +192,13 @@ await collection.insertMany([{ name: 'fido' }, { name: 'luna' }]) The `keepGoing` option was a legacy name for setting `ordered` to `false` for bulk inserts. It was only supported by the legacy `collection.insert()` method which is now removed as noted above. +### `bson-ext` support removed + +The `bson-ext` package will no longer automatically import and supplant the `bson` dependency. + ### `BulkWriteResult` no longer contains a publicly enumerable `result` property. -To access the raw result, please use `bulkWriteResult.getRawResponse()`. +To access the raw result, please use `bulkWriteResult.getRawResponse()`. ### `BulkWriteResult` now contains individual ressult properties. diff --git a/src/bson.ts b/src/bson.ts index 88a4dc9005..4c3d865741 100644 --- a/src/bson.ts +++ b/src/bson.ts @@ -1,34 +1,14 @@ -import type { - calculateObjectSize as calculateObjectSizeFn, - deserialize as deserializeFn, - DeserializeOptions, - serialize as serializeFn, - SerializeOptions -} from 'bson'; - -/** @internal */ -// eslint-disable-next-line @typescript-eslint/no-var-requires -let BSON = require('bson'); - -try { - // Ensure you always wrap an optional require in the try block NODE-3199 - BSON = require('bson-ext'); -} catch {} // eslint-disable-line - -/** @internal */ -export const deserialize = BSON.deserialize as typeof deserializeFn; -/** @internal */ -export const serialize = BSON.serialize as typeof serializeFn; -/** @internal */ -export const calculateObjectSize = BSON.calculateObjectSize as typeof calculateObjectSizeFn; +import type { DeserializeOptions, SerializeOptions } from 'bson'; export { Binary, BSONRegExp, BSONSymbol, + calculateObjectSize, Code, DBRef, Decimal128, + deserialize, Document, Double, Int32, @@ -37,10 +17,15 @@ export { MaxKey, MinKey, ObjectId, + serialize, Timestamp } from 'bson'; +// TODO(NODE-4867): fix with bson v5 /** @internal */ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const BSON = require('bson'); + export { BSON }; /** diff --git a/test/benchmarks/driverBench/index.js b/test/benchmarks/driverBench/index.js index c798e5d81b..f9f420e2e9 100644 --- a/test/benchmarks/driverBench/index.js +++ b/test/benchmarks/driverBench/index.js @@ -8,12 +8,6 @@ let bsonType = 'js-bson'; // TODO(NODE-4606): test against different driver configurations in CI const BSON = require('bson'); -// try { -// BSON = require('bson-ext'); -// bsonType = 'bson-ext'; -// } catch (_) { -// // do not care -// } const { inspect } = require('util'); const { writeFile } = require('fs/promises'); diff --git a/test/tools/utils.ts b/test/tools/utils.ts index 75be56c9f3..7c27884009 100644 --- a/test/tools/utils.ts +++ b/test/tools/utils.ts @@ -507,13 +507,6 @@ export class UnifiedTestSuiteBuilder { } } -/** Test whether the driver is using bson-ext */ -export function isBSONExtImported() { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const driverBSON = require('../mongodb'); - 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; diff --git a/test/unit/bson.test.js b/test/unit/bson.test.js index a555e24bb9..19e1407a5b 100644 --- a/test/unit/bson.test.js +++ b/test/unit/bson.test.js @@ -2,7 +2,6 @@ const { expect } = require('chai'); const BSON = require('../mongodb'); -const { isBSONExtImported } = require('../tools/utils'); describe('When importing BSON', function () { const types = [ @@ -27,56 +26,22 @@ describe('When importing BSON', function () { bsonRegExp: true }; - function testTypes() { - for (const [type, ctorArg] of types) { - it(`should correctly round trip ${type}`, function () { - const typeCtor = BSON[type]; - expect(typeCtor).to.be.a('function'); - const doc = { key: new typeCtor(ctorArg) }; - const outputDoc = BSON.deserialize(BSON.serialize(doc), options); - expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor); - expect(outputDoc).to.deep.equal(doc); - }); - } - - it('should correctly round trip Map', function () { - expect(BSON.Map).to.be.a('function'); - const doc = { key: new BSON.Map([['2', 2]]) }; - const outputDoc = BSON.deserialize(BSON.serialize(doc)); - expect(outputDoc).to.have.nested.property('key.2', 2); + for (const [type, ctorArg] of types) { + it(`should correctly round trip ${type}`, function () { + const typeCtor = BSON[type]; + expect(typeCtor).to.be.a('function'); + const doc = { key: new typeCtor(ctorArg) }; + const outputDoc = BSON.deserialize(BSON.serialize(doc), options); + expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor); + expect(outputDoc).to.deep.equal(doc); }); } - describe('bson-ext', function () { - before(function () { - if (!isBSONExtImported()) { - this.skip(); - } - }); - - it('should be imported if it exists', function () { - expect(BSON.deserialize.toString()).to.include('[native code]'); - expect(BSON.serialize.toString()).to.include('[native code]'); - expect(BSON.calculateObjectSize.toString()).to.include('[native code]'); - }); - - testTypes(); - }); - - describe('js-bson', function () { - before(function () { - if (isBSONExtImported()) { - this.skip(); - } - }); - - it('should be imported by default', function () { - expect(BSON.deserialize.toString()).to.not.include('[native code]'); - expect(BSON.serialize.toString()).to.not.include('[native code]'); - expect(BSON.calculateObjectSize.toString()).to.not.include('[native code]'); - }); - - testTypes(); + it('should correctly round trip Map', function () { + expect(BSON.Map).to.be.a('function'); + const doc = { key: new BSON.Map([['2', 2]]) }; + const outputDoc = BSON.deserialize(BSON.serialize(doc)); + expect(outputDoc).to.have.nested.property('key.2', 2); }); }); diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 1979655c58..0ff4f0c5ff 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import * as BSON from '../mongodb'; import { BinMsg, MessageHeader } from '../mongodb'; -import { isBSONExtImported } from '../tools/utils'; const msgHeader: MessageHeader = { length: 735, @@ -42,232 +41,105 @@ const nKeyWithInvalidUtf8 = const msgBodyNKeyWithInvalidUtf8 = Buffer.from(nKeyWithInvalidUtf8, 'hex'); describe('BinMsg BSON utf8 validation', () => { - describe('when bson-ext is installed', () => { - beforeEach(function () { - if (!isBSONExtImported()) { - if (this.currentTest) - this.currentTest.skipReason = 'tests require driver to be using bson-ext'; - this.skip(); - } - }); - - it('throws when invalid utf8 in writeErrors object regardless of options', () => { - // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - const options = { validation: { utf8: { writeErrors: false } as const } }; - const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); - expect(deserializerCall).to.throw(Error, 'Invalid UTF8 string found'); - }); + it('correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { + // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - context('when enableUtf8Validation option is not specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); + const options = { validation: { utf8: { writeErrors: false } as const } }; + const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); + expect(deserializerCall()).to.deep.equals(invalidUtf8InWriteErrorsJSON); + }); - const options = {}; - it('should validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + context('when enableUtf8Validation option is not specified', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + const options = {}; + it('does not validate the writeErrors key', () => { + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - context('when validation is disabled', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('validates keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 + ); + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); + }); + }); - const options = { enableUtf8Validation: false }; - it('should validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + context('when validation is disabled', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + const options = { enableUtf8Validation: false }; + it('should not validate the writeErrors key', () => { + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - it('should still validate for writeErrors if no validation specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('does not validate keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 ); - const options = { - bsonRegExp: false, - promoteBuffers: false, - promoteLongs: true, - promoteValues: true - }; - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.not.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); }); - - context('utf8 validation enabled', () => { - const options = { enableUtf8Validation: true }; - it('should validate the writeErrors key', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); - }); }); - describe('when js-bson is installed', () => { - beforeEach(function () { - if (isBSONExtImported()) { - if (this.currentTest) this.currentTest.skipReason = 'tests require driver to be using bson'; - this.skip(); - } - }); - - it('bson correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { - // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - - const options = { validation: { utf8: { writeErrors: false } as const } }; - const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); - expect(deserializerCall()).to.deep.equals(invalidUtf8InWriteErrorsJSON); - }); + it('disables validation by default for writeErrors if no validation specified', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); + const options = { + bsonRegExp: false, + promoteBuffers: false, + promoteLongs: true, + promoteValues: true + }; + + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); + }); - context('when enableUtf8Validation option is not specified', () => { + context('utf8 validation enabled', () => { + const options = { enableUtf8Validation: true }; + it('does not validate the writeErrors key', () => { const binMsgInvalidUtf8ErrorMsg = new BinMsg( Buffer.alloc(0), msgHeader, msgBodyInvalidUtf8WriteErrors ); - const options = {}; - it('does not validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); - }); - - context('when validation is disabled', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).not.to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); - - const options = { enableUtf8Validation: false }; - it('should not validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - it('should not validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.not.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); }); - it('should by default disable validation for writeErrors if no validation specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('validates keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 + ); + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); - const options = { - bsonRegExp: false, - promoteBuffers: false, - promoteLongs: true, - promoteValues: true - }; - - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - context('utf8 validation enabled', () => { - const options = { enableUtf8Validation: true }; - it('should not validate the writeErrors key', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); - - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).not.to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); }); }); });