Skip to content

Commit

Permalink
test: allow easier test debugging via TEDIOUS_DEBUG env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed Aug 5, 2023
1 parent b78df14 commit 649c6e5
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 220 deletions.
24 changes: 24 additions & 0 deletions test/helpers/debug-options-from-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export function debugOptionsFromEnv() {
const options = {
packet: false,
data: false,
payload: false,
token: false,
};

if (!process.env.TEDIOUS_DEBUG) {
return options;
}

for (const type of process.env.TEDIOUS_DEBUG.split(',')) {
switch (type) {
case 'packet':
case 'data':
case 'payload':
case 'token':
options[type] = true;
}
}

return options;
}
14 changes: 6 additions & 8 deletions test/integration/binary-insert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ const TYPES = require('../../src/data-type').typeByName;

import Connection from '../../src/connection';
import Request from '../../src/request';
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';

const config = JSON.parse(
fs.readFileSync(require('os').homedir() + '/.tedious/test-connection.json', 'utf8')
).config;

config.options.debug = {
packet: true,
data: true,
payload: true,
token: true,
log: true
};

config.options.debug = debugOptionsFromEnv();
config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION;

describe('inserting binary data', function() {
Expand All @@ -28,6 +22,10 @@ describe('inserting binary data', function() {
beforeEach(function(done) {
this.connection = new Connection(config);
this.connection.connect(done);

if (process.env.TEDIOUS_DEBUG) {
this.connection.on('debug', console.log);
}
});

afterEach(function(done) {
Expand Down
26 changes: 9 additions & 17 deletions test/integration/bulk-load-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const TYPES = require('../../src/data-type').typeByName;
import Connection from '../../src/connection';
import { RequestError } from '../../src/errors';
import Request from '../../src/request';

const debugMode = false;
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';

function getConfig() {
const { config } = JSON.parse(
Expand All @@ -21,14 +20,7 @@ function getConfig() {

config.options.cancelTimeout = 1000;

if (debugMode) {
config.options.debug = {
packet: true,
data: true,
payload: true,
token: true
};
}
config.options.debug = debugOptionsFromEnv();

return config;
}
Expand All @@ -43,14 +35,14 @@ describe('BulkLoad', function() {
connection = new Connection(getConfig());
connection.connect(done);

if (debugMode) {
if (process.env.TEDIOUS_DEBUG) {
connection.on('debug', (message) => console.log(message));
connection.on('infoMessage', (info) =>
console.log('Info: ' + info.number + ' - ' + info.message)
);
connection.on('errorMessage', (error) =>
console.log('Error: ' + error.number + ' - ' + error.message)
);
connection.on('infoMessage', (info) => {
console.log('Info: ' + info.number + ' - ' + info.message);
});
connection.on('errorMessage', (error) => {
console.log('Error: ' + error.number + ' - ' + error.message);
});
}
});

Expand Down
7 changes: 7 additions & 0 deletions test/integration/collation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import Connection from '../../src/connection';
import Request from '../../src/request';
import { Flags } from '../../src/collation';
import { TYPES } from '../../src/data-type';
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';

function getConfig() {
const { config } = JSON.parse(
fs.readFileSync(homedir() + '/.tedious/test-connection.json', 'utf8')
);

config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION;
config.options.debug = debugOptionsFromEnv();

return config;
}
Expand All @@ -33,6 +35,11 @@ describe('Database Collation Support', function() {
connection.once('databaseChange', (databaseName) => {
originalDatabaseName = databaseName;
});

if (process.env.TEDIOUS_DEBUG) {
connection.on('debug', console.log);
}

connection.connect(done);
});

Expand Down
Loading

0 comments on commit 649c6e5

Please sign in to comment.