Skip to content

Commit

Permalink
Respect KNEX_TEST, support omitting sqlite3 from DB, and reduce outsi…
Browse files Browse the repository at this point in the history
…de mssql test db config (#4313)
  • Loading branch information
jeremy-w committed Feb 24, 2021
1 parent c58794b commit 3718d64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
10 changes: 9 additions & 1 deletion test/integration2/transaction/set-isolation-level.spec.js
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 8 additions & 6 deletions test/integration2/util/knex-instance-provider.js
@@ -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',
Expand Down Expand Up @@ -52,7 +54,7 @@ const seeds = {
const testConfigs = {
mysql: {
client: 'mysql',
connection: {
connection: testConfig.mysql || {
port: 23306,
database: 'knex_test',
host: 'localhost',
Expand All @@ -67,7 +69,7 @@ const testConfigs = {

mysql2: {
client: 'mysql2',
connection: {
connection: testConfig.mysql || {
port: 23306,
database: 'knex_test',
host: 'localhost',
Expand All @@ -82,7 +84,7 @@ const testConfigs = {

postgres: {
client: 'postgres',
connection: {
connection: testConfig.postgres || {
adapter: 'postgresql',
port: 25432,
host: 'localhost',
Expand All @@ -97,15 +99,15 @@ const testConfigs = {

sqlite3: {
client: 'sqlite3',
connection: ':memory:',
connection: testConfig.sqlite3 || ':memory:',
pool: poolSqlite,
migrations,
seeds,
},

mssql: {
client: 'mssql',
connection: {
connection: testConfig.mssql || {
user: 'sa',
password: 'S0meVeryHardPassword',
server: 'localhost',
Expand All @@ -119,7 +121,7 @@ const testConfigs = {

oracledb: {
client: 'oracledb',
connection: {
connection: testConfig.oracledb || {
user: 'system',
password: 'Oracle18',
connectString: 'localhost:21521/XE',
Expand Down
16 changes: 11 additions & 5 deletions test/unit/knex.js
Expand Up @@ -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' });
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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:');
Expand Down

0 comments on commit 3718d64

Please sign in to comment.