data.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var should = require('should')
  2. var polymer = require('../')
  3. describe("data", function(){
  4. describe("valid", function(){
  5. var root = __dirname + "/fixtures/data/valid"
  6. var poly = polymer.root(root)
  7. it("should be available in the layouts", function(done){
  8. poly.render("index.jade", function(error, body){
  9. should.not.exist(error)
  10. should.exist(body)
  11. body.should.include("<h1>My Articles</h1>")
  12. body.should.include('<h5 class="feature">Earth people, New York to California</h5>')
  13. done()
  14. })
  15. })
  16. it("should be available in the template", function(done){
  17. poly.render("articles/hello-jupiter.jade", function(error, body){
  18. should.not.exist(error)
  19. should.exist(body)
  20. body.should.include("<h3>I was born on Jupiter</h3>")
  21. body.should.include("<h4>Brock Whitten</h4>")
  22. done()
  23. })
  24. })
  25. it("should be available in the nunjucks template", function(done){
  26. poly.render("articles/hello-jupiter.nunjucks", function(error, body){
  27. should.not.exist(error)
  28. should.exist(body)
  29. body.should.include("<h3>I was born on Jupiter</h3>")
  30. body.should.include("<h4>Brock Whitten</h4>")
  31. done()
  32. })
  33. })
  34. it("should handle escaped html", function(done){
  35. poly.render("articles/hello-pluto.jade", function(error, body){
  36. should.not.exist(error)
  37. should.exist(body)
  38. body.should.include("<h1><a href=\"http://harpjs.com\">Harp</a></h1>")
  39. done()
  40. })
  41. })
  42. it("should be available to override data when calling partial", function(done){
  43. poly.render("index.jade", function(error, body){
  44. should.not.exist(error)
  45. should.exist(body)
  46. body.should.include("<h3>I was born on Jupiter</h3>")
  47. body.should.include("<h4>Kool Keith</h4>")
  48. done()
  49. })
  50. })
  51. })
  52. describe("invalid", function(){
  53. it("should return errors when invalid _data.json file", function(done){
  54. var root = __dirname + "/fixtures/data/invalid"
  55. try{
  56. var poly = polymer.root(root)
  57. }catch(error){
  58. should.exist(error)
  59. error.should.have.property('source', "Data")
  60. error.should.have.property('dest', "Globals")
  61. error.should.have.property('lineno')
  62. error.should.have.property('filename')
  63. error.should.have.property('message')
  64. error.should.have.property('stack')
  65. done()
  66. }
  67. })
  68. })
  69. describe("missing", function(){
  70. it("should return errors when missing source directory", function(done){
  71. var root = __dirname + "/fixtures/data/nonexisting"
  72. try{
  73. var poly = polymer.root(root)
  74. }catch(error){
  75. should.exist(error)
  76. error.should.have.property('source', "Config")
  77. error.should.have.property('dest', "Config")
  78. error.should.have.property('lineno')
  79. error.should.have.property('filename')
  80. error.should.have.property('message')
  81. error.should.have.property('stack')
  82. done()
  83. }
  84. })
  85. })
  86. describe("public", function(){
  87. it("should return public object", function(done){
  88. var root = __dirname + "/fixtures/data/valid"
  89. var poly = polymer.root(root)
  90. poly.render("pub.json.jade", function(err, result){
  91. var pub = JSON.parse(result)
  92. should.not.exist(pub[".foo"])
  93. done()
  94. })
  95. })
  96. })
  97. describe("dynamic", function(){
  98. it("should return public object", function(done){
  99. var root = __dirname + "/fixtures/data/dynamic"
  100. var poly = polymer.root(root)
  101. poly.render("pub.json.jade", { "layout": false }, function(err, result){
  102. var pub = JSON.parse(result)
  103. should.exist(pub["articles"]["_data"]["hello-world"])
  104. should.not.exist(pub[".foo"])
  105. done()
  106. })
  107. })
  108. })
  109. })