UNPKG

2.56 kBJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3var assert = require('assert');
4var rewire = require("rewire");
5var parse = rewire('../../src/parse/parse');
6
7describe('parse', function(){
8 it('handlePath', function(){
9 let ht = parse.__get__('handleMdPathToHtml');
10 assert.equal(ht('/a/a.md'), '/a/a.html')
11 assert.equal(ht('/a/a.jsx'), '/a/a.html')
12 assert.equal(ht('/a/a.html'), '/a/a.html')
13 assert.equal(ht('/a/a.x'), '/a/a.x')
14 })
15
16 it('getIndexPath', function(){
17 let getIndexPath = parse.__get__('getIndexPath');
18 let htmlDirpath = path.resolve(__dirname, './fixtures/index-test/html')
19 let mdDirpath = path.resolve(__dirname, './fixtures/index-test/md')
20 let jsxDirpath = path.resolve(__dirname, './fixtures/index-test/jsx')
21 assert.equal(getIndexPath(htmlDirpath), path.resolve(htmlDirpath, 'index.html'))
22 assert.equal(getIndexPath(mdDirpath), path.resolve(mdDirpath, 'index.md'))
23 assert.equal(getIndexPath(jsxDirpath), path.resolve(jsxDirpath, 'index.jsx'))
24 })
25
26 it('getBooksByNav', function(){
27 let getBooks = parse.__get__('getBooks');
28 let dist = path.resolve(__dirname, 'fixtures');
29 let menus = [
30 {
31 "title": "文档",
32 "ref": "markdown.md",
33 "items": []
34 },
35 {
36 "title": "文档规范",
37 "ref": "index-test/html/index.html",
38 "items": []
39 },
40 {
41 "title": "插件",
42 "ref": "index-test/jsx/index.jsx",
43 "items": []
44 },{
45 "tilte": "error",
46 "ref": "err/error.md",
47 "items": []
48 },{
49 "title": "none",
50 "ref": "none.md"
51 },{
52 "title": "github",
53 "ref": "https://github.com/ymfe/yapi"
54 }
55 ]
56 let books = getBooks(menus, dist)
57 let result = [{
58 bookpath: dist,
59 indexFile: 'markdown.md',
60 title: '文档'
61 },{
62 bookpath: path.resolve(dist, 'index-test/html'),
63 indexFile: 'index.html',
64 title: '文档规范'
65 },{
66 bookpath: path.resolve(dist, 'index-test/jsx'),
67 indexFile: 'index.jsx',
68 title: '插件'
69 }]
70
71 assert.deepEqual(books, result)
72
73 })
74
75 it('parseDocuments', function(){
76 let parseDocuments = parse.__get__('parseDocuments')
77 let bookpath = path.resolve(__dirname, 'fixtures/bookpath');
78 let length = 0;
79 let callback = function(absolutePath, reletivePath){
80 length++;
81 }
82 let summary = require(path.resolve(bookpath, 'summary.json'));
83 parseDocuments(bookpath, callback)(summary)
84 assert.equal(length, 6)
85 })
86
87
88})