Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: resolve paths for windows #32

Merged
merged 3 commits into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var normalize = path.normalize;
var basename = path.basename;
var extname = path.extname;
var resolve = path.resolve;
var parse = path.parse;
var sep = path.sep;
var fs = require('mz/fs');
var co = require('co');

Expand Down Expand Up @@ -41,7 +43,7 @@ function send(ctx, path, opts) {
debug('send "%s" %j', path, opts);
var root = opts.root ? normalize(resolve(opts.root)) : '';
var trailingSlash = '/' == path[path.length - 1];
path = path[0] == '/' ? path.slice(1) : path;
path = path.substr(parse(path).root.length);
var index = opts.index;
var maxage = opts.maxage || opts.maxAge || 0;
var hidden = opts.hidden || false;
Expand Down Expand Up @@ -108,7 +110,7 @@ function send(ctx, path, opts) {
*/

function isHidden(root, path) {
path = path.substr(root.length).split('/');
path = path.substr(root.length).split(sep);
for(var i = 0; i < path.length; i++) {
if(path[i][0] === '.') return true;
}
Expand Down
7 changes: 4 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var request = require('supertest');
var send = require('..');
var path = require('path');
var koa = require('koa');
var assert = require('assert');

Expand Down Expand Up @@ -281,7 +282,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p);
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand Down Expand Up @@ -358,7 +359,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p, { maxage: 5000 });
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand All @@ -373,7 +374,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p, { maxage: 1234 });
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand Down