-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy patherrors.js
More file actions
54 lines (47 loc) · 1.51 KB
/
errors.js
File metadata and controls
54 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var supertest = require('supertest')
var path = require('path')
// Helper functions for the FS
// var rm = require('./test-utils').rm
// var write = require('./test-utils').write
// var cp = require('./test-utils').cp
var read = require('./test-utils').read
var ldnode = require('../index')
describe('Error pages', function () {
// LDP with error pages
var errorLdp = ldnode({
root: path.join(__dirname, '/resources'),
errorPages: path.join(__dirname, '/resources/errorPages')
})
var errorServer = supertest(errorLdp)
// LDP with no error pages
var noErrorLdp = ldnode({
root: path.join(__dirname, '/resources'),
noErrorPages: true
})
var noErrorServer = supertest(noErrorLdp)
function defaultErrorPage (filepath, expected) {
var handler = function (res) {
var errorFile = read(filepath)
if (res.text === errorFile && !expected) {
console.log('Not default text')
}
}
return handler
}
describe('noErrorPages', function () {
var file404 = 'errorPages/404.html'
it('Should return 404 express default page', function (done) {
noErrorServer.get('/non-existent-file.html')
.expect(defaultErrorPage(file404, false))
.expect(404, done)
})
})
describe('errorPages set', function () {
var file404 = 'errorPages/404.html'
it('Should return 404 custom page if exists', function (done) {
errorServer.get('/non-existent-file.html')
.expect(defaultErrorPage(file404, true))
.expect(404, done)
})
})
})