forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallbacks.js
147 lines (125 loc) · 4.88 KB
/
fallbacks.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var should = require("should")
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
var harp = require("../")
describe("fallbacks", function(){
describe("plain 200 file", function(){
var projectPath = path.join(__dirname, "apps/fallbacks/two-hundy/plain")
var outputPath = path.join(__dirname, "out/fallbacks-two-hundy-plain")
var port = 8115
before(function(done){
harp.compile(projectPath, outputPath, function(errors, output){
var server = harp.server(projectPath)
server.listen(port, done)
})
})
it("should return proper mime type on 200 page", function(done){
request('http://localhost:'+ port +'/some/fallback/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
it("should have custom 200 page", function(done){
fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
should.not.exist(err)
request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
})
})
describe("processed 200 file", function(){
var projectPath = path.join(__dirname, "apps/fallbacks/two-hundy/processed")
var outputPath = path.join(__dirname, "out/fallbacks-two-hundy-processed")
var port = 8116
before(function(done){
harp.compile(projectPath, outputPath, function(errors, output){
var server = harp.server(projectPath)
server.listen(port, done)
})
})
it("should return proper mime type on 200 page", function(done){
request('http://localhost:'+ port +'/some/fallback/path', function(e, r, b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
it("should have custom 200 page", function(done){
fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
should.not.exist(err)
request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
})
})
describe("nested 200 file", function(){
var projectPath = path.join(__dirname, "apps/fallbacks/two-hundy/nested")
var outputPath = path.join(__dirname, "out/fallbacks-two-hundy-nested")
var port = 8117
before(function(done){
harp.compile(projectPath, outputPath, function(errors, output){
var server = harp.server(projectPath)
server.listen(port, done)
})
})
it("should return 404 on missing path", function(done){
request('http://localhost:'+ port +'/some/fallback/path', function(e, r, b){
r.statusCode.should.eql(404)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
it("should have fallback 404 page", function(done){
request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
r.statusCode.should.eql(404)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
it("should return custom 200 page on nested path", function(done){
fs.readFile(path.join(outputPath, "app/200.html"), function(err, contents){
should.not.exist(err)
request('http://localhost:'+ port +'/app/missing/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
})
it("should return 200 on /app/", function(done){
fs.readFile(path.join(outputPath, "app/200.html"), function(err, contents){
should.not.exist(err)
request('http://localhost:'+ port +'/app/', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
})
it("should return 301 on /app to redirect to /app/", function(done){
request('http://localhost:'+ port +'/app', { followRedirect: false }, function(e,r,b){
r.statusCode.should.eql(301)
//r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
})
after(function(done){
exec("rm -rf " + path.join(__dirname, "out"), function(){
done()
})
})
})