bootstrap.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Created by Estevao on 08-06-2015.
  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: md,
  31. expected: html
  32. };
  33. };
  34. }
  35. function assertion (testCase, converter) {
  36. return function () {
  37. testCase.actual = converter.makeHtml(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. // Ignore all leading/trailing whitespace
  49. testCase.expected = testCase.expected.split('\n').map(function (x) {
  50. return x.trim();
  51. }).join('\n');
  52. testCase.actual = testCase.actual.split('\n').map(function (x) {
  53. return x.trim();
  54. }).join('\n');
  55. // Remove extra lines
  56. testCase.expected = testCase.expected.trim();
  57. testCase.actual = testCase.actual.trim();
  58. //Beautify
  59. //testCase.expected = beautify(testCase.expected, beauOptions);
  60. //testCase.actual = beautify(testCase.actual, beauOptions);
  61. // Normalize line returns
  62. testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
  63. testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
  64. return testCase;
  65. }
  66. module.exports = {
  67. getTestSuite: getTestSuite,
  68. assertion: assertion,
  69. normalize: normalize,
  70. showdown: require('../.build/showdown.js')
  71. };
  72. })();