errors.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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("errors", function(){
  8. describe("err-invalid-config", function(){
  9. var projectPath = path.join(__dirname, "apps/err-invalid-config")
  10. var outputPath = path.join(__dirname, "out/err-invalid-config")
  11. var port = 8111
  12. before(function(done){
  13. harp.server(projectPath, { port: port }, function(){
  14. done()
  15. })
  16. })
  17. it("should get error message for invalid harp.json", function(done){
  18. request('http://localhost:'+ port +'/', function (e, r, b) {
  19. r.statusCode.should.eql(500)
  20. b.should.include(harp.pkg.version)
  21. harp.compile(projectPath, outputPath, function(error){
  22. should.exist(error)
  23. error.should.have.property("source")
  24. error.should.have.property("dest")
  25. error.should.have.property("filename")
  26. error.should.have.property("message")
  27. error.should.have.property("stack")
  28. error.should.have.property("lineno")
  29. done()
  30. })
  31. })
  32. })
  33. })
  34. describe("err-invalid-data", function(){
  35. var projectPath = path.join(__dirname, "apps/err-invalid-data")
  36. var outputPath = path.join(__dirname, "out/err-invalid-data")
  37. var port = 8112
  38. before(function(done){
  39. harp.server(projectPath, { port: port }, function(){
  40. done()
  41. })
  42. })
  43. it("should get error message for invalid _data.json", function(done){
  44. request('http://localhost:'+ port +'/', function (e, r, b) {
  45. r.statusCode.should.eql(500)
  46. b.should.include(harp.pkg.version)
  47. harp.compile(projectPath, outputPath, function(error){
  48. should.exist(error)
  49. error.should.have.property("source")
  50. error.should.have.property("dest")
  51. error.should.have.property("filename")
  52. error.should.have.property("message")
  53. error.should.have.property("stack")
  54. error.should.have.property("lineno")
  55. done()
  56. })
  57. })
  58. })
  59. })
  60. describe("err-missing-public", function(){
  61. var projectPath = path.join(__dirname, "apps/err-missing-public")
  62. var outputPath = path.join(__dirname, "out/err-missing-public")
  63. var port = 8113
  64. before(function(done){
  65. harp.server(projectPath, { port: port }, function(){
  66. done()
  67. })
  68. })
  69. it("should get error message for invalid _data.json", function(done){
  70. request('http://localhost:'+ port +'/', function (e, r, b) {
  71. r.statusCode.should.eql(500)
  72. b.should.include(harp.pkg.version)
  73. harp.compile(projectPath, outputPath, function(error){
  74. should.exist(error)
  75. error.should.have.property("source")
  76. error.should.have.property("dest")
  77. error.should.have.property("filename")
  78. error.should.have.property("message")
  79. error.should.have.property("stack")
  80. error.should.have.property("lineno")
  81. done()
  82. })
  83. })
  84. })
  85. })
  86. describe("err-missing-public", function(){
  87. var projectPath = path.join(__dirname, "apps/err-missing-404")
  88. var outputPath = path.join(__dirname, "out/err-missing-404")
  89. var port = 8114
  90. before(function(done){
  91. harp.server(projectPath, { port: port }, function(){
  92. done()
  93. })
  94. })
  95. it("should return proper mime type on 404 page", function(done){
  96. request('http://localhost:'+ port +'/some/missing/path.css', function (e, r, b) {
  97. r.statusCode.should.eql(404)
  98. b.should.include(harp.pkg.version)
  99. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  100. done()
  101. })
  102. })
  103. })
  104. after(function(done){
  105. exec("rm -rf " + path.join(__dirname, "out"), function(){
  106. done()
  107. })
  108. })
  109. })