-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
128 lines (113 loc) · 3 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
var assert = require("assert");
var generate = require("bit-docs-generate-html/generate");
var path = require("path");
var fs = require("fs");
var Browser = require("zombie");
var connect = require("connect");
var open = function(url, callback, done) {
var server = connect().use(connect.static(path.join(__dirname, "temp"))).listen(8081);
var browser = new Browser();
browser.visit("http://localhost:8081/" + url)
.then(function() {
callback(browser, function() {
server.close();
});
}).catch(function(e) {
server.close();
done(e);
});
};
describe("bit-docs-html-highlight-line", function() {
it("basics works", function(done) {
this.timeout(60000);
var docMap = Promise.resolve({
index: {
name: "index",
demo: "path/to/demo.html",
body: fs.readFileSync(__dirname+"/test-demo.md", "utf8")
}
});
generate(docMap, {
html: {
dependencies: {
"bit-docs-html-highlight-line": __dirname
}
},
dest: path.join(__dirname, "temp"),
parent: "index",
forceBuild: true,
debug: true,
minifyBuild: false
}).then(function() {
open("index.html",function(browser, close) {
var doc = browser.window.document;
var lineCodes = doc.querySelectorAll('pre[data-line] code');
var collapseCodes = doc.querySelectorAll('pre[data-collapse] code');
assert.ok(lineCodes.length, "there are code blocks with data-line");
assert.ok(collapseCodes.length, "there are code blocks with data-collapse");
close();
done();
}, done);
}, done);
});
it("dosen't show expand button for one line code", function(done) {
this.timeout(60000);
var docMap = Promise.resolve({
index: {
name: "index",
demo: "path/to/demo.html",
body: fs.readFileSync(__dirname+"/collapse-test.md", "utf8")
}
});
generate(docMap, {
html: {
dependencies: {
"bit-docs-html-highlight-line": __dirname
}
},
dest: path.join(__dirname, "temp"),
parent: "index",
forceBuild: true,
debug: true,
minifyBuild: false
}).then(function() {
open("index.html",function(browser, close) {
var doc = browser.window.document;
var collapseCodes = doc.querySelectorAll('pre[data-collapse] code');
assert.equal(collapseCodes.length, 0);
close();
done();
}, done);
}, done);
});
it("Collapse last line", function(done) {
this.timeout(60000);
var docMap = Promise.resolve({
index: {
name: "index",
demo: "path/to/demo.html",
body: fs.readFileSync(__dirname+"/test-collapse-last-line.md", "utf8")
}
});
generate(docMap, {
html: {
dependencies: {
"bit-docs-html-highlight-line": __dirname
}
},
dest: path.join(__dirname, "temp"),
parent: "index",
forceBuild: true,
debug: true,
minifyBuild: false
}).then(function() {
open("index.html",function(browser, close) {
var doc = browser.window.document;
var collapseCode = doc.querySelectorAll('pre[data-collapse="11-12"]');
assert.ok(collapseCode);
close();
done();
}, done);
}, done);
});
});