-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
92 lines (77 loc) · 2.13 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
var generate = require("bit-docs-generate-html/generate");
var Q = require("q");
var path = require("path");
var assert = require("assert");
var Browser = require("zombie"),
connect = require("connect");
var find = function(browser, property, callback, done){
var start = new Date();
var check = function(){
if(browser.window && browser.window[property]) {
callback(browser.window[property]);
} else if(new Date() - start < 2000){
setTimeout(check, 20);
} else {
done("failed to find "+property);
}
};
check();
};
var waitFor = function(browser, checker, callback, done){
var start = new Date();
var check = function(){
if(checker(browser.window)) {
callback(browser.window);
} else if(new Date() - start < 2000){
setTimeout(check, 20);
} else {
done(new Error("checker was never true"));
}
};
check();
};
var open = function(url, callback, done){
var server = connect().use(connect.static(path.join(__dirname))).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)
});
};
// somehow do a build with this added on ...
describe("bit-docs-prettify", function(){
it("basics work", function(done){
this.timeout(30000);
var docMap = Q({
index: {
name: "index",
body: "```\nvar str ='hello world';\n```"
}
});
generate(docMap,{
html: {
dependencies: {
"bit-docs-prettify": __dirname
}
},
dest: path.join(__dirname, "temp"),
parent: "index",
forceBuild: true
}).then(function(){
open("temp/index.html",function(browser, close){
var prettyprinted = browser.window.document.getElementsByClassName("prettyprint")
assert.ok(prettyprinted.length, "has a returns object")
close();
done();
},done);
}).catch(function(err){
console.log("err",err.stack);
done(err)
});
});
});