templates.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var should = require('should')
  2. var polymer = require('../')
  3. describe("templates", function(){
  4. var root = __dirname + "/fixtures/templates"
  5. var poly = polymer.root(root)
  6. describe(".nunjucks", function(){
  7. it("should render simple flat nunjucks file", function(done){
  8. poly.render("nunjucks-sample.nunjucks", function(error, body){
  9. should.not.exist(error)
  10. should.exist(body)
  11. body.should.include("Hello Nunjucks!")
  12. done()
  13. })
  14. })
  15. it("should be configured to extend and include another files", function(done) {
  16. poly.render("nunjucks/index.nunjucks", function(error, body){
  17. should.not.exist(error)
  18. should.exist(body)
  19. body.should.include("<h1>Nunjucks</h1>")
  20. body.should.include("<p>This is a sample file.</p>")
  21. done()
  22. })
  23. })
  24. it("should bypass layout rendering", function(done) {
  25. poly.render("nunjucks/index.nunjucks", function(error, body){
  26. should.not.exist(error)
  27. body.should.not.include('This layout file should be ignored.')
  28. done()
  29. })
  30. })
  31. })
  32. describe(".ejs", function(){
  33. it("should render ejs file", function(done){
  34. poly.render("bio.ejs", function(error, body){
  35. should.not.exist(error)
  36. should.exist(body)
  37. body.should.include("<h1>Hello EJS</h1>")
  38. done()
  39. })
  40. })
  41. it("should minify beyond preprocessor", function(done){
  42. poly.render("bio.ejs", function(error, body){
  43. should.not.exist(error)
  44. body.should.not.include("\n\n")
  45. done()
  46. })
  47. })
  48. })
  49. describe(".md", function(){
  50. it("should render markdown file", function(done){
  51. poly.render("stuff.md", function(error, body){
  52. should.not.exist(error)
  53. should.exist(body)
  54. body.should.include("<h1>hello markdown</h1>")
  55. body.should.include("<p>")
  56. body.should.include('<code class="language-json">')
  57. body.should.not.include('<code class="lang-json">')
  58. done()
  59. })
  60. })
  61. it("should minify beyond preprocessor", function(done){
  62. poly.render("stuff.md", function(error, body){
  63. should.not.exist(error)
  64. body.should.not.include("\n\n")
  65. done()
  66. })
  67. })
  68. it("should render markdown file encoded in UTF-8 with BOM", function(done){
  69. poly.render("bom.md", function(error, body){
  70. should.not.exist(error)
  71. should.exist(body)
  72. body.should.include("<h1>file with bom marker</h1>")
  73. done()
  74. })
  75. })
  76. })
  77. describe(".jade", function(){
  78. it("should not give deprecated !!! warning", function(done){
  79. poly.render("deprecated/jade/index.jade", function(error, body){
  80. should.exist(error)
  81. should.not.exist(body)
  82. done()
  83. })
  84. })
  85. it("should have jade partial layout and include working", function(done){
  86. poly.render("index.jade", function(error, body){
  87. should.not.exist(error)
  88. should.exist(body)
  89. body.should.include("<h1>Sintaxi</h1>")
  90. body.should.include("<h2>Hello World</h2>")
  91. body.should.include("<h3>Brock Whitten</h3>")
  92. body.should.include("<h4>Vancouver</h4>")
  93. done()
  94. })
  95. })
  96. it("should minify beyond preprocessor", function(done){
  97. poly.render("index.jade", function(error, body){
  98. should.not.exist(error)
  99. body.should.not.include("\n\n")
  100. done()
  101. })
  102. })
  103. it("should pass in partials from the global object", function(done){
  104. poly.render("index.jade", function(error, body){
  105. should.not.exist(error)
  106. should.exist(body)
  107. body.should.include("<h1>Sintaxi</h1>")
  108. body.should.include("<h2>Hello World</h2>")
  109. body.should.include("<h3>Brock Whitten</h3>")
  110. body.should.include("<h4>Vancouver</h4>")
  111. done()
  112. })
  113. })
  114. it("should return errors if error found", function(done){
  115. poly.render("invalid.jade", function(error, body){
  116. should.not.exist(body)
  117. should.exist(error)
  118. error.should.have.property("name")
  119. error.should.have.property("message")
  120. error.should.have.property("stack")
  121. done()
  122. })
  123. })
  124. it("should extend from a file with absolute path", function(done){
  125. poly.render("extend.jade", function(error, body){
  126. should.not.exist(error)
  127. should.exist(body)
  128. body.should.include("<h1>Sintaxi</h1>")
  129. body.should.include("<h2>Hello World</h2>")
  130. body.should.include("<h3>Brock Whitten</h3>")
  131. body.should.include("<h4>Vancouver</h4>")
  132. done()
  133. })
  134. })
  135. })
  136. })