Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pull out some common test code

  • Loading branch information...
commit d8e7c186041fa4bd8001250e7e888a08d9bc557e 1 parent a93e643
@orlandov authored
Showing with 32 additions and 43 deletions.
  1. +22 −0 tests/lib/common.js
  2. +10 −43 tests/test-statement-step.js
View
22 tests/lib/common.js
@@ -38,3 +38,25 @@ exports.insertMany = function (db, table, fields, rows, callback) {
doStep(--i);
});
}
+
+exports.getResultsStep = function (db, callback) {
+ var results = [];
+
+ db.prepare('SELECT * FROM table1', function (error, statement) {
+ function doStep() {
+ statement.step(function (error, row) {
+ if (row) {
+ results.push(row);
+ doStep();
+ }
+ else {
+ statement.finalize(function () {
+ callback && callback(results);
+ });
+ }
+ });
+ }
+
+ doStep();
+ });
+}
View
53 tests/test-statement-step.js
@@ -43,52 +43,19 @@ var tests = [
var self = this;
self.db.open(':memory:', function (error) {
- function selectStatementPrepared(error, statement) {
- if (error) throw error;
- statement.fetchAll(function (error, rows) {
- if (error) throw error;
-
- assert.deepEqual(testRowsExpected, rows);
-
- self.db.close(function () {
- finished();
- });
- });
- }
createTestTable(self.db,
function () {
- function insertRows(db, rows, callback) {
- var i = rows.length;
- db.prepare('INSERT INTO table1 (id, name, age) VALUES (?, ?, ?)',
- function (error, statement) {
- function doStep(i) {
- statement.bindArray(rows[i], function () {
- statement.step(function (error, row) {
- if (error) throw error;
- assert.ok(!row, "Row should be unset");
- statement.reset();
- if (i) {
- doStep(--i);
- }
- else {
- statement.finalize(function () {
- callback();
- });
- }
- });
- });
- }
-
- doStep(--i);
- });
- }
-
- var selectSQL
- = 'SELECT * from table1';
-
- common.insertMany(self.db, 'table1', ['id', 'name', 'age'], testRows, function () {
- self.db.prepare(selectSQL, selectStatementPrepared);
+ common.insertMany(self.db
+ , 'table1'
+ , ['id', 'name', 'age']
+ , testRows
+ , function () {
+ common.getResultsStep(self.db, function (rows) {
+ console.log(sys.inspect(arguments));
+ assert.deepEqual(rows, testRowsExpected);
+ finished();
+ });
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.