不要怂,就是干,撸起袖子干!

Commit e7365ba6 by Aleksander Barszczewski Committed by Sushant

Fix: Sync Hook not called (#6681)

* Update hooks.js

Fixed error where `return` was called inside of a for loop. 
This prevented execution of more than one synchronous hook.

* Added tests for before/afterInit and before/afterDefine hooks

* sooo many new lines 🔥
1 parent aeaf1e57
# Future # Future
- [FIXED] Issue with sync hooks (before/afterInit, before/afterDefine) [#6680](https://github.com/sequelize/sequelize/issues/6680)
- [FIXED] MSSQL handle large bulk inserts #6866 - [FIXED] MSSQL handle large bulk inserts #6866
- [FIXED] describeTable returns a wrong value for primaryKey [#5756] (https://github.com/sequelize/sequelize/issues/5756) - [FIXED] describeTable returns a wrong value for primaryKey [#5756] (https://github.com/sequelize/sequelize/issues/5756)
- [FIXED] MSSQL LIMIT IN UPDATE [#6636](https://github.com/sequelize/sequelize/issues/6636) - [FIXED] MSSQL LIMIT IN UPDATE [#6636](https://github.com/sequelize/sequelize/issues/6636)
......
...@@ -106,7 +106,7 @@ const Hooks = { ...@@ -106,7 +106,7 @@ const Hooks = {
} }
debug(`running hook(sync) ${hookType}`); debug(`running hook(sync) ${hookType}`);
return hook.apply(this, hookArgs); hook.apply(this, hookArgs);
} }
return; return;
} }
......
...@@ -302,4 +302,54 @@ describe(Support.getTestDialectTeaser('Hooks'), function() { ...@@ -302,4 +302,54 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
return expect(this.Model.runHooks('beforeCreate')).to.be.rejectedWith('Forbidden'); return expect(this.Model.runHooks('beforeCreate')).to.be.rejectedWith('Forbidden');
}); });
}); });
describe('sync hooks', function() {
beforeEach(function () {
this.hook1 = sinon.spy();
this.hook2 = sinon.spy();
this.hook3 = sinon.spy();
this.hook4 = sinon.spy();
});
it('runs all beforInit/afterInit hooks', function() {
Support.Sequelize.addHook('beforeInit', 'h1', this.hook1);
Support.Sequelize.addHook('beforeInit', 'h2', this.hook2);
Support.Sequelize.addHook('afterInit', 'h3', this.hook3);
Support.Sequelize.addHook('afterInit', 'h4', this.hook4);
Support.createSequelizeInstance();
expect(this.hook1).to.have.been.calledOnce;
expect(this.hook2).to.have.been.calledOnce;
expect(this.hook3).to.have.been.calledOnce;
expect(this.hook4).to.have.been.calledOnce;
// cleanup hooks on Support.Sequelize
Support.Sequelize.removeHook('beforeInit', 'h1');
Support.Sequelize.removeHook('beforeInit', 'h2');
Support.Sequelize.removeHook('afterInit', 'h3');
Support.Sequelize.removeHook('afterInit', 'h4');
Support.createSequelizeInstance();
// check if hooks were removed
expect(this.hook1).to.have.been.calledOnce;
expect(this.hook2).to.have.been.calledOnce;
expect(this.hook3).to.have.been.calledOnce;
expect(this.hook4).to.have.been.calledOnce;
});
it('runs all beforDefine/afterDefine hooks', function() {
const sequelize = Support.createSequelizeInstance();
sequelize.addHook('beforeDefine', this.hook1);
sequelize.addHook('beforeDefine', this.hook2);
sequelize.addHook('afterDefine', this.hook3);
sequelize.addHook('afterDefine', this.hook4);
sequelize.define('Test', {});
expect(this.hook1).to.have.been.calledOnce;
expect(this.hook2).to.have.been.calledOnce;
expect(this.hook3).to.have.been.calledOnce;
expect(this.hook4).to.have.been.calledOnce;
});
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!