PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/test/test.compile.js

https://github.com/KINGSABRI/nodefront
JavaScript | 154 lines | 134 code | 14 blank | 6 comment | 0 complexity | b26ca2d27eaf450de775297859ab63be MD5 | raw file
Possible License(s): MIT
  1. var fs = require('fs');
  2. var q = require('q');
  3. var request = require('request');
  4. var utils = require('../lib/utils');
  5. var testUtils = require('./lib/utils');
  6. var nodefront = __dirname + '/../nodefront.js';
  7. var inputDir = __dirname + '/resources/compile/input';
  8. var expectedDir = __dirname + '/resources/compile/expected';
  9. var compile = require('../commands/compile');
  10. var defaultEnv = {};
  11. var originalDir = process.cwd();
  12. describe('`nodefront compile`', function() {
  13. before(function() {
  14. process.chdir(inputDir);
  15. });
  16. after(function() {
  17. process.chdir(originalDir);
  18. });
  19. describe('compiles', function() {
  20. before(function(done) {
  21. compile(defaultEnv, true)
  22. .then(function() {
  23. done();
  24. })
  25. .end();
  26. });
  27. it('Jade files', function(done) {
  28. testUtils.expectFilesToMatch(inputDir + '/index.html',
  29. expectedDir + '/index.html')
  30. .then(function() {
  31. return testUtils.expectFilesToMatch(inputDir + '/layout.html',
  32. expectedDir + '/layout.html');
  33. })
  34. .fin(function() {
  35. try {
  36. fs.unlinkSync(inputDir + '/index.html');
  37. } catch (error) {
  38. // don't worry about this; an error probably occurred above
  39. }
  40. try {
  41. fs.unlinkSync(inputDir + '/layout.html');
  42. } catch (error) {
  43. // don't worry about this; an error probably occurred above
  44. }
  45. })
  46. .then(done)
  47. .end();
  48. });
  49. it('Stylus files', function(done) {
  50. testUtils.expectFilesToMatch(inputDir + '/style.css',
  51. expectedDir + '/style.css')
  52. .fin(function() {
  53. try {
  54. fs.unlinkSync(inputDir + '/style.css');
  55. } catch (error) {
  56. // don't worry about this; an error probably occurred above
  57. }
  58. })
  59. .then(done)
  60. .end();
  61. });
  62. });
  63. describe('serves', function() {
  64. var port = 3217;
  65. before(function(done) {
  66. compile(utils.extend(defaultEnv, { serve: port }), true)
  67. .then(function() {
  68. done();
  69. });
  70. });
  71. it('HTML files', function(done) {
  72. var responseBody;
  73. q.ncall(request, this, 'http://localhost:' + port + '/index.html')
  74. .spread(function(response, body) {
  75. responseBody = body;
  76. return utils.readFile(inputDir + '/index.html');
  77. })
  78. .then(function(expected) {
  79. responseBody.should.eql(expected);
  80. return q.ncall(request, this, 'http://localhost:' + port +
  81. '/layout.html');
  82. })
  83. .spread(function(response, body) {
  84. responseBody = body;
  85. return utils.readFile(inputDir + '/layout.html');
  86. })
  87. .then(function(expected) {
  88. responseBody.should.eql(expected);
  89. })
  90. .fin(function() {
  91. try {
  92. fs.unlinkSync(inputDir + '/index.html');
  93. } catch (error) {
  94. // don't worry about this; an error probably occurred above
  95. }
  96. try {
  97. fs.unlinkSync(inputDir + '/layout.html');
  98. } catch (error) {
  99. // don't worry about this; an error probably occurred above
  100. }
  101. })
  102. .then(done)
  103. .end();
  104. });
  105. it('CSS files', function(done) {
  106. var responseBody;
  107. q.ncall(request, this, 'http://localhost:' + port + '/style.css')
  108. .spread(function(response, body) {
  109. responseBody = body;
  110. return utils.readFile(inputDir + '/style.css');
  111. })
  112. .then(function(expected) {
  113. responseBody.should.eql(expected);
  114. })
  115. .fin(function() {
  116. try {
  117. fs.unlinkSync(inputDir + '/style.css');
  118. } catch (error) {
  119. // don't worry about this; an error probably occurred above
  120. }
  121. })
  122. .then(done)
  123. .end();
  124. });
  125. it('Image files', function(done) {
  126. var responseBody;
  127. q.ncall(request, this, { encoding: null, uri: 'http://localhost:' +
  128. port + '/images/pattern.jpg' })
  129. .spread(function(response, body) {
  130. responseBody = body;
  131. return utils.readFile(inputDir + '/images/pattern.jpg', true);
  132. })
  133. .then(function(expected) {
  134. responseBody.should.eql(expected);
  135. })
  136. .then(done)
  137. .end();
  138. });
  139. });
  140. });