basic.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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("basic", function(){
  8. var projectPath = path.join(__dirname, "apps/basic")
  9. var outputPath = path.join(__dirname, "out/basic")
  10. var config;
  11. before(function(done){
  12. harp.compile(projectPath, outputPath, function(errors, output){
  13. config = output
  14. harp.server(projectPath, { port: 8100 }, done)
  15. })
  16. })
  17. it("should have node version in config", function(done){
  18. config.should.have.property("harp_version")
  19. done()
  20. })
  21. it("should have global vars", function(done){
  22. var staticGlobals = require(path.join(outputPath, "globals.json"))
  23. staticGlobals.should.have.property("environment", "production")
  24. staticGlobals.should.have.property("public")
  25. request('http://localhost:8100/globals.json', function (e, r, b) {
  26. r.statusCode.should.eql(200)
  27. var dynamicGlobals = JSON.parse(b)
  28. dynamicGlobals.should.have.property("environment", "development")
  29. dynamicGlobals.should.have.property("public")
  30. done()
  31. })
  32. })
  33. it("should have current vars", function(done){
  34. var staticCurrent = require(path.join(outputPath, "current.json"))
  35. staticCurrent.should.have.property("path")
  36. staticCurrent.should.have.property("source", "current.json")
  37. request('http://localhost:8100/current.json', function (e, r, b) {
  38. r.statusCode.should.eql(200)
  39. var dynamicCurrent = JSON.parse(b)
  40. dynamicCurrent.should.have.property("path")
  41. dynamicCurrent.should.have.property("source", "current.json")
  42. done()
  43. })
  44. })
  45. it("should have index file that uses the layout", function(done){
  46. fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
  47. contents.toString().should.include("Kitchen Sink")
  48. contents.toString().should.include("Home")
  49. request('http://localhost:8100/', function (e, r, b) {
  50. r.statusCode.should.eql(200)
  51. b.should.include("Kitchen Sink")
  52. b.should.include("Home")
  53. done()
  54. })
  55. })
  56. })
  57. it("should have custom 404 page that does not use layout", function(done){
  58. fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
  59. contents.toString().should.not.include("Kitchen Sink")
  60. contents.toString().should.include("Custom, Page Not Found")
  61. request('http://localhost:8100/some/missing/path', function (e, r, b) {
  62. r.statusCode.should.eql(404)
  63. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  64. b.should.not.include("Kitchen Sink")
  65. b.should.include("Custom, Page Not Found")
  66. b.should.eql(contents.toString())
  67. done()
  68. })
  69. })
  70. })
  71. it("should return CSS file", function(done){
  72. fs.readFile(path.join(outputPath, "css", "main.css"), function(err, contents){
  73. contents.toString().should.include("background")
  74. request('http://localhost:8100/css/main.css', function (e, r, b) {
  75. r.statusCode.should.eql(200)
  76. b.should.include("background")
  77. b.should.eql(contents.toString())
  78. done()
  79. })
  80. })
  81. })
  82. it("should return proper mime type on 404 page", function(done){
  83. request('http://localhost:8100/some/missing/path.css', function (e, r, b) {
  84. r.statusCode.should.eql(404)
  85. r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
  86. done()
  87. })
  88. })
  89. it("should render HTML page without requiring extension", function(done){
  90. fs.readFile(path.join(outputPath, "basic.html"), function(err, contents){
  91. contents.toString().should.not.include("Kitchen Sink")
  92. contents.toString().should.include("<h1>Basic HTML Page</h1>")
  93. request('http://localhost:8100/basic', function(e,r,b){
  94. r.statusCode.should.eql(200)
  95. b.should.not.include("Kitchen Sink")
  96. b.should.include("<h1>Basic HTML Page</h1>")
  97. b.should.eql(contents.toString())
  98. done()
  99. })
  100. })
  101. })
  102. it("should not return file starting with underscore", function(done){
  103. request('http://localhost:8100/shared/_nav.jade', function(e,r,b){
  104. r.statusCode.should.eql(404)
  105. done()
  106. })
  107. })
  108. it("should render HTML page with spaces in the file name", function(done){
  109. request('http://localhost:8100/articles/with%20spaces', function(e,r,b){
  110. r.statusCode.should.eql(200)
  111. b.should.include("foo article")
  112. done()
  113. })
  114. })
  115. after(function(done){
  116. exec("rm -rf " + outputPath, function(){
  117. done()
  118. })
  119. })
  120. })