-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
65 lines (51 loc) · 1.41 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var tests = {
'posthtml-md': {
'basic': {
message: 'supports basic usage',
options: {
from: './test/index.html'
}
}
}
};
var debug = true;
var dir = './test/';
var fs = require('fs');
var path = require('path');
var plugin = require('./');
var test = require('tape');
Object.keys(tests).forEach(function (name) {
var parts = tests[name];
test(name, function (t) {
var fixtures = Object.keys(parts);
t.plan(fixtures.length);
fixtures.forEach(function (fixture) {
var message = parts[fixture].message;
var options = parts[fixture].options;
var baseName = fixture.split(':')[0];
var testName = fixture.split(':').join('.');
var inputPath = path.resolve(dir + baseName + '.html');
var expectPath = path.resolve(dir + testName + '.expect.html');
var actualPath = path.resolve(dir + testName + '.actual.html');
var inputHTML = '';
var expectHTML = '';
try {
inputHTML = fs.readFileSync(inputPath, 'utf8');
} catch (error) {
fs.writeFileSync(inputPath, inputHTML);
}
try {
expectHTML = fs.readFileSync(expectPath, 'utf8');
} catch (error) {
fs.writeFileSync(expectPath, expectHTML);
}
plugin.process(inputHTML, options).then(function (result) {
var actualHTML = result.html;
if (debug) {
fs.writeFileSync(actualPath, actualHTML);
}
t.equal(actualHTML, expectHTML, message);
});
});
});
});