Skip to content

Commit

Permalink
[test] Added autoindex test
Browse files Browse the repository at this point in the history
  * Covers basic cases
  * Needs more coverage
  • Loading branch information
Marak committed Oct 17, 2017
1 parent a38bc5c commit 6bd9e26
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/autoindex/a/e.html
@@ -0,0 +1 @@
g
1 change: 1 addition & 0 deletions test/autoindex/a/f.html
@@ -0,0 +1 @@
f
1 change: 1 addition & 0 deletions test/autoindex/a/g/h.html
@@ -0,0 +1 @@
h
1 change: 1 addition & 0 deletions test/autoindex/a/g/i/index.html
@@ -0,0 +1 @@
i
58 changes: 58 additions & 0 deletions test/middleware-test.js
Expand Up @@ -246,3 +246,61 @@ test("stop a view server", function(t) {
t.end();
});
});


test("start a view server", function(t) {
view = require('../'),
http = require('resource-http');
http.listen({ port: 8888 }, function(err, _server) {
t.error(err, 'no error');
t.ok(_server, 'server is returned');
server = _server;
t.end();
});
});

test("load autoindex view", function(t) {
view.create( { path: __dirname + "/autoindex", autoindex: true } , function(err, _view) {
t.error(err, 'no error');
t.ok(_view, 'view is returned');
server.use(view.middle({view: _view}));

supertest(server) // first test index2
.get('/')
.end(function(err, res){
if (err) throw err;
t.error(err, 'no error');
// when using curl, returns as json
var rsp = JSON.parse(res.text)
t.equal(rsp[0], '/a')
t.equal(rsp[1], '/b')
t.equal(rsp[2], '/c')
t.equal(rsp[3], '/d')
t.end();
});

});
});

test("drill into nested autoindex", function(t) {
supertest(server) // first test index2
.get('/a')
.end(function(err, res){
if (err) throw err;
t.error(err, 'no error');
// when using curl, returns as json
var rsp = JSON.parse(res.text)
t.equal(rsp[0], '/e')
t.equal(rsp[1], '/f')
t.equal(rsp[2], '/g')
t.end();
});

});

test("stop a view server", function(t) {
server.server.close(function(err) {
t.ok(!err, 'no error');
t.end();
});
});

0 comments on commit 6bd9e26

Please sign in to comment.