mirror of
https://github.com/knex/knex.git
synced 2025-12-27 06:58:39 +00:00
Respect KNEX_TEST, support omitting sqlite3 from DB, and reduce outside mssql test db config (#4313)
This commit is contained in:
parent
c58794b2ad
commit
3718d647e4
@ -10,6 +10,14 @@ describe('Transaction', () => {
|
||||
const tableName = 'key_value';
|
||||
before(() => {
|
||||
knex = getKnexForDb(db);
|
||||
|
||||
if (isMssql(knex)) {
|
||||
// Enable the snapshot isolation level required by certain transaction tests.
|
||||
return knex.raw(
|
||||
`ALTER DATABASE :db: SET ALLOW_SNAPSHOT_ISOLATION ON`,
|
||||
{ db: knex.context.client.config.connection.database }
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@ -46,7 +54,7 @@ describe('Transaction', () => {
|
||||
if (isSQLite(knex) || isOracle(knex)) {
|
||||
return;
|
||||
}
|
||||
// NOTE: for mssql, it requires an alter database call that happens in docker-compose
|
||||
// NOTE: mssql requires an alter database call to enable the snapshot isolation level.
|
||||
const isolationLevel = isMssql(knex) ? 'snapshot' : 'repeatable read';
|
||||
const trx = await knex.transaction({ isolationLevel });
|
||||
const result1 = await trx(tableName).select();
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
const { promisify } = require('util');
|
||||
const knex = require('../../../lib');
|
||||
const testConfig =
|
||||
(process.env.KNEX_TEST && require(process.env.KNEX_TEST)) || {};
|
||||
|
||||
const Db = {
|
||||
PostgresSQL: 'postgres',
|
||||
@ -52,7 +54,7 @@ const seeds = {
|
||||
const testConfigs = {
|
||||
mysql: {
|
||||
client: 'mysql',
|
||||
connection: {
|
||||
connection: testConfig.mysql || {
|
||||
port: 23306,
|
||||
database: 'knex_test',
|
||||
host: 'localhost',
|
||||
@ -67,7 +69,7 @@ const testConfigs = {
|
||||
|
||||
mysql2: {
|
||||
client: 'mysql2',
|
||||
connection: {
|
||||
connection: testConfig.mysql || {
|
||||
port: 23306,
|
||||
database: 'knex_test',
|
||||
host: 'localhost',
|
||||
@ -82,7 +84,7 @@ const testConfigs = {
|
||||
|
||||
postgres: {
|
||||
client: 'postgres',
|
||||
connection: {
|
||||
connection: testConfig.postgres || {
|
||||
adapter: 'postgresql',
|
||||
port: 25432,
|
||||
host: 'localhost',
|
||||
@ -97,7 +99,7 @@ const testConfigs = {
|
||||
|
||||
sqlite3: {
|
||||
client: 'sqlite3',
|
||||
connection: ':memory:',
|
||||
connection: testConfig.sqlite3 || ':memory:',
|
||||
pool: poolSqlite,
|
||||
migrations,
|
||||
seeds,
|
||||
@ -105,7 +107,7 @@ const testConfigs = {
|
||||
|
||||
mssql: {
|
||||
client: 'mssql',
|
||||
connection: {
|
||||
connection: testConfig.mssql || {
|
||||
user: 'sa',
|
||||
password: 'S0meVeryHardPassword',
|
||||
server: 'localhost',
|
||||
@ -119,7 +121,7 @@ const testConfigs = {
|
||||
|
||||
oracledb: {
|
||||
client: 'oracledb',
|
||||
connection: {
|
||||
connection: testConfig.oracledb || {
|
||||
user: 'system',
|
||||
password: 'Oracle18',
|
||||
connectString: 'localhost:21521/XE',
|
||||
|
||||
@ -366,11 +366,14 @@ describe('knex', () => {
|
||||
});
|
||||
|
||||
describe('transaction', () => {
|
||||
it('transaction of a copy with userParams retains userparams', async function () {
|
||||
before(function skipSuiteIfSqliteConfigAbsent() {
|
||||
// This is the case when the |DB| environment parameter does not include |sqlite|.
|
||||
if (!sqliteConfig) {
|
||||
return this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
it('transaction of a copy with userParams retains userparams', async function () {
|
||||
const knex = Knex(sqliteConfig);
|
||||
|
||||
const knexWithParams = knex.withUserParams({ userParam: '451' });
|
||||
@ -599,10 +602,6 @@ describe('knex', () => {
|
||||
});
|
||||
|
||||
it('creating transaction copy with user params should throw an error', async function () {
|
||||
if (!sqliteConfig) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
const knex = Knex(sqliteConfig);
|
||||
|
||||
await knex.transaction(async (trx) => {
|
||||
@ -639,6 +638,13 @@ describe('knex', () => {
|
||||
});
|
||||
|
||||
describe('extend query builder', () => {
|
||||
before(function skipSuiteIfSqliteConfigAbsent() {
|
||||
// This is the case when the |DB| environment parameter does not include |sqlite|.
|
||||
if (!sqliteConfig) {
|
||||
return this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
let connection;
|
||||
beforeEach(() => {
|
||||
connection = new sqlite3.Database(':memory:');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user