UNPKG

2.25 kBJavaScriptView Raw
1/**
2 * Created by Estevao on 08-06-2015.
3 */
4
5//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
6(function () {
7 'use strict';
8
9 require('source-map-support').install();
10 require('chai').should();
11 var fs = require('fs');
12
13 function getTestSuite (dir) {
14 return fs.readdirSync(dir)
15 .filter(filter())
16 .map(map(dir));
17 }
18
19 function filter () {
20 return function (file) {
21 var ext = file.slice(-3);
22 return (ext === '.md');
23 };
24 }
25
26 function map (dir) {
27 return function (file) {
28 var name = file.replace('.md', ''),
29 htmlPath = dir + name + '.html',
30 html = fs.readFileSync(htmlPath, 'utf8'),
31 mdPath = dir + name + '.md',
32 md = fs.readFileSync(mdPath, 'utf8');
33
34 return {
35 name: name,
36 input: md,
37 expected: html
38 };
39 };
40 }
41
42 function assertion (testCase, converter) {
43 return function () {
44 testCase.actual = converter.makeHtml(testCase.input);
45 testCase = normalize(testCase);
46
47 // Compare
48 testCase.actual.should.equal(testCase.expected);
49 };
50 }
51
52 //Normalize input/output
53 function normalize (testCase) {
54
55 // Normalize line returns
56 testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
57 testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
58
59 // Ignore all leading/trailing whitespace
60 testCase.expected = testCase.expected.split('\n').map(function (x) {
61 return x.trim();
62 }).join('\n');
63 testCase.actual = testCase.actual.split('\n').map(function (x) {
64 return x.trim();
65 }).join('\n');
66
67 // Remove extra lines
68 testCase.expected = testCase.expected.trim();
69 testCase.actual = testCase.actual.trim();
70
71 //Beautify
72 //testCase.expected = beautify(testCase.expected, beauOptions);
73 //testCase.actual = beautify(testCase.actual, beauOptions);
74
75 // Normalize line returns
76 testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
77 testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
78
79 return testCase;
80 }
81
82 module.exports = {
83 getTestSuite: getTestSuite,
84 assertion: assertion,
85 normalize: normalize,
86 showdown: require('../.build/showdown.js')
87 };
88})();
89