mirror of
https://github.com/knex/knex.git
synced 2025-10-04 20:46:04 +00:00

Only left alone ones in `test/tape/transactions.js` which would just cause unnecessary conflicts and get cleaned up by separate pull request #1257 anyway.
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
'use strict';
|
|
var tape = require('tape')
|
|
var Promise = require('bluebird')
|
|
var debug = require('debug')('knex:tests')
|
|
|
|
module.exports = function(tableName, knex) {
|
|
|
|
return function(name, dialects, cb) {
|
|
|
|
if (arguments.length === 2) {
|
|
cb = dialects
|
|
} else {
|
|
if (!Array.isArray(dialects)) {
|
|
dialects = [dialects]
|
|
}
|
|
if (dialects.indexOf(knex.client.dialect) === -1) {
|
|
debug('Skipping dialect ' + knex.client.dialect + ' for test ' + name)
|
|
return;
|
|
}
|
|
}
|
|
|
|
return tape(name, function(t) {
|
|
|
|
var hasPlanned = false
|
|
|
|
t.on('plan', function() { hasPlanned = true })
|
|
|
|
var disposable = Promise.resolve(true).disposer(function() {
|
|
return knex.truncate(tableName).finally(function() {
|
|
t.end()
|
|
})
|
|
})
|
|
|
|
Promise.using(disposable, function() {
|
|
var val = cb(t)
|
|
if (val && typeof val.then === 'function') {
|
|
return val.catch(function(err) {
|
|
t.error(err)
|
|
})
|
|
} else {
|
|
t.error(new Error('A promise should be returned to test ' + name))
|
|
t.end()
|
|
}
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} |