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

support.js 756 Bytes
'use strict';

const Support = require('../support');

const runningQueries = new Set();

before(function() {
  this.sequelize.addHook('beforeQuery', (options, query) => {
    runningQueries.add(query);
  });
  this.sequelize.addHook('afterQuery', (options, query) => {
    runningQueries.delete(query);
  });
});

beforeEach(function() {
  return Support.clearDatabase(this.sequelize);
});

afterEach(function() {
  if (runningQueries.size === 0) {
    return;
  }
  let msg = `Expected 0 running queries. ${runningQueries.size} queries still running in ${this.currentTest.fullTitle()}\n`;
  msg += 'Queries:\n\n';
  msg += [...runningQueries].map(query => `${query.uuid}: ${query.sql}`).join('\n');
  throw new Error(msg);
});

module.exports = Support;