summaryrefslogtreecommitdiff
path: root/node_modules/mongoose/support/expresso/test
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/mongoose/support/expresso/test
ok
Diffstat (limited to 'node_modules/mongoose/support/expresso/test')
-rw-r--r--node_modules/mongoose/support/expresso/test/assert.test.js91
-rw-r--r--node_modules/mongoose/support/expresso/test/async.test.js12
-rw-r--r--node_modules/mongoose/support/expresso/test/bar.test.js13
-rw-r--r--node_modules/mongoose/support/expresso/test/foo.test.js14
-rw-r--r--node_modules/mongoose/support/expresso/test/http.test.js109
-rw-r--r--node_modules/mongoose/support/expresso/test/serial/async.test.js39
-rw-r--r--node_modules/mongoose/support/expresso/test/serial/http.test.js48
7 files changed, 326 insertions, 0 deletions
diff --git a/node_modules/mongoose/support/expresso/test/assert.test.js b/node_modules/mongoose/support/expresso/test/assert.test.js
new file mode 100644
index 0000000..f822595
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/assert.test.js
@@ -0,0 +1,91 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert');
+
+module.exports = {
+ 'assert.eql()': function(){
+ assert.equal(assert.deepEqual, assert.eql);
+ },
+
+ 'assert.type()': function(){
+ assert.type('foobar', 'string');
+ assert.type(2, 'number');
+ assert.throws(function(){
+ assert.type([1,2,3], 'string');
+ });
+ },
+
+ 'assert.includes()': function(){
+ assert.includes('some random string', 'dom');
+ assert.throws(function(){
+ assert.include('some random string', 'foobar');
+ });
+
+ assert.includes(['foo', 'bar'], 'bar');
+ assert.includes(['foo', 'bar'], 'foo');
+ assert.includes([1,2,3], 3);
+ assert.includes([1,2,3], 2);
+ assert.includes([1,2,3], 1);
+ assert.throws(function(){
+ assert.includes(['foo', 'bar'], 'baz');
+ });
+
+ assert.throws(function(){
+ assert.includes({ wrong: 'type' }, 'foo');
+ });
+ },
+
+ 'assert.isNull()': function(){
+ assert.isNull(null);
+ assert.throws(function(){
+ assert.isNull(undefined);
+ });
+ assert.throws(function(){
+ assert.isNull(false);
+ });
+ },
+
+ 'assert.isUndefined()': function(){
+ assert.isUndefined(undefined);
+ assert.throws(function(){
+ assert.isUndefined(null);
+ });
+ assert.throws(function(){
+ assert.isUndefined(false);
+ });
+ },
+
+ 'assert.isNotNull()': function(){
+ assert.isNotNull(false);
+ assert.isNotNull(undefined);
+ assert.throws(function(){
+ assert.isNotNull(null);
+ });
+ },
+
+ 'assert.isDefined()': function(){
+ assert.isDefined(false);
+ assert.isDefined(null);
+ assert.throws(function(){
+ assert.isDefined(undefined);
+ });
+ },
+
+ 'assert.match()': function(){
+ assert.match('foobar', /foo(bar)?/);
+ assert.throws(function(){
+ assert.match('something', /rawr/);
+ });
+ },
+
+ 'assert.length()': function(){
+ assert.length('test', 4);
+ assert.length([1,2,3,4], 4);
+ assert.throws(function(){
+ assert.length([1,2,3], 4);
+ });
+ }
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/support/expresso/test/async.test.js b/node_modules/mongoose/support/expresso/test/async.test.js
new file mode 100644
index 0000000..d1d2036
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/async.test.js
@@ -0,0 +1,12 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert');
+
+setTimeout(function(){
+ exports['test async exports'] = function(){
+ assert.ok('wahoo');
+ };
+}, 100); \ No newline at end of file
diff --git a/node_modules/mongoose/support/expresso/test/bar.test.js b/node_modules/mongoose/support/expresso/test/bar.test.js
new file mode 100644
index 0000000..cfc2e11
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/bar.test.js
@@ -0,0 +1,13 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert')
+ , bar = require('bar');
+
+module.exports = {
+ 'bar()': function(){
+ assert.equal('bar', bar.bar());
+ }
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/support/expresso/test/foo.test.js b/node_modules/mongoose/support/expresso/test/foo.test.js
new file mode 100644
index 0000000..ee5cff3
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/foo.test.js
@@ -0,0 +1,14 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert')
+ , foo = require('foo');
+
+module.exports = {
+ 'foo()': function(){
+ assert.equal('foo', foo.foo());
+ assert.equal('foo', foo.foo());
+ }
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/support/expresso/test/http.test.js b/node_modules/mongoose/support/expresso/test/http.test.js
new file mode 100644
index 0000000..41648d2
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/http.test.js
@@ -0,0 +1,109 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert')
+ , http = require('http');
+
+var server = http.createServer(function(req, res){
+ if (req.method === 'GET') {
+ if (req.url === '/delay') {
+ setTimeout(function(){
+ res.writeHead(200, {});
+ res.end('delayed');
+ }, 200);
+ } else {
+ var body = JSON.stringify({ name: 'tj' });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'Content-Length': body.length
+ });
+ res.end(body);
+ }
+ } else {
+ var body = '';
+ req.setEncoding('utf8');
+ req.addListener('data', function(chunk){ body += chunk });
+ req.addListener('end', function(){
+ res.writeHead(200, {});
+ res.end(req.url + ' ' + body);
+ });
+ }
+});
+
+var delayedServer = http.createServer(function(req, res){
+ res.writeHead(200);
+ res.end('it worked');
+});
+
+var oldListen = delayedServer.listen;
+delayedServer.listen = function(){
+ var args = arguments;
+ setTimeout(function(){
+ oldListen.apply(delayedServer, args);
+ }, 100);
+};
+
+module.exports = {
+ 'test assert.response()': function(beforeExit){
+ var called = 0;
+
+ assert.response(server, {
+ url: '/',
+ method: 'GET'
+ },{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8'
+ }
+ });
+
+ assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+ },{
+ body: '/foo bar baz',
+ status: 200
+ }, function(res){
+ ++called;
+ assert.ok(res);
+ });
+
+ assert.response(server, {
+ url: '/foo'
+ }, function(res){
+ ++called;
+ assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback');
+ });
+
+ assert.response(server,
+ { url: '/delay', timeout: 300 },
+ { body: 'delayed' });
+
+ beforeExit(function(){
+ assert.equal(2, called);
+ });
+ },
+
+ 'test assert.response() regexp': function(){
+ assert.response(server,
+ { url: '/foo', method: 'POST', data: 'foobar' },
+ { body: /^\/foo foo(bar)?/ });
+ },
+
+ 'test assert.response() regexp headers': function(){
+ assert.response(server,
+ { url: '/' },
+ { body: '{"name":"tj"}', headers: { 'Content-Type': /^application\/json/ } });
+ },
+
+ // [!] if this test doesn't pass, an uncaught ECONNREFUSED will display
+ 'test assert.response() with deferred listen()': function(){
+ assert.response(delayedServer,
+ { url: '/' },
+ { body: 'it worked' });
+ }
+};
diff --git a/node_modules/mongoose/support/expresso/test/serial/async.test.js b/node_modules/mongoose/support/expresso/test/serial/async.test.js
new file mode 100644
index 0000000..c596d5c
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/serial/async.test.js
@@ -0,0 +1,39 @@
+
+var assert = require('assert')
+ , setup = 0
+ , order = [];
+
+module.exports = {
+ setup: function(done){
+ ++setup;
+ done();
+ },
+
+ a: function(done){
+ assert.equal(1, setup);
+ order.push('a');
+ setTimeout(function(){
+ done();
+ }, 500);
+ },
+
+ b: function(done){
+ assert.equal(2, setup);
+ order.push('b');
+ setTimeout(function(){
+ done();
+ }, 200);
+ },
+
+ c: function(done){
+ assert.equal(3, setup);
+ order.push('c');
+ setTimeout(function(){
+ done();
+ }, 1000);
+ },
+
+ d: function(){
+ assert.eql(order, ['a', 'b', 'c']);
+ }
+}; \ No newline at end of file
diff --git a/node_modules/mongoose/support/expresso/test/serial/http.test.js b/node_modules/mongoose/support/expresso/test/serial/http.test.js
new file mode 100644
index 0000000..7783eb5
--- /dev/null
+++ b/node_modules/mongoose/support/expresso/test/serial/http.test.js
@@ -0,0 +1,48 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert')
+ , http = require('http');
+
+var server = http.createServer(function(req, res){
+ if (req.method === 'GET') {
+ if (req.url === '/delay') {
+ setTimeout(function(){
+ res.writeHead(200, {});
+ res.end('delayed');
+ }, 200);
+ } else {
+ var body = JSON.stringify({ name: 'tj' });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'Content-Length': body.length
+ });
+ res.end(body);
+ }
+ } else {
+ var body = '';
+ req.setEncoding('utf8');
+ req.addListener('data', function(chunk){ body += chunk });
+ req.addListener('end', function(){
+ res.writeHead(200, {});
+ res.end(req.url + ' ' + body);
+ });
+ }
+});
+
+module.exports = {
+ 'test assert.response()': function(done){
+ assert.response(server, {
+ url: '/',
+ method: 'GET'
+ },{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8'
+ }
+ }, done);
+ }
+}; \ No newline at end of file