-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
143 lines (130 loc) · 5.06 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var assert = require('assert');
var _ = require('lodash');
var Q = require('q');
var path = require('path');
var fs = require('fs');
var rmdir = require('rimraf');
var readFile = Q.denodeify(fs.readFile);
var searchMapHash = require('./generators/search-map-hash');
var searchMap = require('./generators/search-map');
var generator = require("./generate");
var docMap = require('./testDocMap');
var siteConfig = {
dest: path.join(__dirname, "test_tmp"),
devBuild: true,
minify: false,
parent: "index",
forceBuild: true
};
var docMapPromise;
describe("bitDocs.generators.searchMap",function(){
beforeEach(function(done){
docMapPromise = Q.Promise(function(resolve){
resolve(_.assign(docMap));
});
done();
});
afterEach(function(done){
rmdir(path.join(__dirname,"test_tmp"),done);
});
it("(bitDocs.generators.searchMap.searchMap) Generates a searchMap file", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig);
}).then(function(){
if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMap.json"))) {
throw new Error("searchMap.json does not exist");
} else{
assert.ok(true, "searchMap.json exists");
}
});
});
it("(bitDocs.generators.searchMap.searchMap) Excludes docObjects with @hide", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig).then(function(searchMapResult){
assert.ok(!searchMapResult['guides/what-is-canjs']);
});
});
});
it("(bitDocs.generators.searchMap.searchMap) Strips HTML from the description", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig);
}).then(function(searchMapResult){
var description = searchMapResult['can-core'].description;
assert.ok(description.indexOf('span') < 0, 'stripped basic HTML');
});
});
it("(bitDocs.generators.searchMap.searchMap) Leaves HTML code examples in the description", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig);
}).then(function(searchMapResult){
var description = searchMapResult['can-core'].description;
assert.ok(description.indexOf('<code><input /></code>') > 0, 'stripped inputs');
});
});
it("(bitDocs.generators.searchMap.searchMap) Does not filter hidden and empty docObjects", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig).then(function(searchMapResult){
assert.ok(searchMapResult.Component);
});
});
});
it("(bitDocs.generators.searchMap.searchMap) Does not filter docObjects with only “undefined\n” as their description", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig).then(function(searchMapResult){
assert.ok(searchMapResult['can.Control']);
});
});
});
it("bit-docs links should render", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig);
}).then(function(searchMapResult){
assert.equal(searchMapResult['can-core'].description.indexOf('[steal-stache]'), -1);
assert.ok(searchMapResult['can-core'].description.indexOf('<a href="steal-stache.html"') > -1);
});
});
it("(bitDocs.generators.searchMap.searchMapHash) Generates a searchMapHash file", function(){
return docMapPromise.then(function(docMap){
return searchMapHash(docMap, siteConfig);
}).then(function(){
if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMapHash.json"))) {
throw new Error("searchMapHash.json does not exist");
} else{
assert.ok(true, "searchMapHash.json exists");
}
});
});
it("(bitDocs.generators.searchMap.searchMapHash) Generates a new hash when the searchMap changes", function(){
return docMapPromise.then(function(docMap){
return searchMap(docMap, siteConfig);
}).then(function(searchMapResult){
return searchMapHash(searchMapResult, siteConfig).then(function(firstHash){
if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMapHash.json"))) {
throw new Error("searchMapHash.json does not exist (1)");
} else{
searchMapResult.description = "test " + searchMapResult.description;
return searchMapHash(searchMapResult, siteConfig).then(function(secondHash){
if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMapHash.json"))) {
throw new Error("searchMapHash.json does not exist (2)");
} else if(firstHash.hash === secondHash){
throw new Error("searchMapHash.json does not exist (2)");
}else{
assert.ok(true, "The hash changed when the search map changed");
}
});
}
});
});
});
it("(bitDocs.generators.searchMap) Generates searchMap and searchMapHash files", function(){
return generator(docMapPromise, siteConfig).then(function(){
if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMap.json"))) {
throw new Error("searchMapHash.json does not exist");
} else if(!fs.existsSync(path.join(__dirname,"test_tmp","searchMapHash.json"))) {
throw new Error("searchMapHash.json does not exist");
} else{
assert.ok(true, "seachMap.json and searchMapHash.json exists");
}
});
});
});