2015-04-24 10:10:34 -04:00
|
|
|
'use strict';
|
2018-10-15 22:29:53 -04:00
|
|
|
const tape = require('tape');
|
|
|
|
const debug = require('debug')('knex:tests');
|
2015-04-24 10:10:34 -04:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
module.exports = function (tableName, knex) {
|
|
|
|
return function (name, dialects, cb) {
|
2015-04-24 15:20:35 -04:00
|
|
|
if (arguments.length === 2) {
|
2018-07-09 08:10:34 -04:00
|
|
|
cb = dialects;
|
2015-04-24 15:20:35 -04:00
|
|
|
} else {
|
|
|
|
if (!Array.isArray(dialects)) {
|
2018-07-09 08:10:34 -04:00
|
|
|
dialects = [dialects];
|
2015-04-24 15:20:35 -04:00
|
|
|
}
|
|
|
|
if (dialects.indexOf(knex.client.dialect) === -1) {
|
2018-07-09 08:10:34 -04:00
|
|
|
debug('Skipping dialect ' + knex.client.dialect + ' for test ' + name);
|
2015-04-24 15:20:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
return tape(name, async function (t) {
|
2020-02-25 03:24:30 +03:00
|
|
|
const val = cb(t);
|
|
|
|
try {
|
|
|
|
if (!val || typeof val.then !== 'function') {
|
|
|
|
throw new Error('A promise should be returned to test ' + name);
|
2015-04-24 10:10:34 -04:00
|
|
|
}
|
2020-02-25 03:24:30 +03:00
|
|
|
|
|
|
|
await val;
|
|
|
|
} catch (err) {
|
|
|
|
t.error(err);
|
|
|
|
} finally {
|
|
|
|
await knex.truncate(tableName).catch((e) => t.fail(e));
|
|
|
|
t.end();
|
|
|
|
}
|
2018-07-09 08:10:34 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|