Skip to content

Commit e55202b

Browse files
author
Martin Martinez Rivera
committed
Add basic page error handling tests
1 parent e7ce40e commit e55202b

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"test-params": "./node_modules/mocha/bin/mocha ./test/params.js",
6565
"test-http": "./node_modules/mocha/bin/mocha ./test/http.js",
6666
"test-formats": "./node_modules/mocha/bin/mocha ./test/formats.js",
67+
"test-errors": "./node_modules/mocha/bin/mocha ./test/errors.js",
6768
"ldp-webid": "node ./bin/ldnode.js --webid --cert ./test/keys/cert.pem --key ./test/keys/key.pem -v -r ./test/resources",
6869
"ldp-ssl": "node ./bin/ldnode.js --cert ./test/keys/cert.pem --key ./test/keys/key.pem -v -r ./test/resources"
6970
},

‎test/errors.js‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*jslint node: true*/
2+
var assert = require('chai').assert;
3+
var fs = require('fs');
4+
var $rdf = require('rdflib');
5+
var request = require('request');
6+
var S = require('string');
7+
var supertest = require('supertest');
8+
var async = require('async');
9+
10+
// Helper functions for the FS
11+
var rm = require('./test-utils').rm;
12+
var write = require('./test-utils').write;
13+
var cp = require('./test-utils').cp;
14+
var read = require('./test-utils').read;
15+
16+
var ldnode = require('../index');
17+
var ACL = require('../lib/acl').ACL;
18+
var ns = require('../lib/vocab/ns.js').ns;
19+
20+
describe('Error page tests', function() {
21+
var errorAddress = 'http://localhost:3457/test/';
22+
23+
var errorLdp = ldnode.createServer({
24+
root: __dirname + '/resources',
25+
});
26+
errorLdp.listen(3457);
27+
28+
var errorServer = supertest(errorAddress);
29+
30+
// Instance of server with error pages flag set to false
31+
var noErrorAddress = 'http://localhost:3458/test/';
32+
33+
var noErrorLdp = ldnode.createServer({
34+
root: __dirname + '/resources',
35+
noErrorPages: true
36+
});
37+
noErrorLdp.listen(3458);
38+
39+
var noErrorServer = supertest(errorAddress);
40+
41+
42+
describe('Error page test', function() {
43+
it('Should return 404 custom page if flag set to true',
44+
function(done) {
45+
errorServer.get('/non-existent-file.html')
46+
.expect(/404 Error Page/)
47+
.expect(404, done);
48+
});
49+
it('Should return 404 default page if flag set to false',
50+
function(done) {
51+
function isDefaultErrorPage(customText) {
52+
var handler = function (res) {
53+
if (res.text.match(customText)){
54+
console.log("Not default text");
55+
}
56+
};
57+
return handler;
58+
}
59+
noErrorServer.get('/non-existent-file.html')
60+
.expect(isDefaultErrorPage('404 Error Page'))
61+
.expect(404, done);
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)