plain.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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("plain", function(){
  8. var output = path.join(__dirname, "out/plain")
  9. describe("framework-style", function(){
  10. var projectPath = path.join(__dirname, "apps/plain/framework-style")
  11. var outputPath = path.join(__dirname, "out/plain/framework-style")
  12. var config;
  13. before(function(done){
  14. harp.compile(projectPath, outputPath, function(errors, output){
  15. config = output
  16. harp.server(projectPath, { port: 8102 }, done)
  17. })
  18. })
  19. it("should have node version in config", function(done){
  20. config.should.have.property("harp_version")
  21. done()
  22. })
  23. it("should serve index file", function(done){
  24. fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
  25. request('http://localhost:8102/', function(e, r, b){
  26. r.statusCode.should.eql(200)
  27. b.should.eql(contents.toString())
  28. done()
  29. })
  30. })
  31. })
  32. it("should serve text file", function(done){
  33. fs.readFile(path.join(outputPath, "hello.txt"), function(err, contents){
  34. contents.toString().should.eql("text files are wonderful")
  35. request('http://localhost:8102/hello.txt', function(e, r, b){
  36. r.statusCode.should.eql(200)
  37. b.should.eql(contents.toString())
  38. done()
  39. })
  40. })
  41. })
  42. it("should have custom 404 page that is raw HTML", function(done){
  43. fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
  44. request('http://localhost:8102/404.html', function(e, r, b){
  45. r.statusCode.should.eql(200)
  46. b.should.eql(contents.toString())
  47. request('http://localhost:8102/missing/path', function(e, r, b){
  48. r.statusCode.should.eql(404)
  49. b.should.eql(contents.toString())
  50. done()
  51. })
  52. })
  53. })
  54. })
  55. })
  56. describe("root-style", function(){
  57. var projectPath = path.join(__dirname, "apps/plain/root-style")
  58. var outputPath = path.join(__dirname, "out/plain/root-style")
  59. var config;
  60. before(function(done){
  61. harp.compile(projectPath, outputPath, function(errors, output){
  62. config = output
  63. harp.server(projectPath, { port: 8103 }, done)
  64. })
  65. })
  66. it("should have node version in config", function(done){
  67. config.should.have.property("harp_version")
  68. done()
  69. })
  70. it("should serve index file", function(done){
  71. fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
  72. request('http://localhost:8103/', function(e, r, b){
  73. r.statusCode.should.eql(200)
  74. b.should.eql(contents.toString())
  75. done()
  76. })
  77. })
  78. })
  79. it("should serve text file", function(done){
  80. fs.readFile(path.join(outputPath, "hello.txt"), function(err, contents){
  81. contents.toString().should.eql("text files are wonderful")
  82. request('http://localhost:8103/hello.txt', function(e, r, b){
  83. r.statusCode.should.eql(200)
  84. b.should.eql(contents.toString())
  85. done()
  86. })
  87. })
  88. })
  89. it("should have custom 404 page that is raw HTML", function(done){
  90. fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
  91. request('http://localhost:8103/404.html', function(e, r, b){
  92. r.statusCode.should.eql(200)
  93. b.should.eql(contents.toString())
  94. request('http://localhost:8103/missing/path', function(e, r, b){
  95. r.statusCode.should.eql(404)
  96. b.should.eql(contents.toString())
  97. done()
  98. })
  99. })
  100. })
  101. })
  102. })
  103. after(function(done){
  104. exec("rm -rf " + output, function(){
  105. done()
  106. })
  107. })
  108. })