forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplain.js
127 lines (108 loc) · 3.83 KB
/
plain.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
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("plain", function(){
var output = path.join(__dirname, "out/plain")
describe("framework-style", function(){
var projectPath = path.join(__dirname, "apps/plain/framework-style")
var outputPath = path.join(__dirname, "out/plain/framework-style")
var config;
before(function(done){
harp.compile(projectPath, outputPath, function(errors, output){
config = output
harp.server(projectPath, { port: 8102 }, done)
})
})
it("should have node version in config", function(done){
config.should.have.property("harp_version")
done()
})
it("should serve index file", function(done){
fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
request('http://localhost:8102/', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
done()
})
})
})
it("should serve text file", function(done){
fs.readFile(path.join(outputPath, "hello.txt"), function(err, contents){
contents.toString().should.eql("text files are wonderful")
request('http://localhost:8102/hello.txt', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
done()
})
})
})
it("should have custom 404 page that is raw HTML", function(done){
fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
request('http://localhost:8102/404.html', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
request('http://localhost:8102/missing/path', function(e, r, b){
r.statusCode.should.eql(404)
b.should.eql(contents.toString())
done()
})
})
})
})
})
describe("root-style", function(){
var projectPath = path.join(__dirname, "apps/plain/root-style")
var outputPath = path.join(__dirname, "out/plain/root-style")
var config;
before(function(done){
harp.compile(projectPath, outputPath, function(errors, output){
config = output
harp.server(projectPath, { port: 8103 }, done)
})
})
it("should have node version in config", function(done){
config.should.have.property("harp_version")
done()
})
it("should serve index file", function(done){
fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
request('http://localhost:8103/', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
done()
})
})
})
it("should serve text file", function(done){
fs.readFile(path.join(outputPath, "hello.txt"), function(err, contents){
contents.toString().should.eql("text files are wonderful")
request('http://localhost:8103/hello.txt', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
done()
})
})
})
it("should have custom 404 page that is raw HTML", function(done){
fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
request('http://localhost:8103/404.html', function(e, r, b){
r.statusCode.should.eql(200)
b.should.eql(contents.toString())
request('http://localhost:8103/missing/path', function(e, r, b){
r.statusCode.should.eql(404)
b.should.eql(contents.toString())
done()
})
})
})
})
})
after(function(done){
exec("rm -rf " + output, function(){
done()
})
})
})