fallbacks.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var should = require("should")
  2. var request = require('request')
  3. var path = require("path")
  4. var fs = require("fs")
  5. var exec = require("child_process").exec
  6. var harp = require("../")
  7. describe("fallbacks", function(){
  8. describe("plain 200 file", function(){
  9. var projectPath = path.join(__dirname, "apps/fallbacks/two-hundy/plain")
  10. var outputPath = path.join(__dirname, "out/fallbacks-two-hundy-plain")
  11. var port = 8115
  12. before(function(done){
  13. harp.compile(projectPath, outputPath, function(errors, output){
  14. harp.server(projectPath, { port: port }, function(){
  15. done()
  16. })
  17. })
  18. })
  19. it("should return proper mime type on 200 page", function(done){
  20. request('http://localhost:'+ port +'/some/fallback/path', function(e,r,b){
  21. r.statusCode.should.eql(200)
  22. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  23. done()
  24. })
  25. })
  26. it("should have custom 200 page", function(done){
  27. fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
  28. should.not.exist(err)
  29. request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
  30. r.statusCode.should.eql(200)
  31. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  32. b.should.eql(contents.toString())
  33. done()
  34. })
  35. })
  36. })
  37. })
  38. describe("processed 200 file", function(){
  39. var projectPath = path.join(__dirname, "apps/fallbacks/two-hundy/processed")
  40. var outputPath = path.join(__dirname, "out/fallbacks-two-hundy-processed")
  41. var port = 8116
  42. before(function(done){
  43. harp.compile(projectPath, outputPath, function(errors, output){
  44. harp.server(projectPath, { port: port }, function(){
  45. done()
  46. })
  47. })
  48. })
  49. it("should return proper mime type on 200 page", function(done){
  50. request('http://localhost:'+ port +'/some/fallback/path', function(e, r, b){
  51. r.statusCode.should.eql(200)
  52. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  53. done()
  54. })
  55. })
  56. it("should have custom 200 page", function(done){
  57. fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
  58. should.not.exist(err)
  59. request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
  60. r.statusCode.should.eql(200)
  61. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  62. b.should.eql(contents.toString())
  63. done()
  64. })
  65. })
  66. })
  67. })
  68. after(function(done){
  69. exec("rm -rf " + path.join(__dirname, "out"), function(){
  70. done()
  71. })
  72. })
  73. })