Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support writing test cases using TypeScript #1098

Merged
merged 5 commits into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/travis-cli": "^8.3.5",
"@types/bl": "^2.1.0",
"@types/chai": "^4.2.11",
"@types/depd": "^1.1.32",
"@types/mocha": "^7.0.2",
"@types/node": "^13.5.1",
"@types/readable-stream": "^2.3.5",
"@types/sprintf-js": "^1.1.2",
Expand Down
183 changes: 82 additions & 101 deletions test/integration/rpc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,75 @@ function getConfig() {
return config;
}

function execSqlBatch(connection, sql, doneCallback) {
const request = new Request(sql, function(err) {
if (err) {
console.log(err);
assert.ok(false);
}
describe('RPC test', function() {
let connection;

doneCallback();
});
beforeEach(function(done) {
const config = getConfig();
connection = new Connection(config);
connection.on('connect', done);

connection.execSqlBatch(request);
}
connection.on('infoMessage', (info) => {
// console.log("#{info.number} : #{info.message}")
});

function testProc(done, type, typeAsString, value) {
const config = getConfig();
connection.on('errorMessage', (error) => {
console.log(`${error.number} : ${error.message}`);
});

const request = new Request('#test_proc', function(err) {
assert.ifError(err);
connection.on('debug', (text) => {
// console.log(text)
});
});

connection.close();
afterEach(function(done) {
if (!connection.closed) {
connection.on('end', done);
connection.close();
} else {
done();
}
});

request.addParameter('param', type, value);
function execSqlBatch(connection, sql, done) {
const request = new Request(sql, function(err) {
if (err) {
console.log(err);
assert.ok(false);
}

request.on('doneProc', function(rowCount, more, returnStatus) {
assert.ok(!more);
assert.strictEqual(returnStatus, 0);
});
done();
});

request.on('doneInProc', function(rowCount, more) {
assert.ok(more);
});
connection.execSqlBatch(request);
}

request.on('row', function(columns) {
if (value instanceof Date) {
assert.strictEqual(columns[0].value.getTime(), value.getTime());
} else {
assert.strictEqual(columns[0].value, value);
}
});
function testProc(done, type, typeAsString, value) {
const request = new Request('#test_proc', function(err) {
assert.ifError(err);

let connection = new Connection(config);
done();
});

request.addParameter('param', type, value);

request.on('doneProc', function(rowCount, more, returnStatus) {
assert.ok(!more);
assert.strictEqual(returnStatus, 0);
});

request.on('doneInProc', function(rowCount, more) {
assert.ok(more);
});

request.on('row', function(columns) {
if (value instanceof Date) {
assert.strictEqual(columns[0].value.getTime(), value.getTime());
} else {
assert.strictEqual(columns[0].value, value);
}
});

connection.on('connect', function(err) {
execSqlBatch(
connection,
`\
Expand All @@ -78,63 +103,38 @@ select @param\
connection.callProcedure(request);
}
);
});

connection.on('end', function(info) {
done();
});

connection.on(
'infoMessage',
function(info) { }
// console.log("#{info.number} : #{info.message}")
);

connection.on('errorMessage', function(error) {
console.log(`${error.number} : ${error.message}`);
});

connection.on(
'debug',
function(text) { }
// console.log(text)
);
}

function testProcOutput(done, type, typeAsString, value) {
const config = getConfig();
}

const request = new Request('#test_proc', function(err) {
assert.ifError(err);
function testProcOutput(done, type, typeAsString, value) {

connection.close();
});
const request = new Request('#test_proc', function(err) {
assert.ifError(err);

request.addParameter('paramIn', type, value);
request.addOutputParameter('paramOut', type);
done();
});

request.on('doneProc', function(rowCount, more, returnStatus) {
assert.ok(!more);
assert.strictEqual(returnStatus, 0);
});
request.addParameter('paramIn', type, value);
request.addOutputParameter('paramOut', type);

request.on('doneInProc', function(rowCount, more) {
assert.ok(more);
});
request.on('doneProc', function(rowCount, more, returnStatus) {
assert.ok(!more);
assert.strictEqual(returnStatus, 0);
});

request.on('returnValue', function(name, returnValue, metadata) {
assert.strictEqual(name, 'paramOut');
if (value instanceof Date) {
assert.strictEqual(returnValue.getTime(), value.getTime());
} else {
assert.strictEqual(returnValue, value);
}
assert.ok(metadata);
});
request.on('doneInProc', function(rowCount, more) {
assert.ok(more);
});

let connection = new Connection(config);
request.on('returnValue', function(name, returnValue, metadata) {
assert.strictEqual(name, 'paramOut');
if (value instanceof Date) {
assert.strictEqual(returnValue.getTime(), value.getTime());
} else {
assert.strictEqual(returnValue, value);
}
assert.ok(metadata);
});

connection.on('connect', function(err) {
execSqlBatch(
connection,
`\
Expand All @@ -148,27 +148,8 @@ set @paramOut = @paramIn\
connection.callProcedure(request);
}
);
});

connection.on('end', function(info) {
done();
});
}

connection.on('infoMessage', function(info) {
// console.log("#{info.number} : #{info.message}")
});

connection.on('errorMessage', function(error) {
console.log(`${error.number} : ${error.message}`);
});

connection.on('debug', function(text) {
// console.log(text)
});
}


describe('RPC test', function() {
it('should exec proc varchar', function(done) {
testProc(done, TYPES.VarChar, 'varchar(10)', 'test');
});
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require test/setup.js --timeout 5000
--require test/setup.js --timeout 5000 --extension js,ts
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},

"include": [
"src/**/*.ts", "src/data-types/bitn.js", "src/data-types/bit.js"
"src/**/*.ts",
"test/**/*.ts",
]
}