test-runner.js 827 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Given a db flavor and a query object, generate the SQL statement and test
  3. * it against the expected outcome.
  4. */
  5. var assert = require('assert');
  6. var async = require('async');
  7. var GeneratorFn = require('../../index');
  8. module.exports = function(test, cb) {
  9. var testDialect = function testDialect(outcome, next) {
  10. var generator = GeneratorFn({ dialect: outcome.dialect });
  11. var results = generator.generate(test.query);
  12. try {
  13. assert.equal(results.sql, outcome.sql, outcome.dialect);
  14. if (outcome.bindings) {
  15. assert.deepEqual(results.bindings, outcome.bindings, outcome.dialect);
  16. }
  17. } catch (e) {
  18. e.dialect = outcome.dialect;
  19. return cb(e);
  20. }
  21. return async.setImmediate(function() {
  22. next();
  23. });
  24. };
  25. async.each(test.outcomes, testDialect, cb);
  26. };