diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6d0c74..9ee014c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,7 @@ jobs: - 5.0 - 6.0 - 7.0 + - 8.0 services: mongodb: image: mongo:${{ matrix.mongodb }} diff --git a/package.json b/package.json index 6332045..18fec1c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "MongoDB database adapter for ShareDB", "main": "index.js", "dependencies": { - "mongodb": "^3.1.13 || ^4.0.0 || ^5.0.0 || ^6.0.0", + "mongodb": "^3.1.13 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0", "sharedb": "^1.9.1 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0" }, "devDependencies": { @@ -18,6 +18,7 @@ "mongodb4": "npm:mongodb@^4.0.0", "mongodb5": "npm:mongodb@^5.0.0", "mongodb6": "npm:mongodb@^6.0.0", + "mongodb7": "npm:mongodb@^7.0.0", "nyc": "^14.1.1", "ot-json1": "^1.0.1", "rich-text": "^4.1.0", @@ -33,7 +34,8 @@ "test:mongodb4": "_SHAREDB_MONGODB_DRIVER=mongodb4 npm test", "test:mongodb5": "_SHAREDB_MONGODB_DRIVER=mongodb5 npm test", "test:mongodb6": "_SHAREDB_MONGODB_DRIVER=mongodb6 npm test", - "test:all": "npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5 && npm run test:mongodb6", + "test:mongodb7": "_SHAREDB_MONGODB_DRIVER=mongodb7 npm test", + "test:all": "npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5 && npm run test:mongodb6 && npm run test:mongodb7", "test-cover": "nyc --temp-dir=coverage -r text -r lcov npm run test:all" }, "repository": "git://github.com/share/sharedb-mongo.git", diff --git a/test/test_mongo_middleware.js b/test/test_mongo_middleware.js index c4716aa..6c34f17 100644 --- a/test/test_mongo_middleware.js +++ b/test/test_mongo_middleware.js @@ -71,7 +71,10 @@ describe('mongo db middleware', function() { describe(BEFORE_EDIT, function() { it('has the expected properties on the request object', function(done) { + var middlewareEntranceCount = 0; + db.use(BEFORE_EDIT, function(request, next) { + middlewareEntranceCount = middlewareEntranceCount + 1; expect(request).to.have.all.keys([ 'action', 'collectionName', @@ -87,7 +90,6 @@ describe('mongo db middleware', function() { expect(request.options.testOptions).to.equal('yes'); expect(request.query._id).to.equal('test1'); next(); - done(); }); var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}}; @@ -98,6 +100,9 @@ describe('mongo db middleware', function() { if (err) return done(err); db.commit('testcollection', snapshot.id, editOp, newSnapshot, {testOptions: 'yes'}, function(err) { if (err) return done(err); + + expect(middlewareEntranceCount).to.equal(1); + done(); }); }); }); @@ -221,7 +226,10 @@ describe('mongo db middleware', function() { describe(BEFORE_SNAPSHOT_LOOKUP, function() { it('has the expected properties on the request object before getting a single snapshot', function(done) { + var middlewareEntranceCount = 0; + db.use(BEFORE_SNAPSHOT_LOOKUP, function(request, next) { + middlewareEntranceCount = middlewareEntranceCount + 1; expect(request).to.have.all.keys([ 'action', 'collectionName', @@ -233,7 +241,6 @@ describe('mongo db middleware', function() { expect(request.options.testOptions).to.equal('yes'); expect(request.query._id).to.equal('test1'); next(); - done(); }); var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}}; @@ -242,6 +249,8 @@ describe('mongo db middleware', function() { db.getSnapshot('testcollection', 'test1', null, {testOptions: 'yes'}, function(err, doc) { if (err) return done(err); expect(doc).to.exist; + expect(middlewareEntranceCount).to.equal(1); + done(); }); }); }); @@ -356,7 +365,9 @@ describe('mongo db middleware', function() { }); it('has the expected properties on the request object before getting bulk snapshots', function(done) { + var middlewareEntranceCount = 0; db.use(BEFORE_SNAPSHOT_LOOKUP, function(request, next) { + middlewareEntranceCount = middlewareEntranceCount + 1; expect(request).to.have.all.keys([ 'action', 'collectionName', @@ -368,7 +379,6 @@ describe('mongo db middleware', function() { expect(request.options.testOptions).to.equal('yes'); expect(request.query._id).to.deep.equal({$in: ['test1']}); next(); - done(); }); var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}}; @@ -377,6 +387,8 @@ describe('mongo db middleware', function() { db.getSnapshotBulk('testcollection', ['test1'], null, {testOptions: 'yes'}, function(err, doc) { if (err) return done(err); expect(doc).to.exist; + expect(middlewareEntranceCount).to.equal(1); + done(); }); }); });