forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallbacks.js
86 lines (73 loc) · 2.7 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
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){
harp.server(projectPath, { port: port }, function(){
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){
harp.server(projectPath, { port: port }, function(){
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()
})
})
})
})
after(function(done){
exec("rm -rf " + path.join(__dirname, "out"), function(){
done()
})
})
})