Skip to content

Commit 4f3e210

Browse files
test: allow easier test debugging via TEDIOUS_DEBUG env variable (#1567)
1 parent 0f105c6 commit 4f3e210

15 files changed

Lines changed: 310 additions & 220 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function debugOptionsFromEnv() {
2+
const options = {
3+
packet: false,
4+
data: false,
5+
payload: false,
6+
token: false,
7+
};
8+
9+
if (!process.env.TEDIOUS_DEBUG) {
10+
return options;
11+
}
12+
13+
for (const type of process.env.TEDIOUS_DEBUG.split(',')) {
14+
switch (type) {
15+
case 'packet':
16+
case 'data':
17+
case 'payload':
18+
case 'token':
19+
options[type] = true;
20+
}
21+
}
22+
23+
return options;
24+
}

test/integration/binary-insert-test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@ const TYPES = require('../../src/data-type').typeByName;
77

88
import Connection from '../../src/connection';
99
import Request from '../../src/request';
10+
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';
1011

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

15-
config.options.debug = {
16-
packet: true,
17-
data: true,
18-
payload: true,
19-
token: true,
20-
log: true
21-
};
22-
16+
config.options.debug = debugOptionsFromEnv();
2317
config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION;
2418

2519
describe('inserting binary data', function() {
@@ -28,6 +22,10 @@ describe('inserting binary data', function() {
2822
beforeEach(function(done) {
2923
this.connection = new Connection(config);
3024
this.connection.connect(done);
25+
26+
if (process.env.TEDIOUS_DEBUG) {
27+
this.connection.on('debug', console.log);
28+
}
3129
});
3230

3331
afterEach(function(done) {

test/integration/bulk-load-test.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const TYPES = require('../../src/data-type').typeByName;
99
import Connection from '../../src/connection';
1010
import { RequestError } from '../../src/errors';
1111
import Request from '../../src/request';
12-
13-
const debugMode = false;
12+
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';
1413

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

2221
config.options.cancelTimeout = 1000;
2322

24-
if (debugMode) {
25-
config.options.debug = {
26-
packet: true,
27-
data: true,
28-
payload: true,
29-
token: true
30-
};
31-
}
23+
config.options.debug = debugOptionsFromEnv();
3224

3325
return config;
3426
}
@@ -43,14 +35,14 @@ describe('BulkLoad', function() {
4335
connection = new Connection(getConfig());
4436
connection.connect(done);
4537

46-
if (debugMode) {
38+
if (process.env.TEDIOUS_DEBUG) {
4739
connection.on('debug', (message) => console.log(message));
48-
connection.on('infoMessage', (info) =>
49-
console.log('Info: ' + info.number + ' - ' + info.message)
50-
);
51-
connection.on('errorMessage', (error) =>
52-
console.log('Error: ' + error.number + ' - ' + error.message)
53-
);
40+
connection.on('infoMessage', (info) => {
41+
console.log('Info: ' + info.number + ' - ' + info.message);
42+
});
43+
connection.on('errorMessage', (error) => {
44+
console.log('Error: ' + error.number + ' - ' + error.message);
45+
});
5446
}
5547
});
5648

test/integration/collation-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import Connection from '../../src/connection';
66
import Request from '../../src/request';
77
import { Flags } from '../../src/collation';
88
import { TYPES } from '../../src/data-type';
9+
import { debugOptionsFromEnv } from '../helpers/debug-options-from-env';
910

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

1516
config.options.tdsVersion = process.env.TEDIOUS_TDS_VERSION;
17+
config.options.debug = debugOptionsFromEnv();
1618

1719
return config;
1820
}
@@ -33,6 +35,11 @@ describe('Database Collation Support', function() {
3335
connection.once('databaseChange', (databaseName) => {
3436
originalDatabaseName = databaseName;
3537
});
38+
39+
if (process.env.TEDIOUS_DEBUG) {
40+
connection.on('debug', console.log);
41+
}
42+
3643
connection.connect(done);
3744
});
3845

0 commit comments

Comments
 (0)