Permalink
Browse files

lab + 0.15.4 tests

  • Loading branch information...
1 parent 74d5bdb commit 8f7d71271f487c03129de0b4fbd06440d3d9eeef @hueniverse hueniverse committed Mar 20, 2013
Showing with 76 additions and 68 deletions.
  1. +8 −9 Makefile
  2. +9 −8 lib/session.js
  3. +5 −9 package.json
  4. +30 −26 test/index.js
  5. +8 −4 test/integration/request.js
  6. +16 −12 test/integration/session.js
View
17 Makefile
@@ -1,12 +1,11 @@
-REPORTER = dot
-
test:
- @NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter $(REPORTER) --ignore-leaks --timeout 3000
-
-test-cov:
- @NODE_ENV=test ./node_modules/.bin/mocha --require blanket --recursive --ignore-leaks --timeout 3000 -R travis-cov
-
+ @./node_modules/.bin/lab
+test-cov:
+ @./node_modules/.bin/lab -r threshold -t 100
test-cov-html:
- @NODE_ENV=test ./node_modules/.bin/mocha --require blanket --recursive --ignore-leaks --timeout 3000 -R html-cov > coverage.html
+ @./node_modules/.bin/lab -r html -o coverage.html
+complexity:
+ @./node_modules/.bin/cr -o complexity.md -f markdown lib
+
+.PHONY: test test-cov test-cov-html complexity
-.PHONY: test test-cov test-cov-html
View
17 lib/session.js
@@ -1,11 +1,12 @@
// Load modules
var Hoek = require('hoek');
-var UUID = require('node-uuid');
+var Uuid = require('node-uuid');
var CookieStore = require('./stores/cookie');
var MemoryStore = require('./stores/memory');
var RequestMethods = require('./request');
+
// Declare internals
var internals = {};
@@ -17,7 +18,7 @@ module.exports = internals.Session = function (options) {
Hoek.assert(this.settings.session && this.settings.session.key, 'No session.key defined (the x in request[x])');
Hoek.assert(typeof this.settings.session.key === 'string', 'Invalid session.key defined');
-
+
this.settings.session.startTime = Date.now();
if (this.settings.session.store) {
@@ -117,21 +118,21 @@ internals.Session.prototype.load = function (request, callback) {
var session = request[this.settings.session.key] = request.state[this.settings.name][this.settings.session.key] || {};
var sid = session[this.settings.session.sidKey];
session[this.settings.session.startKey] = session[this.settings.session.startKey] || 0;
-
+
// Check for stale cookie (leftover from server restart)
-
+
var fn = 'get';
if (session[this.settings.session.startKey] != this.settings.session.startTime) {
var fn = 'delete';
}
-
+
// Augment Request
for (var method in RequestMethods) {
request[method] = RequestMethods[method](request);
}
-
+
// Get Session
-
+
if (this.extStore) {
return this.extStore[fn](sid, this.attach(request, callback));
}
@@ -143,7 +144,7 @@ internals.Session.prototype.load = function (request, callback) {
internals.Session.prototype.generateSID = function (session) {
session = session || {};
- return session[this.settings.session.sidKey] || UUID.v4();
+ return session[this.settings.session.sidKey] || Uuid.v4();
};
View
14 package.json
@@ -1,7 +1,7 @@
{
"name": "yar",
"description": "Cookie jar plugin",
- "version": "0.1.2",
+ "version": "0.1.3",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",
"contributors": [
"Van Nguyen <thegoleffect@gmail.com>"
@@ -19,23 +19,19 @@
"node": "0.8.x"
},
"dependencies": {
- "hoek": "0.6.x",
+ "hoek": "0.7.x",
"node-uuid": "1.4.x"
},
"peerDependencies": {
"hapi": "0.15.x"
},
"devDependencies": {
"hapi": "0.15.x",
- "mocha": "1.x.x",
- "chai": "1.x.x",
- "blanket": "1.0.x",
- "travis-cov": "0.2.x"
+ "lab": "0.0.x",
+ "complexity-report": "0.x.x"
},
"scripts": {
- "test": "make test && make test-cov",
- "blanket": { "pattern": "//^((?!\/node_modules\/)(?!\/test\/).)*$/ig", "onlyCwd": true, "data-cover-flags": { "branchTracking": true } },
- "travis-cov": { "threshold": 100 }
+ "test": "make test-cov"
},
"licenses": [
{
View
56 test/index.js
@@ -1,6 +1,6 @@
// Load modules
-var Chai = require('chai');
+var Lab = require('lab');
var Hapi = require('hapi');
@@ -11,67 +11,71 @@ var internals = {};
// Test shortcuts
-var expect = Chai.expect;
+var expect = Lab.expect;
+var before = Lab.before;
+var after = Lab.after;
+var describe = Lab.experiment;
+var it = Lab.test;
-describe('Yar', function () {
+describe('Yar', function () {
- it('sets yar then gets it back', function (done) {
+ it('sets yar then gets it back', function (done) {
- var options = {
+ var options = {
name: 'jarx',
isSingleUse: true,
- cookieOptions: {
+ cookieOptions: {
password: 'password',
- isSecure: true
- }
+ isSecure: true
+ }
};
var server = new Hapi.Server();
server.route([
- {
- method: 'GET', path: '/1', handler: function () {
+ {
+ method: 'GET', path: '/1', handler: function () {
expect(this.state.jarx).to.deep.equal({});
expect(this.plugins.yar).to.deep.equal({});
this.plugins.yar.some = { value: 123 };
- return this.reply('1');
- }
+ return this.reply('1');
+ }
},
- {
- method: 'GET', path: '/2', handler: function () {
+ {
+ method: 'GET', path: '/2', handler: function () {
expect(this.state.jarx).to.deep.equal({ some: { value: 123 } });
expect(this.plugins.yar).to.deep.equal({});
- return this.reply('2');
- }
+ return this.reply('2');
+ }
}
]);
- server.plugin.allow({ ext: true }).require('../', options, function (err) {
+ server.plugin.allow({ ext: true }).require('../', options, function (err) {
expect(err).to.not.exist;
- server.inject({ method: 'GET', url: '/1' }, function (res) {
+ server.inject({ method: 'GET', url: '/1' }, function (res) {
expect(res.result).to.equal('1');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
expect(header[0]).to.contain('Secure');
var cookie = header[0].match(/(jarx=[^\x00-\x20\"\,\;\\\x7F]*)/);
- server.inject({ method: 'GET', url: '/2', headers: { cookie: cookie[1] } }, function (res) {
+ server.inject({ method: 'GET', url: '/2', headers: { cookie: cookie[1] } }, function (res) {
expect(res.result).to.equal('2');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
expect(header[0]).to.equal('jarx=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; Path=/');
- done();
- });
- });
- });
- });
+ done();
+ });
+ });
+ });
+ });
});
View
12 test/integration/request.js 100644 → 100755
@@ -1,6 +1,6 @@
// Load modules
-var Chai = require('chai');
+var Lab = require('lab');
var Hapi = require('hapi');
@@ -11,7 +11,11 @@ var internals = {};
// Test shortcuts
-var expect = Chai.expect;
+var expect = Lab.expect;
+var before = Lab.before;
+var after = Lab.after;
+var describe = Lab.experiment;
+var it = Lab.test;
describe('Request', function () {
@@ -66,7 +70,7 @@ describe('Request', function () {
expect(result.flash.error).to.exist;
expect(result.flash.error.length).to.be.above(0);
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
@@ -134,7 +138,7 @@ describe('Request', function () {
expect(result.flash.error).to.exist;
expect(result.flash.error.length).to.be.above(0);
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
View
28 test/integration/session.js
@@ -1,6 +1,6 @@
// Load modules
-var Chai = require('chai');
+var Lab = require('lab');
var Hapi = require('hapi');
@@ -11,7 +11,11 @@ var internals = {};
// Test shortcuts
-var expect = Chai.expect;
+var expect = Lab.expect;
+var before = Lab.before;
+var after = Lab.after;
+var describe = Lab.experiment;
+var it = Lab.test;
describe('Session', function () {
@@ -58,15 +62,15 @@ describe('Session', function () {
server.inject({ method: 'GET', url: '/set' }, function (res) {
expect(res.result).to.equal('ok');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
server.inject({ method: 'GET', url: '/get', headers: { cookie: cookie[1] } }, function (res) {
// expect(res.result).to.contain('test');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
done();
});
@@ -114,15 +118,15 @@ describe('Session', function () {
server.inject({ method: 'GET', url: '/set' }, function (res) {
expect(res.result).to.equal('ok');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
server.inject({ method: 'GET', url: '/get', headers: { cookie: cookie[1] } }, function (res) {
// expect(res.result).to.contain('test');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
done();
});
@@ -232,15 +236,15 @@ describe('Session', function () {
server.inject({ method: 'GET', url: '/set' }, function (res) {
expect(res.result).to.equal('ok');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
server.inject({ method: 'GET', url: '/get', headers: { cookie: cookie[1] } }, function (res) {
// expect(res.result).to.contain('test');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
done();
});
@@ -297,15 +301,15 @@ describe('Session', function () {
server.inject({ method: 'GET', url: '/set' }, function (res) {
expect(res.result).to.equal('ok');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
server.inject({ method: 'GET', url: '/get', headers: { cookie: cookie[1] } }, function (res) {
// expect(res.result).to.contain('test');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
done();
});
@@ -353,15 +357,15 @@ describe('Session', function () {
server.inject({ method: 'GET', url: '/set' }, function (res) {
expect(res.result).to.equal('ok');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
var cookie = header[0].match(/(yar=[^\x00-\x20\"\,\;\\\x7F]*)/);
server.inject({ method: 'GET', url: '/get', headers: { cookie: cookie[1] } }, function (res) {
// expect(res.result).to.contain('test');
- var header = res.headers['Set-Cookie'];
+ var header = res.headers['set-cookie'];
expect(header.length).to.equal(1);
done();
});

0 comments on commit 8f7d712

Please sign in to comment.