Permalink
Browse files

Upgrading for latest node. Includes errors conforming to 'throw new E…

…rror(msg)' style, much easier to debug tests now.
  • Loading branch information...
1 parent 9e25b24 commit 83c548cb5a9a3527cbb4daed315e228f90582f38 @mikeal mikeal committed Apr 16, 2010
Showing with 45 additions and 45 deletions.
  1. +4 −4 README.md
  2. +3 −3 lib/couchdb.js
  3. +4 −4 test/test-attachment.js
  4. +2 −2 test/test-changes.js
  5. +6 −6 test/test-client.js
  6. +21 −21 test/test-db.js
  7. +5 −5 test/test-request.js
View
@@ -19,13 +19,13 @@ To use the library, create a new file called `my-couch-adventure.js`:
db
.saveDoc('my-doc', {awesome: 'couch fun'}, function(er, ok) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
sys.puts('Saved my first doc to the couch!');
});
db
.getDoc('my-doc', function(er, doc) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
sys.puts('Fetched my new doc from couch:');
sys.p(doc);
});
@@ -81,7 +81,7 @@ Takes the path of a `file` and callback receives a JS object suitable for inline
couchdb
.toAttachment(__filename, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
// r => {"content_type":"text/javascript","data":"dmFyCiAgs...="}
});
@@ -279,7 +279,7 @@ Returns an `events.EventEmitter` stream that emits the following events:
* `data(change)`: Emitted for each change line in the stream. The `change` parameter holds the change object.
* `heartbeat`: Emitted for each heartbeat send by CouchDB, no need to check this for most stuff.
-* `end(hadError)`: Emitted if the stream ends. This should not happen unless you manually invoke `stream.close()`.
+* `end(hadError)`: Emitted if the stream ends. This should not happen unless you manually invoke `stream.end()`.
See the [CouchDB docs](http://wiki.apache.org/couchdb/HTTP_database_API#Changes) for available `query` parameters.
View
@@ -190,7 +190,7 @@ exports.createClient = function(port, host, user, pass) {
});
});
- request.close();
+ request.end();
};
return couchClient;
@@ -575,14 +575,14 @@ Db.prototype.changesStream = function(query, options) {
}
})
});
- request.close();
+ request.end();
client.addListener('close', function(hadError) {
stream.emit('end', hadError);
});
stream.close = function() {
- return client.forceClose();
+ return client.destroy();
};
return stream;
@@ -20,7 +20,7 @@ db.create();
couchdb
.toAttachment(__dirname+'/fixture/logo.png', function (er, attachment) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.A = true;
assert.equal('image/png', attachment.content_type);
@@ -32,7 +32,7 @@ couchdb
'logo.png': attachment
}
}, function (er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.B = true;
assert.ok(r.ok);
assert.equal('logo-doc', r.id);
@@ -49,13 +49,13 @@ db.saveAttachment(
__dirname+'/fixture/logo.png',
'logo-2',
function (er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.C = true;
assert.ok(r.ok);
assert.equal('logo-2', r.id);
db.removeAttachment('logo-2', 'logo.png', r.rev, function (er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.D = true;
assert.ok(r.ok);
})
@@ -16,7 +16,7 @@ var
db.remove();
db
.create(function(er) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
var stream = db.changesStream();
stream
@@ -35,7 +35,7 @@ db.saveDoc({test: 1});
db.saveDoc({test: 2});
db.changes({since: 1}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.A = true;
assert.equal(2, r.results[0].seq);
assert.equal(1, r.results.length);
View
@@ -19,31 +19,31 @@ var
// Get a list of all databases
client
.allDbs(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.A = true;
assert.ok('length' in r);
});
// Get the couch config
client
.config(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.B = true;
assert.ok('httpd' in r);
});
// Get some uuids
client
.uuids(3, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.C = true;
assert.equal(3, r.uuids.length);
});
// Get the couch stats
client
.stats('httpd_status_codes', '200', function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.D = true;
assert.deepEqual(['httpd_status_codes'], Object.keys(r));
assert.deepEqual(['200'], Object.keys(r.httpd_status_codes));
@@ -52,7 +52,7 @@ client
// Find all active tasks
client
.activeTasks(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.E = true;
assert.ok('length' in r);
});
@@ -69,7 +69,7 @@ db2.create();
client
.replicate(DB_NAME, DB_NAME2, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.F = true;
assert.ok('session_id' in r);
});
View
@@ -38,37 +38,37 @@ db.remove();
// Make sure our test db does not exist yet
db
.exists(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.A = true;
assert.equal(false, r);
});
// Now create it
db
.create(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.B = true;
});
// Make sure that worked
db
.exists(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.C = true;
assert.equal(true, r);
});
// Create a document with a given id
db
.saveDoc(TEST_ID, TEST_DOC, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.D = true;
assert.equal(TEST_ID, r.id);
assert.ok('rev' in r);
db
.getDoc(TEST_ID, function(er, doc) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.U = true;
assert.equal(doc.hello, TEST_DOC.hello);
});
@@ -77,43 +77,43 @@ db
// Let couch create a document id for us
db
.saveDoc(TEST_DOC, function(er, doc) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.E = true;
// And lets try to delete this one right away
db
.removeDoc(doc.id, doc.rev, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.F = true;
});
});
// Lets check how we are doing here
db
.info(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.G = true;
assert.equal(2, r.doc_count);
});
// Lets test copying
db
.copyDoc(TEST_ID, TEST_ID2, function(er, copy) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.H = true;
// Now lets try to do this again, but this time we need the destRev
db
.copyDoc(TEST_ID, TEST_ID2, copy.rev, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.I = true;
});
});
// Get a list of all docs
db
.allDocs(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.J = true;
assert.equal(3, r.total_rows);
assert.equal(3, r.rows.length);
@@ -122,23 +122,23 @@ db
// Make sure query options work
db
.allDocs({limit: 2}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.K = true;
assert.equal(2, r.rows.length);
});
// Test allDocsBySeq
db
.allDocsBySeq(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.L = true;
assert.ok('rows' in r);
});
// Test compact
db
.compact(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.M = true;
assert.ok('ok' in r);
});
@@ -151,7 +151,7 @@ db
{_id: '2'},
]
}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.N = true;
assert.equal('1', r[0].id);
assert.equal('2', r[1].id);
@@ -164,15 +164,15 @@ db
emit(null, null);
}
}, {include_docs: true}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.O = true;
assert.ok('total_rows' in r);
});
// Test view cleanup
db
.viewCleanup(function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.P = true;
assert.ok(r.ok);
});
@@ -188,7 +188,7 @@ db
}
}
}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.Q = true;
assert.ok('ok' in r);
assert.ok('_design/nice', r.id);
@@ -206,7 +206,7 @@ db
}
}
}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.R = true;
assert.ok('ok' in r);
assert.ok('_design/other', r.id);
@@ -215,15 +215,15 @@ db
// Test compact on design
db
.compact('nice', function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.S = true;
assert.ok('ok' in r);
});
// Test view querying
db
.view('nice', 'one', {limit: 1}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.T = true;
assert.equal(1, r.rows.length);
});
View
@@ -12,21 +12,21 @@ var
client
.request('/_uuids', function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.A = true;
assert.ok(1, r.uuids.length);
});
client
.request('/_uuids', {count: 2}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.B = true;
assert.ok(2, r.uuids.length);
});
client
.request('get', '/_uuids', {count: 3}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.C = true;
assert.ok(3, r.uuids.length);
});
@@ -36,7 +36,7 @@ client
path: '/_uuids',
query: {count: 4},
}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.D = true;
assert.ok(4, r.uuids.length);
});
@@ -47,7 +47,7 @@ client
query: {count: 5},
full: true
}, function(er, r) {
- if (er) throw er;
+ if (er) throw new Error(JSON.stringify(er));
callbacks.E = true;
assert.ok('headers' in r);
assert.ok(5, r.json.uuids.length);

0 comments on commit 83c548c

Please sign in to comment.