Comparing version 0.9.2 to 0.9.3
14
index.js
@@ -726,2 +726,16 @@ 'use strict'; | ||
/** | ||
* Helper method that proxies to the redirect of the BigPipe instance. | ||
* | ||
* @param {String} path Redirect URI. | ||
* @param {Number} status Optional status code. | ||
* @param {Object} options Optional options, e.g. caching headers. | ||
* @returns {Pagelet} fluent interface. | ||
* @api public | ||
*/ | ||
Pagelet.readable('redirect', function redirect(path, status, options) { | ||
this._bigpipe.redirect(this, path, status, options); | ||
return this; | ||
}); | ||
/** | ||
* Proxy to return the compiled server template from Temper. | ||
@@ -728,0 +742,0 @@ * |
{ | ||
"name": "pagelet", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"description": "pagelet", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
describe('Pagelet', function () { | ||
'use strict'; | ||
var Pagelet = require('../') | ||
var server = require('http').createServer() | ||
, BigPipe = require('bigpipe') | ||
, common = require('./common') | ||
, Temper = require('temper') | ||
, BigPipe = require('bigpipe') | ||
, assume = require('assume') | ||
, Response = common.Response | ||
, Request = common.Request | ||
, Pagelet = require('../') | ||
, React = require('react') | ||
, server = require('http').createServer() | ||
, pagelet, P; | ||
@@ -73,3 +76,3 @@ | ||
describe('.on', function () { | ||
describe('#on', function () { | ||
it('is a function', function () { | ||
@@ -108,3 +111,3 @@ assume(Pagelet.on).is.a('function'); | ||
describe('.destroy', function () { | ||
describe('#destroy', function () { | ||
it('is a function', function () { | ||
@@ -117,3 +120,3 @@ assume(pagelet.destroy).to.be.a('function'); | ||
var local = new Pagelet({ temper: temper, bigpipe: bigpipe }); | ||
local.on('test', noop) | ||
local.on('test', noop); | ||
@@ -128,3 +131,3 @@ local.destroy(); | ||
describe('.discover', function () { | ||
describe('#discover', function () { | ||
it('emits discover and returns immediatly if the parent pagelet has no children', function (done) { | ||
@@ -151,3 +154,3 @@ pagelet.once('discover', done); | ||
describe('.length', function () { | ||
describe('#length', function () { | ||
it('is a getter', function () { | ||
@@ -171,3 +174,3 @@ var props = Object.getOwnPropertyDescriptor(Pagelet.prototype, 'length'); | ||
describe('.template', function () { | ||
describe('#template', function () { | ||
it('is a function', function () { | ||
@@ -195,3 +198,3 @@ assume(Pagelet.prototype.template).to.be.a('function'); | ||
React.createElement('span', null, 'some text') | ||
) | ||
); | ||
} | ||
@@ -223,3 +226,3 @@ }), | ||
describe('.contentType', function () { | ||
describe('#contentType', function () { | ||
it('is a getter', function () { | ||
@@ -263,3 +266,3 @@ var props = Object.getOwnPropertyDescriptor(Pagelet.prototype, 'contentType'); | ||
describe('.bootstrap', function () { | ||
describe('#bootstrap', function () { | ||
it('is a getter', function () { | ||
@@ -319,3 +322,3 @@ var props = Object.getOwnPropertyDescriptor(Pagelet.prototype, 'bootstrap'); | ||
describe('.active', function () { | ||
describe('#active', function () { | ||
it('is a getter', function () { | ||
@@ -373,3 +376,3 @@ var props = Object.getOwnPropertyDescriptor(Pagelet.prototype, 'active'); | ||
describe('.conditional', function () { | ||
describe('#conditional', function () { | ||
it('is a function', function () { | ||
@@ -395,3 +398,3 @@ assume(pagelet.conditional).to.be.a('function'); | ||
var conditional = new Conditional; | ||
conditional = new Conditional; | ||
conditional._active = false; | ||
@@ -466,4 +469,36 @@ | ||
describe('.children', function () { | ||
describe('#redirect', function () { | ||
it('is a function', function () { | ||
assume(pagelet.redirect).to.be.a('function'); | ||
assume(pagelet.redirect.length).to.equal(3); | ||
}); | ||
it('proxies calls to the bigpipe instance', function (done) { | ||
var CustomPipe = BigPipe.extend({ | ||
redirect: function redirect(ref, path, code, options) { | ||
assume(ref).to.be.instanceof(Pagelet); | ||
assume(ref).to.equal(pagelet); | ||
assume(path).to.equal('/test'); | ||
assume(code).to.equal(404); | ||
assume(options).to.have.property('cache', false); | ||
done(); | ||
} | ||
}); | ||
pagelet = new P({ bigpipe: new CustomPipe(server) }); | ||
pagelet.redirect('/test', 404, { | ||
cache: false | ||
}); | ||
}); | ||
it('returns a reference to the pagelet', function () { | ||
pagelet = new P({ bigpipe: bigpipe }); | ||
pagelet._res = new Response; | ||
assume(pagelet.redirect('/')).to.equal(pagelet); | ||
}) | ||
}); | ||
describe('#children', function () { | ||
it('is a function', function () { | ||
assume(Pagelet.children).to.be.a('function'); | ||
@@ -527,3 +562,3 @@ assume(P.children).to.be.a('function'); | ||
describe('.optimize', function () { | ||
describe('#optimize', function () { | ||
it('should prepare an async call stack'); | ||
@@ -530,0 +565,0 @@ it('should provide optimizer with Pagelet reference if no transform:before event'); |
75519
17
1626