From 45fa0c1d35a9ffaa67180ac3c758cbde0e210d88 Mon Sep 17 00:00:00 2001 From: Alec Gibson <12036746+alecgibson@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:07:20 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Fix=20`npm=20test`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is broken in a fresh install: ``` npm install npm test ``` This is because `npm` will fetch `mongodb@5` (the latest it can), but running `npm test` without the `_SHAREDB_MONGODB_DRIVER` variable set means that the map reduce test still runs, when `mongodb@5` doesn't support it. This change tweaks the test to check if the function is defined, instead of relying on the environment variable. --- test/test_mongo.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_mongo.js b/test/test_mongo.js index 40d0e4a..79e1f73 100644 --- a/test/test_mongo.js +++ b/test/test_mongo.js @@ -334,9 +334,10 @@ describe('mongo db', function() { }); it('$mapReduce queries should work when allowJavaScriptQuery == true', function(done) { - if (process.env._SHAREDB_MONGODB_DRIVER === 'mongodb5') { - // This function was removed in mongodb5: - // https://github.com/mongodb/node-mongodb-native/pull/3511 + // This function was removed in mongodb5: + // https://github.com/mongodb/node-mongodb-native/pull/3511 + var mapReduceSupported = typeof this.db.mongo.collection('test').mapReduce === 'function'; + if (!mapReduceSupported) { return done(); } var snapshots = [