makemarkdown.bootstrap.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Created by Estevao on 22-12-2017.
  3. */
  4. //jscs:disable requireCamelCaseOrUpperCaseIdentifiers
  5. (function () {
  6. 'use strict';
  7. require('source-map-support').install();
  8. require('chai').should();
  9. var fs = require('fs');
  10. function getTestSuite (dir) {
  11. return fs.readdirSync(dir)
  12. .filter(filter())
  13. .map(map(dir));
  14. }
  15. function filter () {
  16. return function (file) {
  17. var ext = file.slice(-3);
  18. return (ext === '.md');
  19. };
  20. }
  21. function map (dir) {
  22. return function (file) {
  23. var name = file.replace('.md', ''),
  24. htmlPath = dir + name + '.html',
  25. html = fs.readFileSync(htmlPath, 'utf8'),
  26. mdPath = dir + name + '.md',
  27. md = fs.readFileSync(mdPath, 'utf8');
  28. return {
  29. name: name,
  30. input: html,
  31. expected: md
  32. };
  33. };
  34. }
  35. function assertion (testCase, converter) {
  36. return function () {
  37. testCase.actual = converter.makeMarkdown(testCase.input);
  38. testCase = normalize(testCase);
  39. // Compare
  40. testCase.actual.should.equal(testCase.expected);
  41. };
  42. }
  43. //Normalize input/output
  44. function normalize (testCase) {
  45. // Normalize line returns
  46. testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
  47. testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
  48. // Remove extra lines
  49. testCase.expected = testCase.expected.replace(/^\n+/, '').replace(/\n+$/, '');
  50. testCase.actual = testCase.actual.replace(/^\n+/, '').replace(/\n+$/, '');
  51. return testCase;
  52. }
  53. module.exports = {
  54. getTestSuite: getTestSuite,
  55. assertion: assertion,
  56. normalize: normalize,
  57. showdown: require('../../../.build/showdown.js')
  58. };
  59. })();