-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
70 lines (56 loc) · 1.72 KB
/
index.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
66
67
68
69
70
'use strict';
const path = require('path');
const fs = require('fs-extra');
const assert = require('power-assert');
const createDocParser = require('../');
const util = require('../src/utils');
const docParser = createDocParser({});
describe('test/index.test.js', () => {
describe('parse readme', () => {
let readme;
beforeEach(function* () {
const filepath = path.join(__dirname, './fixture/api.md');
readme = yield fs.readFile(filepath, 'utf8');
});
afterEach(() => {
readme = null;
});
it('should #parse readme', () => {
const data = docParser.parse(readme);
assert(data.title === 'Demo');
assert(data.meta.chinese === '测试');
});
it('should #parseAPI', () => {
const headers = ['name', 'description', 'type', 'defaultValue'];
const apis = docParser.parseAPI(readme, headers);
assert(apis.length);
});
it('should #render markdwon', () => {
const data = docParser.parse(readme);
const md = docParser.render(data.body);
assert(md);
});
});
describe('parse demo', () => {
let demo;
beforeEach(function* () {
const filepath = path.join(__dirname, './fixture/demo.md');
demo = yield fs.readFile(filepath, 'utf8');
});
afterEach(() => {
demo = null;
});
it('should #parse demo', () => {
const data = docParser.parse(demo);
assert(data.title === '基本');
assert(data.codes.jsx);
assert(data.codes.css);
});
it('should #render parsed demo', () => {
const data = docParser.parse(demo);
const html = docParser.render(data.body);
assert(html.includes('<div class="highlight">'));
assert(!html.includes('<p>+</p>'));
});
});
});