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

Commit d76b0a84 by Takashi Sasaki Committed by Sushant

fix(query): check valid warn message (#9919) (#9948)

1 parent fa2f3733
......@@ -178,6 +178,7 @@ class Query extends AbstractQuery {
const warningMessage = 'MySQL Warnings (' + (this.connection.uuid||'default') + '): ';
const messages = [];
for (const _warningRow of warningResults) {
if (typeof _warningRow ==='undefined' || typeof _warningRow[Symbol.iterator] !== 'function') continue;
for (const _warningResult of _warningRow) {
if (_warningResult.hasOwnProperty('Message')) {
messages.push(_warningResult.Message);
......
'use strict';
const chai = require('chai');
const expect = chai.expect;
const Support = require('../../../support');
const Sequelize = Support.Sequelize;
const dialect = Support.getTestDialect();
const sinon = require('sinon');
describe(Support.getTestDialectTeaser('Warning'), () => {
// We can only test MySQL warnings when using MySQL.
if (dialect === 'mysql') {
describe('logging', () => {
it('logs warnings when there are warnings', () => {
const logger = sinon.spy(console, 'log');
const sequelize = Support.createSequelizeInstance({
logging: logger,
benchmark: false,
showWarnings: true
});
const Model = sequelize.define('model', {
name: Sequelize.DataTypes.STRING(1, true)
});
return sequelize.sync({ force: true }).then(() => {
return sequelize.authenticate();
}).then(() => {
return sequelize.query("SET SESSION sql_mode='';");
}).then(() => {
return Model.create({
name: 'very-long-long-name'
});
}).then(() => {
// last log is warning message
expect(logger.args[logger.args.length - 1][0]).to.be.match(/^MySQL Warnings \(default\):.*/m);
}, () => {
expect.fail();
});
});
});
}
});
\ No newline at end of file
'use strict';
const path = require('path');
const Query = require(path.resolve('./lib/dialects/mysql/query.js'));
const Support = require(path.join(__dirname, './../../support'));
const chai = require('chai');
const sinon = require('sinon');
const current = Support.sequelize;
const expect = chai.expect;
describe('[MYSQL Specific] Query', () => {
describe('logWarnings', () => {
beforeEach(() => {
sinon.spy(console, 'log');
});
afterEach(() => {
console.log.restore();
});
it('check iterable', () => {
const validWarning = [];
const invalidWarning = {};
const warnings = [validWarning, undefined, invalidWarning];
const query = new Query({}, current, {});
const stub = sinon.stub(query, 'run');
stub.onFirstCall().resolves(warnings);
return query.logWarnings('dummy-results').then(results => {
expect('dummy-results').to.equal(results);
expect(true).to.equal(console.log.calledOnce);
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!