You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
8.1 KiB

  1. // Generated by CoffeeScript 1.6.2
  2. var CSON, DocPad, PluginTester, RendererTester, ServerTester, balUtil, expect, extendr, joe, pathUtil, pluginPort, test, testers, _ref, _ref1,
  3. __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. pathUtil = require('path');
  7. balUtil = require('bal-util');
  8. extendr = require('extendr');
  9. joe = require('joe');
  10. expect = require('chai').expect;
  11. CSON = require('cson');
  12. DocPad = require(__dirname + '/docpad');
  13. pluginPort = 2000 + String((new Date()).getTime()).substr(-6, 4);
  14. testers = {
  15. CSON: CSON,
  16. DocPad: DocPad
  17. };
  18. testers.PluginTester = PluginTester = (function() {
  19. PluginTester.prototype.config = {
  20. pluginName: null,
  21. pluginPath: null,
  22. autoExit: true,
  23. testPath: null,
  24. outExpectedPath: null,
  25. removeEmptyLines: false
  26. };
  27. PluginTester.prototype.docpadConfig = {
  28. port: null,
  29. growl: false,
  30. logLevel: ((__indexOf.call(process.argv, '-d') >= 0) ? 7 : 5),
  31. rootPath: null,
  32. outPath: null,
  33. srcPath: null,
  34. pluginPaths: null,
  35. enableUnlistedPlugins: false,
  36. enabledPlugins: null,
  37. skipUnsupportedPlugins: false,
  38. catchExceptions: false,
  39. environment: null
  40. };
  41. PluginTester.prototype.docpad = null;
  42. function PluginTester(config, docpadConfig, next) {
  43. var defaultEnabledPlugins, tester, _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _ref, _ref1, _ref2;
  44. if (config == null) {
  45. config = {};
  46. }
  47. if (docpadConfig == null) {
  48. docpadConfig = {};
  49. }
  50. tester = this;
  51. this.config = extendr.deepExtendPlainObjects({}, PluginTester.prototype.config, this.config, config);
  52. this.docpadConfig = extendr.deepExtendPlainObjects({}, PluginTester.prototype.docpadConfig, this.docpadConfig, docpadConfig);
  53. if ((_ref = (_base = this.docpadConfig).port) == null) {
  54. _base.port = ++pluginPort;
  55. }
  56. if ((_ref1 = (_base1 = this.config).testerName) == null) {
  57. _base1.testerName = this.config.pluginName;
  58. }
  59. (_base2 = this.config).testPath || (_base2.testPath = pathUtil.join(this.config.pluginPath, 'test'));
  60. (_base3 = this.config).outExpectedPath || (_base3.outExpectedPath = pathUtil.join(this.config.testPath, 'out-expected'));
  61. (_base4 = this.docpadConfig).rootPath || (_base4.rootPath = this.config.testPath);
  62. (_base5 = this.docpadConfig).outPath || (_base5.outPath = pathUtil.join(this.docpadConfig.rootPath, 'out'));
  63. (_base6 = this.docpadConfig).srcPath || (_base6.srcPath = pathUtil.join(this.docpadConfig.rootPath, 'src'));
  64. if ((_ref2 = (_base7 = this.docpadConfig).pluginPaths) == null) {
  65. _base7.pluginPaths = [this.config.pluginPath];
  66. }
  67. defaultEnabledPlugins = {};
  68. defaultEnabledPlugins[this.config.pluginName] = true;
  69. (_base8 = this.docpadConfig).enabledPlugins || (_base8.enabledPlugins = defaultEnabledPlugins);
  70. joe.describe(this.config.testerName, function(suite, task) {
  71. tester.describe = tester.suite = suite;
  72. tester.it = tester.test = task;
  73. tester.done = tester.exit = function() {};
  74. return typeof next === "function" ? next(null, tester) : void 0;
  75. });
  76. this;
  77. }
  78. PluginTester.prototype.testCreate = function() {
  79. var docpadConfig, tester;
  80. tester = this;
  81. docpadConfig = this.docpadConfig;
  82. this.test("create", function(done) {
  83. return DocPad.createInstance(docpadConfig, function(err, docpad) {
  84. if (err) {
  85. return done(err);
  86. }
  87. tester.docpad = docpad;
  88. return tester.docpad.action('clean', function(err) {
  89. if (err) {
  90. return done(err);
  91. }
  92. return tester.docpad.action('install', function(err) {
  93. return done(err);
  94. });
  95. });
  96. });
  97. });
  98. return this;
  99. };
  100. PluginTester.prototype.testLoad = function() {
  101. var tester;
  102. tester = this;
  103. this.test("load plugin " + tester.config.pluginName, function(done) {
  104. return tester.docpad.loadedPlugin(tester.config.pluginName, function(err, loaded) {
  105. if (err) {
  106. return done(err);
  107. }
  108. expect(loaded).to.be.ok;
  109. return done();
  110. });
  111. });
  112. return this;
  113. };
  114. PluginTester.prototype.testServer = function(next) {
  115. var tester;
  116. tester = this;
  117. this.test("server", function(done) {
  118. return tester.docpad.action('server', function(err) {
  119. return done(err);
  120. });
  121. });
  122. return this;
  123. };
  124. PluginTester.prototype.testGenerate = function() {
  125. var tester;
  126. tester = this;
  127. this.test("generate", function(done) {
  128. return tester.docpad.action('generate', function(err) {
  129. return done(err);
  130. });
  131. });
  132. return this;
  133. };
  134. PluginTester.prototype.testEverything = function() {
  135. var tester;
  136. tester = this;
  137. this.testCreate();
  138. this.testLoad();
  139. this.testGenerate();
  140. this.testServer();
  141. if (typeof this.testCustom === "function") {
  142. this.testCustom();
  143. }
  144. this.finish();
  145. return this;
  146. };
  147. PluginTester.prototype.finish = function() {
  148. var tester;
  149. tester = this;
  150. if (tester.config.autoExit) {
  151. this.test('finish up', function(done) {
  152. done();
  153. tester.exit();
  154. if (tester.config.autoExit !== 'safe') {
  155. return process.exit();
  156. }
  157. });
  158. }
  159. return this;
  160. };
  161. return PluginTester;
  162. })();
  163. testers.ServerTester = ServerTester = (function(_super) {
  164. __extends(ServerTester, _super);
  165. function ServerTester() {
  166. _ref = ServerTester.__super__.constructor.apply(this, arguments);
  167. return _ref;
  168. }
  169. return ServerTester;
  170. })(PluginTester);
  171. testers.RendererTester = RendererTester = (function(_super) {
  172. __extends(RendererTester, _super);
  173. function RendererTester() {
  174. _ref1 = RendererTester.__super__.constructor.apply(this, arguments);
  175. return _ref1;
  176. }
  177. RendererTester.prototype.testGenerate = function() {
  178. var tester;
  179. tester = this;
  180. this.suite("generate", function(suite, test) {
  181. test('action', function(done) {
  182. return tester.docpad.action('generate', function(err) {
  183. return done(err);
  184. });
  185. });
  186. return test('results', function(done) {
  187. return balUtil.scantree(tester.docpadConfig.outPath, function(err, outResults) {
  188. if (err) {
  189. return done(err);
  190. }
  191. return balUtil.scantree(tester.config.outExpectedPath, function(err, outExpectedResults) {
  192. var replaceLinesRegex;
  193. if (err) {
  194. return done(err);
  195. }
  196. if (tester.config.removeWhitespace) {
  197. replaceLinesRegex = /(\\r|\\n|\\t|\s)+/g;
  198. outResults = JSON.parse(JSON.stringify(outResults).replace(replaceLinesRegex, ''));
  199. outExpectedResults = JSON.parse(JSON.stringify(outExpectedResults).replace(replaceLinesRegex, ''));
  200. }
  201. expect(outResults).to.eql(outExpectedResults);
  202. return done();
  203. });
  204. });
  205. });
  206. });
  207. return this;
  208. };
  209. return RendererTester;
  210. })(PluginTester);
  211. testers.test = test = function(testerConfig, docpadConfig) {
  212. var testerClass, _ref2, _ref3;
  213. testerConfig.pluginPath = pathUtil.resolve(testerConfig.pluginPath);
  214. if ((_ref2 = testerConfig.pluginName) == null) {
  215. testerConfig.pluginName = pathUtil.basename(testerConfig.pluginPath).replace('docpad-plugin-', '');
  216. }
  217. if ((_ref3 = testerConfig.testerPath) == null) {
  218. testerConfig.testerPath = pathUtil.join('out', "" + testerConfig.pluginName + ".tester.js");
  219. }
  220. testerConfig.testerPath = pathUtil.resolve(testerConfig.pluginPath, testerConfig.testerPath);
  221. testerClass = require(testerConfig.testerPath)(testers);
  222. new testerClass(testerConfig, docpadConfig, function(err, testerInstance) {
  223. if (err) {
  224. throw err;
  225. }
  226. return testerInstance.testEverything();
  227. });
  228. return testers;
  229. };
  230. module.exports = testers;