Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed tests. Added `create` alias for `createBasic`.

  • Loading branch information...
commit e8ea53c8292a284243a123b2a5d22352bab8ab17 1 parent 0b62b66
@bengourley bengourley authored
View
6 README.md
@@ -38,11 +38,11 @@ Add versionator into your middleware stack before the static middleware:
```js
app.version = '0.1.0';
-var basic = require('versionator').createBasic(app.version);
+var versionator = require('versionator').create(app.version);
app.configure(function() {
- app.use(basic.middleware('v' + app.version))
+ app.use(versionator.middleware(app.version))
....
.use(express.static(__dirname + '/public', { maxAge: 2592000000 }));
@@ -69,7 +69,7 @@ app.configure(function() {
// This exposes the helper to the views
app.helpers({
- versionPath: basic.versionPath
+ versionPath: versionator.versionPath
});
});
View
1  index.js
@@ -1,3 +1,4 @@
+module.exports.create = require('./lib/middleware/basic');
module.exports.createBasic = require('./lib/middleware/basic');
module.exports.createMapped = require('./lib/middleware/mapped');
module.exports.createMapFromPath = require('./lib/map-path');
View
14 test/basic-versionator.test.js
@@ -3,7 +3,8 @@ var
assert = require('assert'),
request = require('request'),
versionator = require('../'),
- appEngine = require('connect');
+ appEngine = require('connect'),
+ http = require('http');
describe('versionator', function() {
@@ -46,7 +47,7 @@ describe('versionator', function() {
describe('basic middleware', function() {
- function startServer() {
+ function startServer(port) {
var app = appEngine.createServer(
versionator.createBasic('v0.1.2').middleware,
function(req, res, next) {
@@ -54,13 +55,12 @@ describe('versionator', function() {
}
);
- app.listen(9898);
- return app;
+ return http.Server(app).listen(port);
}
it('req.url has version removed from pathname', function(done) {
- var app = startServer();
+ var app = startServer(9898);
request('http://localhost:9898/images/v0.1.2/sprite.png', function(error, response, data) {
data.should.eql('/images/sprite.png');
@@ -71,9 +71,9 @@ describe('versionator', function() {
it('req.url is unchanged if no version match is found', function(done) {
- var app = startServer();
+ var app = startServer(9899);
- request('http://localhost:9898/images/sprite.png', function(error, response, data) {
+ request('http://localhost:9899/images/sprite.png', function(error, response, data) {
data.should.eql('/images/sprite.png');
app.close();
done();
View
18 test/map-path.test.js
@@ -11,7 +11,7 @@ function createFiles(dirPath, files, callback) {
var fns = [
async.apply(mkdirp, dirPath + '/sub')
];
-
+
Object.keys(files).forEach(function(filename) {
fns.push(async.apply(fs.writeFile, dirPath + '/' + filename, files[filename]));
});
@@ -21,7 +21,7 @@ function createFiles(dirPath, files, callback) {
function removeFiles(dirPath, files, callback) {
var fns = [];
-
+
Object.keys(files).forEach(function(filename) {
fns.push(async.apply(fs.unlink, dirPath + '/' + filename));
});
@@ -61,9 +61,9 @@ describe('versionator', function() {
it('should correctly walk directory and create hashes', function(done) {
versionator.createMapFromPath(tmpPath, function(error, results) {
-
+
var a = {
- '/a': '/d41d8cd98f00b204e9800998ecf8427e/a',
+ '/a': '/d41d8cd98f00b204e9800998ecf8427e/a',
'/b': '/8b1a9953c4611296a827abf8c47804d7/b',
'/c': '/e509465ef513154988e088d6ad3c21bf/c',
'/sub/a': '/sub/49f68a5c8493ec2c0bf489821c21fc3b/a' }.should.eql(results);
@@ -74,12 +74,12 @@ describe('versionator', function() {
});
it('should accept fileList and create hashes', function(done) {
- var fileList = [
- tmpPath + '/c',
- tmpPath + '/sub/a'
- ]
+ var fileList = [
+ tmpPath + '/c',
+ tmpPath + '/sub/a'
+ ];
versionator.createMapFromPath(tmpPath, {'fileList': fileList}, function(error, results) {
-
+
var a = {
'/c': '/e509465ef513154988e088d6ad3c21bf/c',
'/sub/a': '/sub/49f68a5c8493ec2c0bf489821c21fc3b/a' }.should.eql(results);
View
31 test/mapped-versionator.test.js
@@ -3,7 +3,8 @@ var
assert = require('assert'),
request = require('request'),
versionator = require('../'),
- appEngine = require('connect');
+ appEngine = require('connect'),
+ http = require('http');
describe('versionator', function() {
@@ -51,8 +52,8 @@ describe('versionator', function() {
describe('mapped middleware', function() {
- function startServer(map) {
- var mapped = versionator.createMapped(map)
+ function startServer(map, port) {
+ var mapped = versionator.createMapped(map);
var app = appEngine.createServer(
mapped.middleware,
function(req, res, next) {
@@ -60,15 +61,17 @@ describe('versionator', function() {
}
);
- app.listen(9898);
- return {'app': app, 'mapped': mapped};
+ return {
+ app: http.Server(app).listen(port),
+ mapped: mapped
+ };
}
it('req.url is unchanged if no version match is found', function(done) {
- var app = startServer({}).app;
+ var app = startServer({}, 9900).app;
- request('http://localhost:9898/images/sprite.png', function(error, response, data) {
+ request('http://localhost:9900/images/sprite.png', function(error, response, data) {
data.should.eql('/images/sprite.png');
app.close();
done();
@@ -77,9 +80,9 @@ describe('versionator', function() {
it('req.url mapped url is mapped correctly', function(done) {
- var app = startServer({'/images/sprite.png': '/images/VERSIONHASH/sprite.png' }).app;
+ var app = startServer({'/images/sprite.png': '/images/VERSIONHASH/sprite.png' }, 9901).app;
- request('http://localhost:9898/images/VERSIONHASH/sprite.png', function(error, response, data) {
+ request('http://localhost:9901/images/VERSIONHASH/sprite.png', function(error, response, data) {
data.should.eql('/images/sprite.png');
app.close();
done();
@@ -88,13 +91,13 @@ describe('versionator', function() {
it('req.url mapped url is mapped correctly after hash change', function(done) {
- var appObj = startServer({'/images/sprite.png': '/images/VERSIONHASH/sprite.png' });
- var app = appObj.app;
- var mapped = appObj.mapped;
+ var appObj = startServer({'/images/sprite.png': '/images/VERSIONHASH/sprite.png' }, 9902);
+ var app = appObj.app;
+ var mapped = appObj.mapped;
- mapped.modifyMap({ '/images/sprite.png': '/images/OTHERHASH/sprite.png' });
+ mapped.modifyMap({ '/images/sprite.png': '/images/OTHERHASH/sprite.png' });
- request('http://localhost:9898/images/OTHERHASH/sprite.png', function(error, response, data) {
+ request('http://localhost:9902/images/OTHERHASH/sprite.png', function(error, response, data) {
data.should.eql('/images/sprite.png');
app.close();
done();
Please sign in to comment.
Something went wrong with that request. Please try again.