compile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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("compile", function(){
  8. describe("basic app", function(){
  9. var projectPath = path.join(__dirname, "apps/compile/basic")
  10. var outputPath = path.join(__dirname, "out/compile-basic")
  11. it("should compile", function(done){
  12. harp.compile(projectPath, outputPath, function(error){
  13. should.not.exist(error)
  14. done()
  15. })
  16. })
  17. it("compile should not include folders named with underscores", function(done) {
  18. var cssOutputPath = path.join(outputPath, "/css")
  19. var rsp = fs.existsSync(path.join(cssOutputPath, "/_partials/some.css"))
  20. rsp.should.be.false
  21. var rsp = fs.existsSync(path.join(cssOutputPath, "/_partials/_more.css"))
  22. rsp.should.be.false
  23. done()
  24. })
  25. it("compile should not include files named with underscores", function(done) {
  26. var cssOutputPath = path.join(outputPath, "/css")
  27. var rsp = fs.existsSync(path.join(cssOutputPath, "/one/two/three/_four.css"))
  28. rsp.should.be.false
  29. var rsp = fs.existsSync(path.join(cssOutputPath, "/one/two/three/_five.css"))
  30. rsp.should.be.false
  31. var rsp = fs.existsSync(path.join(cssOutputPath, "/_nav.css"))
  32. rsp.should.be.false
  33. done()
  34. })
  35. after(function(done){
  36. exec("rm -rf " + outputPath, function() {
  37. done();
  38. })
  39. })
  40. })
  41. describe("root app with .git dir", function(){
  42. var projectPath = path.join(__dirname, "apps","compile","root")
  43. var outputPath = path.join(__dirname, "out","compile-root")
  44. var gitPath = path.join(projectPath, ".git")
  45. // Make at runtime since git refuses to store .git dirs
  46. if (!fs.existsSync(gitPath)) {
  47. fs.mkdirSync(gitPath);
  48. fs.openSync(path.join(gitPath, "foo"), 'a')
  49. }
  50. it("should compile", function(done){
  51. harp.compile(projectPath, outputPath, function(error){
  52. should.not.exist(error)
  53. done()
  54. })
  55. })
  56. it("should not include .git in output", function(done) {
  57. var rsp = fs.existsSync(path.join(projectPath, ".git", "foo"))
  58. rsp.should.be.true
  59. var rsp = fs.existsSync(path.join(outputPath, ".git"))
  60. rsp.should.be.false
  61. done()
  62. })
  63. after(function(done){
  64. exec("rm -rf " + outputPath + " " + gitPath, function() {
  65. done();
  66. })
  67. })
  68. })
  69. describe("root app with output dir containing .git in project dir", function(){
  70. var projectPath = path.join(__dirname, "apps","compile","root")
  71. var outputPath = path.join(projectPath, "out")
  72. var gitPath = path.join(outputPath, ".git")
  73. // Making this at runtime since git refuses to store .git dirs
  74. if (!fs.existsSync(gitPath)) {
  75. fs.mkdirSync(outputPath);
  76. fs.mkdirSync(gitPath);
  77. fs.openSync(path.join(gitPath, "foo"), 'a')
  78. }
  79. it("should compile", function(done){
  80. harp.compile(projectPath, outputPath, function(error){
  81. should.not.exist(error)
  82. done()
  83. })
  84. })
  85. it("should not include a copy of the output subpath in output", function(done) {
  86. var rsp = fs.existsSync(path.join(outputPath, "out"))
  87. rsp.should.be.false
  88. done();
  89. })
  90. after(function(done){
  91. exec("rm -rf " + outputPath, function() {
  92. done();
  93. })
  94. })
  95. })
  96. })