run.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var showdown = new require('../src/showdown').Showdown,
  2. convertor = new showdown.converter(),
  3. fs = require('fs'),
  4. path = require('path'),
  5. should = require('should');
  6. // Load test cases from disk
  7. var cases = fs.readdirSync('test/cases').filter(function(file){
  8. return ~file.indexOf('.md');
  9. }).map(function(file){
  10. return file.replace('.md', '');
  11. });
  12. // Run each test case
  13. cases.forEach(function(test){
  14. var name = test.replace(/[-.]/g, ' ');
  15. it (name, function(){
  16. var mdpath = path.join('test/cases', test + '.md'),
  17. htmlpath = path.join('test/cases', test + '.html'),
  18. md = fs.readFileSync(mdpath, 'utf8'),
  19. expected = fs.readFileSync(htmlpath, 'utf8').trim(),
  20. actual = convertor.makeHtml(md).trim();
  21. // Normalize line returns
  22. expected = expected.replace(/\r/g, '');
  23. // Ignore all leading/trailing whitespace
  24. expected = expected.split('\n').map(function(x){
  25. return x.trim();
  26. }).join('\n');
  27. actual = actual.split('\n').map(function(x){
  28. return x.trim();
  29. }).join('\n');
  30. // Convert whitespace to a visible character so that it shows up on error reports
  31. expected = expected.replace(/ /g, '·');
  32. expected = expected.replace(/\n/g, '•\n');
  33. actual = actual.replace(/ /g, '·');
  34. actual = actual.replace(/\n/g, '•\n');
  35. if (test == 'github-style-codeblock') {
  36. console.log(actual);
  37. }
  38. // Compare
  39. actual.should.equal(expected);
  40. });
  41. });