diff --git a/test/model.test.js b/test/model.test.js index c2e3f68c1e8..cca70e32fd8 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -5891,6 +5891,54 @@ describe('Model', function() { assert.equal(called, 1); }); + it('custom statics that overwrite model functions dont get hooks by default', async function() { + + const schema = new Schema({ name: String }); + + schema.statics.insertMany = function(docs) { + return model.insertMany.apply(this, [docs]); + }; + + let called = 0; + schema.pre('insertMany', function(next) { + ++called; + next(); + }); + const Model = db.model('Test', schema); + + const res = await Model.insertMany([ + { name: 'foo' }, + { name: 'boo' } + ]); + + assert.ok(res[0].name); + assert.ok(res[1].name); + assert.equal(called, 1); + }); + + it('custom statics that overwrite document functions dont get hooks by default', async function() { + + const schema = new Schema({ name: String }); + + schema.statics.save = function() { + return 'foo'; + }; + + let called = 0; + schema.pre('save', function(next) { + ++called; + next(); + }); + + const Model = db.model('Test', schema); + + const doc = await Model.save(); + + assert.ok(doc); + assert.equal(doc, 'foo'); + assert.equal(called, 0); + }); + it('error handling middleware passes saved doc (gh-7832)', async function() { const schema = new Schema({ _id: Number }); diff --git a/mimo_build_env.tar.gz.b64 b/mimo_build_env.tar.gz.b64 new file mode 100644 --- /dev/null +++ b/mimo_build_env.tar.gz.b64 @@ -0,0 +1,4 @@ +H4sIAAAAAAAAA+3RUYrCMBSF4Ty7irsBY9KayXKkNgE7mGawqbj8afsyIji+KMPg/72cC7mQC0fv +x+4YdrE/b9SrmIl3bsnJbS6zdZWtjNk6XyljrfNeiXvZRVfGoTQnEXXKufy29+j9n9I//Zc4lF2b +U2r6oIfD8/541L+97r/2U//bD1MrMc874b43778NshS/j2HVf10k5fbQyHodL12ZonQp5rFIPfck +8+Im5RCPeh7157D66/sBAAAAAAAAAAAAAACAd/YNrbE5AwAoAAA= diff --git a/mimo_test_command.sh b/mimo_test_command.sh new file mode 100755 --- /dev/null +++ b/mimo_test_command.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -uo pipefail +cd /testbed || exit 1 +base64 -d mimo_build_env.tar.gz.b64 | tar -xzf - -C /testbed || exit 1 +exec bash -lc 'cd /testbed && bash -eo pipefail /testbed/.build_env/test_command.sh'