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.

275 lines
8.2 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. PluginTester.prototype.logger = null;
  43. function PluginTester(config, docpadConfig, next) {
  44. var defaultEnabledPlugins, tester, _base, _base1, _base2, _base3, _base4, _base5, _base6, _base7, _base8, _ref, _ref1, _ref2;
  45. if (config == null) {
  46. config = {};
  47. }
  48. if (docpadConfig == null) {
  49. docpadConfig = {};
  50. }
  51. tester = this;
  52. this.config = extendr.deepExtendPlainObjects({}, PluginTester.prototype.config, this.config, config);
  53. this.docpadConfig = extendr.deepExtendPlainObjects({}, PluginTester.prototype.docpadConfig, this.docpadConfig, docpadConfig);
  54. if ((_ref = (_base = this.docpadConfig).port) == null) {
  55. _base.port = ++pluginPort;
  56. }
  57. if ((_ref1 = (_base1 = this.config).testerName) == null) {
  58. _base1.testerName = this.config.pluginName;
  59. }
  60. (_base2 = this.config).testPath || (_base2.testPath = pathUtil.join(this.config.pluginPath, 'test'));
  61. (_base3 = this.config).outExpectedPath || (_base3.outExpectedPath = pathUtil.join(this.config.testPath, 'out-expected'));
  62. (_base4 = this.docpadConfig).rootPath || (_base4.rootPath = this.config.testPath);
  63. (_base5 = this.docpadConfig).outPath || (_base5.outPath = pathUtil.join(this.docpadConfig.rootPath, 'out'));
  64. (_base6 = this.docpadConfig).srcPath || (_base6.srcPath = pathUtil.join(this.docpadConfig.rootPath, 'src'));
  65. if ((_ref2 = (_base7 = this.docpadConfig).pluginPaths) == null) {
  66. _base7.pluginPaths = [this.config.pluginPath];
  67. }
  68. defaultEnabledPlugins = {};
  69. defaultEnabledPlugins[this.config.pluginName] = true;
  70. (_base8 = this.docpadConfig).enabledPlugins || (_base8.enabledPlugins = defaultEnabledPlugins);
  71. joe.describe(this.config.testerName, function(suite, task) {
  72. tester.describe = tester.suite = suite;
  73. tester.it = tester.test = task;
  74. tester.done = tester.exit = function() {};
  75. return typeof next === "function" ? next(null, tester) : void 0;
  76. });
  77. this;
  78. }
  79. PluginTester.prototype.testCreate = function() {
  80. var docpadConfig, tester;
  81. tester = this;
  82. docpadConfig = this.docpadConfig;
  83. this.test("create", function(done) {
  84. return DocPad.createInstance(docpadConfig, function(err, docpad) {
  85. if (err) {
  86. return done(err);
  87. }
  88. tester.docpad = docpad;
  89. tester.logger = docpad.logger;
  90. return tester.docpad.action('clean', function(err) {
  91. if (err) {
  92. return done(err);
  93. }
  94. return tester.docpad.action('install', function(err) {
  95. return done(err);
  96. });
  97. });
  98. });
  99. });
  100. return this;
  101. };
  102. PluginTester.prototype.testLoad = function() {
  103. var tester;
  104. tester = this;
  105. this.test("load plugin " + tester.config.pluginName, function(done) {
  106. return tester.docpad.loadedPlugin(tester.config.pluginName, function(err, loaded) {
  107. if (err) {
  108. return done(err);
  109. }
  110. expect(loaded).to.be.ok;
  111. return done();
  112. });
  113. });
  114. return this;
  115. };
  116. PluginTester.prototype.testServer = function(next) {
  117. var tester;
  118. tester = this;
  119. this.test("server", function(done) {
  120. return tester.docpad.action('server', function(err) {
  121. return done(err);
  122. });
  123. });
  124. return this;
  125. };
  126. PluginTester.prototype.testGenerate = function() {
  127. var tester;
  128. tester = this;
  129. this.test("generate", function(done) {
  130. return tester.docpad.action('generate', function(err) {
  131. return done(err);
  132. });
  133. });
  134. return this;
  135. };
  136. PluginTester.prototype.testEverything = function() {
  137. var tester;
  138. tester = this;
  139. this.testCreate();
  140. this.testLoad();
  141. this.testGenerate();
  142. this.testServer();
  143. if (typeof this.testCustom === "function") {
  144. this.testCustom();
  145. }
  146. this.finish();
  147. return this;
  148. };
  149. PluginTester.prototype.finish = function() {
  150. var tester;
  151. tester = this;
  152. if (tester.config.autoExit) {
  153. this.test('finish up', function(done) {
  154. done();
  155. tester.exit();
  156. if (tester.config.autoExit !== 'safe') {
  157. return process.exit();
  158. }
  159. });
  160. }
  161. return this;
  162. };
  163. return PluginTester;
  164. })();
  165. testers.ServerTester = ServerTester = (function(_super) {
  166. __extends(ServerTester, _super);
  167. function ServerTester() {
  168. _ref = ServerTester.__super__.constructor.apply(this, arguments);
  169. return _ref;
  170. }
  171. return ServerTester;
  172. })(PluginTester);
  173. testers.RendererTester = RendererTester = (function(_super) {
  174. __extends(RendererTester, _super);
  175. function RendererTester() {
  176. _ref1 = RendererTester.__super__.constructor.apply(this, arguments);
  177. return _ref1;
  178. }
  179. RendererTester.prototype.testGenerate = function() {
  180. var tester;
  181. tester = this;
  182. this.suite("generate", function(suite, test) {
  183. test('action', function(done) {
  184. return tester.docpad.action('generate', function(err) {
  185. return done(err);
  186. });
  187. });
  188. return test('results', function(done) {
  189. return balUtil.scantree(tester.docpadConfig.outPath, function(err, outResults) {
  190. if (err) {
  191. return done(err);
  192. }
  193. return balUtil.scantree(tester.config.outExpectedPath, function(err, outExpectedResults) {
  194. var replaceLinesRegex;
  195. if (err) {
  196. return done(err);
  197. }
  198. if (tester.config.removeWhitespace) {
  199. replaceLinesRegex = /(\\r|\\n|\\t|\s)+/g;
  200. outResults = JSON.parse(JSON.stringify(outResults).replace(replaceLinesRegex, ''));
  201. outExpectedResults = JSON.parse(JSON.stringify(outExpectedResults).replace(replaceLinesRegex, ''));
  202. }
  203. expect(outResults).to.eql(outExpectedResults);
  204. return done();
  205. });
  206. });
  207. });
  208. });
  209. return this;
  210. };
  211. return RendererTester;
  212. })(PluginTester);
  213. testers.test = test = function(testerConfig, docpadConfig) {
  214. var testerClass, _ref2, _ref3;
  215. testerConfig.pluginPath = pathUtil.resolve(testerConfig.pluginPath);
  216. if ((_ref2 = testerConfig.pluginName) == null) {
  217. testerConfig.pluginName = pathUtil.basename(testerConfig.pluginPath).replace('docpad-plugin-', '');
  218. }
  219. if ((_ref3 = testerConfig.testerPath) == null) {
  220. testerConfig.testerPath = pathUtil.join('out', "" + testerConfig.pluginName + ".tester.js");
  221. }
  222. testerConfig.testerPath = pathUtil.resolve(testerConfig.pluginPath, testerConfig.testerPath);
  223. testerClass = require(testerConfig.testerPath)(testers);
  224. new testerClass(testerConfig, docpadConfig, function(err, testerInstance) {
  225. if (err) {
  226. throw err;
  227. }
  228. return testerInstance.testEverything();
  229. });
  230. return testers;
  231. };
  232. module.exports = testers;