headers.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. var should = require("should")
  2. var request = require('request')
  3. var path = require('path')
  4. var harp = require('../')
  5. describe("headers", function(){
  6. var projectPath = path.join(__dirname, "apps/headers")
  7. var port = 8901
  8. before(function(done){
  9. harp.server(projectPath, { port: port }, done)
  10. })
  11. // static
  12. it("should be correct with a valid CSS file", function(done){
  13. request("http://localhost:" + port + "/valid-css.css", function(e,r,b){
  14. r.statusCode.should.eql(200)
  15. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  16. r.headers.should.have.property("content-length")
  17. done()
  18. })
  19. })
  20. it("should be correct with a valid HTML file", function(done){
  21. request("http://localhost:" + port + "/valid-html.html", function(e, r, b){
  22. r.statusCode.should.eql(200)
  23. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  24. r.headers.should.have.property("content-length")
  25. done()
  26. })
  27. })
  28. it("should be correct with a valid JS file", function(done){
  29. request("http://localhost:" + port + "/valid-js.js", function(e, r, b){
  30. r.statusCode.should.eql(200)
  31. r.headers.should.have.property("content-type", "application/javascript")
  32. r.headers.should.have.property("content-length")
  33. done()
  34. })
  35. })
  36. // valid
  37. it("should be correct with a valid Jade file", function(done){
  38. request("http://localhost:" + port + "/valid-jade.html", function(e, r, b){
  39. r.statusCode.should.eql(200)
  40. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  41. r.headers.should.have.property("content-length")
  42. done()
  43. })
  44. })
  45. it("should be correct with a valid EJS file", function(done){
  46. request("http://localhost:" + port + "/valid-ejs.html", function(e, r, b){
  47. r.statusCode.should.eql(200)
  48. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  49. r.headers.should.have.property("content-length")
  50. done()
  51. })
  52. })
  53. it("should be correct with a valid Markdown file", function(done){
  54. request("http://localhost:" + port + "/valid-markdown.html", function(e, r, b){
  55. r.statusCode.should.eql(200)
  56. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  57. r.headers.should.have.property("content-length")
  58. done()
  59. })
  60. })
  61. it("should be correct with a valid CoffeeScript file", function(done){
  62. request("http://localhost:" + port + "/valid-coffee.js", function(e, r, b){
  63. r.statusCode.should.eql(200)
  64. r.headers.should.have.property("content-type", "application/javascript")
  65. r.headers.should.have.property("content-length")
  66. done()
  67. })
  68. })
  69. it("should be correct with a valid LESS file", function(done){
  70. request("http://localhost:" + port + "/valid-less.css", function(e, r, b){
  71. r.statusCode.should.eql(200)
  72. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  73. r.headers.should.have.property("content-length")
  74. done()
  75. })
  76. })
  77. it("should be correct with a valid Stylus file", function(done){
  78. request("http://localhost:" + port + "/valid-styl.css", function(e, r, b){
  79. r.statusCode.should.eql(200)
  80. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  81. r.headers.should.have.property("content-length")
  82. done()
  83. })
  84. })
  85. it("should be correct with a valid SCSS file", function(done){
  86. request("http://localhost:" + port + "/valid-scss.css", function(e, r, b){
  87. r.statusCode.should.eql(200)
  88. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  89. r.headers.should.have.property("content-length")
  90. done()
  91. })
  92. })
  93. it("should be correct with a valid Sass file", function(done){
  94. request("http://localhost:" + port + "/valid-sass.css", function(e, r, b){
  95. r.statusCode.should.eql(200)
  96. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  97. r.headers.should.have.property("content-length")
  98. done()
  99. })
  100. })
  101. // invalid
  102. it("should be correct with an invalid EJS file", function(done){
  103. request("http://localhost:" + port + "/invalid-ejs.html", function(e, r, b){
  104. r.statusCode.should.eql(500)
  105. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  106. r.headers.should.have.property("content-length")
  107. done()
  108. })
  109. })
  110. it("should be correct with an invalid Jade file", function(done){
  111. request("http://localhost:" + port + "/invalid-jade.html", function(e, r, b){
  112. r.statusCode.should.eql(500)
  113. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  114. r.headers.should.have.property("content-length")
  115. done()
  116. })
  117. })
  118. it("should be correct with an invalid LESS file", function(done){
  119. request("http://localhost:" + port + "/invalid-less.css", function(e, r, b){
  120. r.statusCode.should.eql(200)
  121. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  122. r.headers.should.have.property("content-length")
  123. done()
  124. })
  125. })
  126. it("should be correct with an invalid Stylus file", function(done){
  127. request("http://localhost:" + port + "/invalid-styl.css", function(e, r, b){
  128. r.statusCode.should.eql(200)
  129. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  130. r.headers.should.have.property("content-length")
  131. done()
  132. })
  133. })
  134. it("should be correct with an invalid SCSS file", function(done){
  135. request("http://localhost:" + port + "/invalid-scss.css", function(e, r, b){
  136. r.statusCode.should.eql(200)
  137. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  138. r.headers.should.have.property("content-length")
  139. done()
  140. })
  141. })
  142. it("should be correct with an invalid Sass file", function(done){
  143. request("http://localhost:" + port + "/invalid-sass.css", function(e, r, b){
  144. r.statusCode.should.eql(200)
  145. r.headers.should.have.property("content-type", "text/css; charset=UTF-8")
  146. r.headers.should.have.property("content-length")
  147. done()
  148. })
  149. })
  150. // TODO: This should change to javascript error file.
  151. it("should be correct with an invalid CoffeeScript file", function(done){
  152. request("http://localhost:" + port + "/invalid-coffee.js", function(e, r, b){
  153. r.statusCode.should.eql(500)
  154. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  155. r.headers.should.have.property("content-length")
  156. done()
  157. })
  158. })
  159. // direct
  160. it("should be correct when Jade file requested", function(done){
  161. request("http://localhost:" + port + "/valid-jade.jade", function(e, r, b){
  162. r.statusCode.should.eql(404)
  163. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  164. r.headers.should.have.property("content-length")
  165. done()
  166. })
  167. })
  168. it("should be correct when EJS file requested", function(done){
  169. request("http://localhost:" + port + "/valid-ejs.ejs", function(e, r, b){
  170. r.statusCode.should.eql(404)
  171. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  172. r.headers.should.have.property("content-length")
  173. done()
  174. })
  175. })
  176. it("should be correct when Markdown file requested", function(done){
  177. request("http://localhost:" + port + "/valid-markdown.md", function(e, r, b){
  178. r.statusCode.should.eql(404)
  179. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  180. r.headers.should.have.property("content-length")
  181. done()
  182. })
  183. })
  184. it("should be correct when CoffeeScript file requested", function(done){
  185. request("http://localhost:" + port + "/valid-coffee.coffee", function(e, r, b){
  186. r.statusCode.should.eql(404)
  187. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  188. r.headers.should.have.property("content-length")
  189. done()
  190. })
  191. })
  192. it("should be correct when LESS file requested", function(done){
  193. request("http://localhost:" + port + "/valid-less.less", function(e, r, b){
  194. r.statusCode.should.eql(404)
  195. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  196. r.headers.should.have.property("content-length")
  197. done()
  198. })
  199. })
  200. it("should be correct when Stylus file requested", function(done){
  201. request("http://localhost:" + port + "/valid-styl.styl", function(e, r, b){
  202. r.statusCode.should.eql(404)
  203. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  204. r.headers.should.have.property("content-length")
  205. done()
  206. })
  207. })
  208. it("should be correct when SCSS file requested", function(done){
  209. request("http://localhost:" + port + "/valid-scss.scss", function(e, r, b){
  210. r.statusCode.should.eql(404)
  211. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  212. r.headers.should.have.property("content-length")
  213. done()
  214. })
  215. })
  216. // missing pages
  217. it("should be correct when missing css file", function(done){
  218. request("http://localhost:" + port + "/missing.css", function(e, r, b){
  219. r.statusCode.should.eql(404)
  220. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  221. r.headers.should.have.property("content-length")
  222. done()
  223. })
  224. })
  225. it("should be correct when missing html file", function(done){
  226. request("http://localhost:" + port + "/missing.html", function(e, r, b){
  227. r.statusCode.should.eql(404)
  228. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  229. r.headers.should.have.property("content-length")
  230. done()
  231. })
  232. })
  233. it("should be correct when missing js file", function(done){
  234. request("http://localhost:" + port + "/missing.js", function(e, r, b){
  235. r.statusCode.should.eql(404)
  236. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  237. r.headers.should.have.property("content-length")
  238. done()
  239. })
  240. })
  241. })